How frolant/react-ssr-pack works
Project type and purpose
• This is a monorepo toolkit (“React SSR Pack”) for adding server-side rendering (SSR) to React applications with minimal extra code.
• It consists of:
• A set of reusable npm packages under packages/ (babel-plugin, resolve-plugin, server, tools, etc.)
• An example full-stack React/Redux/Redux-Saga/Express application under example/
• Build and development scripts and configs at the root.
File structure
• Top-level:
• packages/: individual libraries that implement core SSR behavior, plugin replacements, server runner, utilities.
• example/: a standalone client+server React app demonstrating integration.
• Build/tooling configs: webpack.*, lerna.json, tsconfig.json, run.js, and tools/.
• src/: implementation files
• README.md: package-specific docs
• package.json, tsconfig
• The example app has separate entry points (src/client.ts, src/server.ts), React components, store (Redux+Saga), rendering modules (clientAppRender, serverAppRender), and webpack configs for client/server.
Key insights from README
• Core flow:
1) Webpack server build uses @react-ssr-pack/babel-plugin to intercept useEffect.
2) @react-ssr-pack/resolve-plugin redirects imports of React hooks to SSR-aware implementations.
3) At runtime, runAppServer (from @react-ssr-pack/server) spins up Express, invokes nodeAppRender (from @react-ssr-pack/tools) to render the app to string, running all server-side useEffect hooks to completion, populating the Redux store.
4) Final HTML with preloaded state is sent to the client.
• Client build is a normal React SPA; hydration reuses the same hooks & store logic.
Components
a. Main components:
• Client build pipeline (webpack → babel/ts-loader, CSS, assets → clientAppRender → Browser)
• Server build pipeline (webpack → babel with babel-plugin, resolve-plugin → serverAppRender)
• Express server (runAppServer)
• SSR runtime: nodeAppRender + hook registry + Redux store + Redux-Saga
• Individual packages in packages/ (grouped by role: plugins, server, tools, utilities)
• Example app code (App, Routes, Components, Store)
• External resources: API endpoints, data services (JSON files in resources/data), third-party libs.
b. Relationships & interactions:
• Runtime: Express → serverAppRender → SSR tools → React → Store & Sagas → HTML → Client.
• Client: browser bootstraps via clientAppRender, hydrates state, runs effects normally.
• Packages: show dependencies between babel-plugin → resolve-plugin → tools → server.
c. Architectural patterns & principles:
• Monorepo managed by Lerna.
• Plugin architecture: webpack plugins & Babel plugin for hook interception.
• SSR as progressive render iterations until no new effects.
• Separation of concerns: build plugins vs. runtime server vs. client hydration.
d. Key technologies & libraries:
• Webpack (multiple configs)
• Babel (with @react-ssr-pack/babel-plugin)
• @react-ssr-pack/resolve-plugin
• Express (runAppServer)
• React (v18+), Redux, Redux-Saga, React Hooks (useEffect)
• TypeScript, Lerna, Node utilities