-
-
Notifications
You must be signed in to change notification settings - Fork 372
feat(rsc-demo): React Server Components demo with Module Federation #4247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ScriptedAlchemy
wants to merge
26
commits into
main
Choose a base branch
from
rsc-demo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
74fedd5
chore(rsc-demo): runtime client ref discovery + MF manifest data
ScriptedAlchemy 7ed1dcf
docs: add Option2Plan for MF-native actions
ScriptedAlchemy f9b51f0
chore: restore app2 action fallback (revert accidental removal)
ScriptedAlchemy 0f3acfe
docs: enrich Option2 plan with runtime/manifest details
ScriptedAlchemy 2181f26
chore: drop manual manifest merge (runtime is source of truth)
ScriptedAlchemy 02520cd
fix(rsc-demo): export server MF container and merge remote manifest
ScriptedAlchemy f2b56b8
chore: enforce async-node + MF node runtime on server builds
ScriptedAlchemy a594dbb
fix(rsc-demo): http mf metadata and context guards
ScriptedAlchemy 9644619
feat(rsc-demo): eager server action registration and share scope fixes
ScriptedAlchemy 125fbf5
fix(rsc-demo): server action registry singleton and test improvements
ScriptedAlchemy baccd46
fix(rsc-demo): remove skips from HTTP forwarding tests
ScriptedAlchemy dbd2c15
fix(rsc-demo): http forwarding and test reliability improvements
ScriptedAlchemy b816818
Merge remote-tracking branch 'origin/main' into rsc-demo
ScriptedAlchemy e55c0b2
fix(rsc-demo): address CodeQL security alerts
ScriptedAlchemy 74f73f8
fix(rsc-demo): address remaining CodeQL format string alerts
ScriptedAlchemy 8ab0371
fix(rsc-demo): downgrade jsdom to 24.x for Node 18 compatibility
ScriptedAlchemy fa2ff3e
fix(rsc-demo): make timer sanitization explicit for CodeQL
ScriptedAlchemy 38ca8e7
chore(rsc-demo): remove notes/.gitkeep
ScriptedAlchemy eeb2841
chore(rsc-demo): remove notes directory
ScriptedAlchemy 2a29f94
chore(rsc-demo): remove debug plugin and fix flaky tests
ScriptedAlchemy 6d9c0d1
fix(rsc-demo): fix SSR module resolution and test stability
ScriptedAlchemy f2e4218
chore: auto-include client refs for SSR and fix resolver
ScriptedAlchemy 2de6c9b
chore(rsc-demo): preserve actual export names in SSR module map
ScriptedAlchemy a31a374
ci: add RSC E2E workflow for rsc-demo
ScriptedAlchemy 76756e5
fix(rsc-demo): use dynamic paths in client-refs tests for CI
ScriptedAlchemy 6459f6e
fix(rsc-demo): address CodeQL alerts and add missing deps
ScriptedAlchemy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # .github/workflows/e2e-rsc.yml | ||
| name: E2E RSC Demo | ||
|
|
||
| on: | ||
| workflow_call: | ||
|
|
||
| jobs: | ||
| e2e-rsc: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
| steps: | ||
| - name: Checkout Repository | ||
| uses: actions/checkout@v5 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Cache Tool Downloads | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: ~/.cache | ||
| key: ${{ runner.os }}-toolcache-${{ hashFiles('pnpm-lock.yaml') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-toolcache- | ||
|
|
||
| - name: Install Pnpm | ||
| run: | | ||
| corepack prepare pnpm@8.11.0 --activate | ||
| corepack enable | ||
|
|
||
| - name: Setup Node.js 18 | ||
| uses: actions/setup-node@v5 | ||
| with: | ||
| node-version: '18' | ||
| cache: 'pnpm' | ||
|
|
||
| - name: Set Nx SHA | ||
| uses: nrwl/nx-set-shas@v3 | ||
|
|
||
| - name: Set SKIP_DEVTOOLS_POSTINSTALL environment variable | ||
| run: echo "SKIP_DEVTOOLS_POSTINSTALL=true" >> "$GITHUB_ENV" | ||
|
|
||
| - name: Install Dependencies | ||
| run: pnpm install | ||
|
|
||
| - name: Run Build for All Packages | ||
| run: npx nx run-many --targets=build --projects=tag:type:pkg | ||
|
|
||
| - name: Build RSC Demo App1 | ||
| working-directory: apps/rsc-demo/packages/app1 | ||
| run: pnpm build | ||
|
|
||
| - name: Build RSC Demo App2 | ||
| working-directory: apps/rsc-demo/packages/app2 | ||
| run: pnpm build | ||
|
|
||
| - name: Verify SSR Registry Injection | ||
| run: | | ||
| echo "Checking app1 SSR registry injection..." | ||
| head -c 100 apps/rsc-demo/packages/app1/build/ssr.js | grep -q "__RSC_SSR_REGISTRY_INJECTED__" || (echo "ERROR: SSR registry not injected in app1" && exit 1) | ||
| echo "Checking app2 SSR registry injection..." | ||
| head -c 100 apps/rsc-demo/packages/app2/build/ssr.js | grep -q "__RSC_SSR_REGISTRY_INJECTED__" || (echo "ERROR: SSR registry not injected in app2" && exit 1) | ||
| echo "SSR registry injection verified in both apps" | ||
|
|
||
| - name: Verify Manifest Files | ||
| run: | | ||
| echo "Checking manifest files..." | ||
| test -f apps/rsc-demo/packages/app1/build/react-client-manifest.json || (echo "ERROR: react-client-manifest.json missing in app1" && exit 1) | ||
| test -f apps/rsc-demo/packages/app1/build/react-ssr-manifest.json || (echo "ERROR: react-ssr-manifest.json missing in app1" && exit 1) | ||
| test -f apps/rsc-demo/packages/app1/build/react-server-actions-manifest.json || (echo "ERROR: react-server-actions-manifest.json missing in app1" && exit 1) | ||
| test -f apps/rsc-demo/packages/app2/build/react-client-manifest.json || (echo "ERROR: react-client-manifest.json missing in app2" && exit 1) | ||
| test -f apps/rsc-demo/packages/app2/build/react-ssr-manifest.json || (echo "ERROR: react-ssr-manifest.json missing in app2" && exit 1) | ||
| test -f apps/rsc-demo/packages/app2/build/react-server-actions-manifest.json || (echo "ERROR: react-server-actions-manifest.json missing in app2" && exit 1) | ||
| echo "All manifest files present" | ||
|
|
||
| - name: Run RSC E2E Tests | ||
| working-directory: apps/rsc-demo/packages/e2e | ||
| run: pnpm test:rsc | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # Option 2 (MF-Native RSC Actions) – Execution Plan | ||
|
|
||
| Goal: execute remote “use server” modules in-process via Module Federation, without HTTP forwarding, while keeping HTTP as a safe fallback. This must work for RSC, SSR, client hydration, shared packages, and layered share scopes. | ||
|
|
||
| ## Outcomes | ||
| - Host can `getServerAction(id)` for remote actions loaded via MF. | ||
| - No filesystem coupling; remotes discovered over HTTP via MF manifest data. | ||
| - Layer-aware sharing preserved (rsc vs client). | ||
| - Tests cover MF-native path plus fallback to HTTP. | ||
| - Works when remotes are deployed separately (no shared filesystem) and when the remote HTTP server is offline (MF container already loaded). | ||
|
|
||
| ## Workstream A – Remote publishes the right metadata | ||
| 1) **MF manifest extraData**: ensure remote (e.g., app2) publishes in `manifest.additionalData`: | ||
| - `rsc.serverActionsManifest`, `rsc.clientManifest`, `rsc.remote.url`, `rsc.remote.serverContainer`, `rsc.remote.actionsEndpoint`. | ||
| - `rsc.exposeTypes` marking `./server-actions` as `server-action` (and other exposes as `client-component`, `server-component`, etc.). | ||
| - (Optional) `rsc.layers` map so the host knows which shareScope each expose expects. | ||
| 2) **Public paths**: remoteEntry.server.js, mf-stats.json, manifests all served over HTTP (no fs paths). | ||
| 3) **Share scopes**: keep `shareScope: 'rsc'` for server layer, `'client'` for browser; include `react`, `react/jsx-runtime`, `react/jsx-dev-runtime`, `react-server-dom-webpack/server`. | ||
|
|
||
| ## Workstream B – Host runtime plugin wiring | ||
| 1) **Runtime plugin** (rscRuntimePlugin): | ||
| - On remote load, read MF manifest extraData (or mf-stats fallback). | ||
| - Fetch `serverActionsManifest` URL; cache by URL. | ||
| - For `server-actions` exposes, call `registerServerReference(fn, id, exportName)` for every manifest entry belonging to that remote. | ||
| - Use `resolveShare` / `loadShare` hooks to map to the correct shareScope based on issuer layer (rsc vs client), avoiding alias hacks. | ||
| - Emit structured logs (DEBUG) for: manifest fetch, module load, registration counts, and failures; surface a non-fatal warning when MF load fails so HTTP fallback remains available. | ||
| 2) **Host RSC entry**: ensure host imports remote `server-actions` so MF loads the container in the RSC layer (or trigger via lazy load during first request). | ||
| 3) **Option ordering** in `/react` handler: | ||
| - Try `getServerAction(id)` (populated by runtime plugin). | ||
| - If missing and remote match → HTTP forward (Option 1) as fallback. | ||
| - Add a small counter/metric for MF hits vs HTTP fallbacks. | ||
|
|
||
| ## Workstream C – Loader & plugin alignment | ||
| 1) **rsc-server-loader**: when processing MF-imported modules, preserve the canonical module URL from the manifest (do not rewrite to host paths) when calling `registerServerReference`. | ||
| 2) **react-server-dom-webpack plugin**: ensure manifest generation includes MF-imported actions (buildInfo flags already set; just respect provided module URLs). | ||
| 3) **No build-time manifest merge** in the host; everything discovered at runtime via MF data. | ||
| 4) **Client manifest for SSR (optional stretch)**: allow runtime plugin to fetch `clientManifest` from remote and merge into SSR worker’s manifest if we later SSR remote client islands. | ||
|
|
||
| ## Workstream D – Tests | ||
| 1) Unit: assert runtime plugin fetches extraData URLs, registers actions, and populates `getServerAction` without HTTP. | ||
| 2) Integration (node --test): start host only, stop remote HTTP server, verify remote actions still execute (pure MF). Then start remote server to confirm HTTP fallback still works when MF load fails. | ||
| 3) E2E: browser flows unchanged; add a case where host uses MF-native action and HTTP server is down. | ||
| 4) Negative tests: malformed extraData URL, missing manifest, incompatible shareScope, and mismatched React version in remote (should log and fall back). | ||
| 5) Performance check: compare latency of MF-native vs HTTP forward; assert no extra network calls for manifest after first fetch (cache hit). | ||
|
|
||
| ## Rollout Steps | ||
| 1) Update remote MF config to emit extraData URLs over HTTP. | ||
| 2) Update rscRuntimePlugin to prefer extraData, cache by manifest URL, and use loadShare for layer-aware React sharing. | ||
| 3) Ensure host server-entry imports remote server-actions (or lazy load before first action). | ||
| 4) Remove any residual build-time merges; rely solely on runtime discovery. | ||
| 5) Add tests (unit + integration + e2e) for MF-native path and fallback behavior. | ||
| 6) Add observability: lightweight counters for MF registrations, MF load failures, HTTP fallbacks; optionally expose in logs or a diagnostics endpoint. | ||
|
|
||
| ## Open Questions | ||
| - MF runtime “factory is not a function” on Node: diagnose container format vs runtime plugin; may need `@module-federation/node` runtimePlugin ordering or `library.type: 'commonjs-module'` alignment. | ||
| - Should remote also publish RSC client manifest URL for host-side SSR of remote client components? If yes, extend runtime plugin to fetch/merge client manifests for SSR worker. | ||
| - Do we need per-remote auth headers/cookies when fetching manifests over HTTP? If so, allow a configurable fetch hook in the runtime plugin. | ||
| - How to handle version skew of `react-server-dom-webpack` between host and remote? Consider validating major/minor in extraData and warning/falling back to HTTP. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
|
||
| # dependencies | ||
| /node_modules | ||
| **/node_modules/ | ||
| /.pnp | ||
| .pnp.js | ||
|
|
||
| # testing | ||
| /coverage | ||
|
|
||
| # production | ||
| /build | ||
| /dist | ||
| **/dist | ||
| /packages/app1/dist | ||
| /packages/app2/dist | ||
| **/build | ||
| /packages/app1/build | ||
| /packages/app2/build | ||
|
|
||
| # notes | ||
| notes/*.md | ||
| !notes/RESEARCH.md | ||
| test-results/ | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| .eslintcache | ||
| .env | ||
| .env.local | ||
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
|
|
||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|
|
||
| # vscode | ||
| .vscode |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 18.19.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # dependencies | ||
| /node_modules | ||
| /.pnp | ||
| .pnp.js | ||
|
|
||
| # testing | ||
| /coverage | ||
|
|
||
| # production | ||
| /build | ||
| /dist | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| .eslintcache | ||
| .env.local | ||
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
|
|
||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|
|
||
| *.html | ||
| *.json | ||
| *.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /** | ||
| * Copyright (c) Facebook, Inc. and its affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| * | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| module.exports = { | ||
| arrowParens: 'always', | ||
| bracketSpacing: false, | ||
| singleQuote: true, | ||
| jsxBracketSameLine: true, | ||
| trailingComma: 'es5', | ||
| printWidth: 80, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # Repository Guidelines | ||
|
|
||
| ## Project Structure & Modules | ||
| - Monorepo managed by `pnpm`. Primary apps live in `packages/app1` and `packages/app2`; shared RSC tooling is in `packages/react-server-dom-webpack`. | ||
| - App source: `packages/*/src`. Servers: `packages/*/server`. Webpack configs and build scripts: `packages/*/scripts`. | ||
| - Tests: unit/integration in `packages/e2e/rsc`, Playwright E2E in `packages/e2e/e2e`. Build output lands in `packages/*/build` (gitignored). | ||
|
|
||
| ## Build, Test, Dev Commands | ||
| - `pnpm install` — install workspace deps. | ||
| - `pnpm start` — run app1 dev server with webpack watch (bundler + server). | ||
| - `pnpm --filter app2 start` — same for app2. | ||
| - `pnpm run build` — production builds for app1 and app2 (client + server layers). | ||
| - `pnpm test` — top-level test entry; runs RSC tests and MF tests after building. | ||
| - `pnpm run test:rsc` — RSC unit/integration tests (Node `--test`). | ||
| - `pnpm run test:e2e:rsc` — Playwright smoke for the RSC notes apps. | ||
| - `pnpm run test:e2e` — all Playwright suites (requires prior build). | ||
|
|
||
| ## Coding Style & Naming | ||
| - JavaScript/React with ES modules; prefer functional components. | ||
| - Indent with 2 spaces; keep files ASCII-only unless existing file uses Unicode. | ||
| - Client components carry the `'use client'` directive; server actions/components avoid it. Name server action files `*.server.js` when possible. | ||
| - Webpack chunk/module ids are kept readable (`chunkIds: 'named', moduleIds: 'named'`). | ||
|
|
||
| ## Testing Guidelines | ||
| - Frameworks: Node’s built-in `node --test`, Playwright for E2E. | ||
| - Place unit/integration specs under `packages/e2e/rsc`. Name with `.test.js`. | ||
| - E2E specs live in `packages/e2e/e2e`; keep them idempotent and avoid relying on pre-existing data. | ||
| - Run `pnpm run build` before E2E to ensure assets exist. | ||
|
|
||
| ## Commit & PR Expectations | ||
| - Use concise, descriptive commit messages (e.g., `fix: inline action manifest ids`). | ||
| - For PRs, include: summary of changes, testing performed (`pnpm test:rsc`, `pnpm test:e2e:rsc`), and any follow-up risks or TODOs. | ||
|
|
||
| ## Module Federation Configuration | ||
| - ALL Module Federation plugins MUST include `experiments: { asyncStartup: true }` in their configuration (both client and server). | ||
| - ALL shared modules MUST use `eager: false` - no exceptions. The federation runtime handles async loading. | ||
| - Server-side code using asyncStartup bundles must `await` the module loads since module init is async. | ||
| - Use separate share scopes for different layers: `'client'` for browser bundles, `'rsc'` for RSC server bundles. | ||
| - Shared modules must also specify `layer` and `issuerLayer` matching the webpack layer they belong to (e.g., `client`, `rsc`, `ssr`). | ||
|
|
||
| ## Security & Config Tips | ||
| - Do not check `packages/*/build` or credentials into git; `.gitignore` already covers build artifacts. | ||
| - If enabling Postgres locally, gate with `USE_POSTGRES` and ensure fallback to the mock DB for offline runs. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Copilot Autofix
AI 4 days ago
To fix the issue, add an explicit
permissionsblock to limit the GITHUB_TOKEN's access. Since the workflow only reads repository contents (for checkout, potentially cache keys), the minimal safe set is{ contents: read }. This can be set either at the workflow root (so it applies to all jobs), or within the specific job if only one job exists. In this case, the workflow contains one job, so it's acceptable to add to either place; best practice is to set at the workflow root (directly below thename:and beforeon:) so future jobs inherit the least privilege by default. No imports, method definitions, or other changes required—simply add the permissions block.