fix: evaluate generateStaticParams under react-server condition - #328
Conversation
Avoid loading react-server-dom-webpack/server in the Vite process, which triggered CJS named-export errors and broke client builds when --conditions=react-server was set globally.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughStatic parameter evaluation now runs compiled route modules in an isolated Node worker with an RSC resolve hook. Props extraction and Vite manifest enrichment consume the helper’s result, validate static-parameter arrays, and process dynamic routes concurrently. ChangesStatic params evaluation
Estimated code review effort: 4 (Complex) | ~35 minutes Sequence Diagram(s)sequenceDiagram
participant BuildPipeline
participant evaluateGenerateStaticParams
participant NodeWorker
participant CompiledRouteModule
BuildPipeline->>evaluateGenerateStaticParams: Pass compiled route path
evaluateGenerateStaticParams->>NodeWorker: Spawn with react-server conditions
NodeWorker->>CompiledRouteModule: Import module and call generateStaticParams
CompiledRouteModule-->>NodeWorker: Return params or null
NodeWorker-->>evaluateGenerateStaticParams: Send IPC result
evaluateGenerateStaticParams-->>BuildPipeline: Resolve value or reject error
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/rari/src/router/build/vite-plugin.ts (1)
484-509: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winSequential subprocess spawn per dynamic route.
evaluateGenerateStaticParamsspawns a fresh Node process per call; awaiting it sequentially for every dynamic route means N routes incur N sequential process-startup costs duringcloseBundle. Consider evaluating routes concurrently (e.g.Promise.allwith a concurrency cap) to shrink build time on route-heavy apps.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/rari/src/router/build/vite-plugin.ts` around lines 484 - 509, Update the dynamic-route processing loop around evaluateGenerateStaticParams to evaluate multiple routes concurrently instead of awaiting each subprocess sequentially. Use Promise.all with a reasonable concurrency cap, while preserving existing route.staticParams updates, invalid-parameter warnings, and per-route error handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/rari/src/router/build/evaluate-static-params.ts`:
- Around line 29-65: Update the spawned worker flow in evaluateStaticParams to
enforce a timeout while awaiting child.on('close'). When the timeout expires,
kill the child process, clear any related timer during normal close or spawn
error, and reject with a descriptive timeout error; preserve the existing
nonzero-exit, JSON parsing, and successful resolution behavior.
- Around line 18-19: Replace the deprecated module.register() usage in the
worker setup with module.registerHooks(), passing the resolved hook
implementation so it is registered before the generated static-params module’s
dynamic import. Update the node:module import accordingly while preserving the
existing resolveHookUrl behavior.
- Around line 21-24: Remove the explicit process.exit(0) from the
missing-generateStaticParams branch in evaluate-static-params.ts. Preserve
writing "null" to stdout, then let the script terminate naturally without
continuing into subsequent evaluation logic.
In `@packages/rari/src/router/build/vite-plugin.ts`:
- Around line 493-502: Update the valid-array branch in the route processing
around evaluateGenerateStaticParams and isStaticParamsArray so every valid
static params array, including empty arrays, is assigned to route.staticParams
and sets updated to true. Preserve the existing handling for null results and
invalid non-array values, ensuring an empty result clears any stale
staticParams.
---
Outside diff comments:
In `@packages/rari/src/router/build/vite-plugin.ts`:
- Around line 484-509: Update the dynamic-route processing loop around
evaluateGenerateStaticParams to evaluate multiple routes concurrently instead of
awaiting each subprocess sequentially. Use Promise.all with a reasonable
concurrency cap, while preserving existing route.staticParams updates,
invalid-parameter warnings, and per-route error handling.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: b52120e6-1743-493c-9ed4-68857f6e4c34
📒 Files selected for processing (3)
packages/rari/src/router/build/evaluate-static-params.tspackages/rari/src/router/build/props-extractor.tspackages/rari/src/router/build/vite-plugin.ts
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/rari/src/router/build/evaluate-static-params.ts`:
- Around line 19-24: Update the static-params worker around generateStaticParams
to use a Node IPC channel instead of process.stdout.write for returning null or
generated params. Configure the worker and parent process with an ipc stdio
channel, send the serialized result through IPC, and have the parent consume
that message while continuing to drain stdout only for diagnostics.
- Around line 42-50: Update the timeout handler in the static-params evaluation
flow to terminate the worker unconditionally, replacing the current SIGTERM-only
cleanup with SIGKILL or a short-grace-period escalation to SIGKILL. Preserve the
existing timeout rejection and settled-state handling while ensuring the child
cannot remain alive after timeout.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 1c520979-4435-4157-9e1e-72f8fd442397
📒 Files selected for processing (2)
packages/rari/src/router/build/evaluate-static-params.tspackages/rari/src/router/build/vite-plugin.ts
…cess disconnect occurs after message is sent
Avoid loading react-server-dom-webpack/server in the Vite process, which triggered CJS named-export errors and broke client builds when --conditions=react-server was set globally.
Summary by CodeRabbit
generateStaticParamsin a more isolated and reliable way.generateStaticParamsis missing or invalid, with warnings instead of build failures.