Skip to content

fix: evaluate generateStaticParams under react-server condition - #328

Merged
skiniks merged 4 commits into
mainfrom
burning-damselfly
Jul 29, 2026
Merged

fix: evaluate generateStaticParams under react-server condition#328
skiniks merged 4 commits into
mainfrom
burning-damselfly

Conversation

@skiniks

@skiniks skiniks commented Jul 29, 2026

Copy link
Copy Markdown
Member

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

  • Bug Fixes
    • Improved dynamic route static-parameter generation by evaluating generateStaticParams in a more isolated and reliable way.
    • Added bounded-concurrency evaluation for faster, safer manifest enrichment.
    • Validates returned values and falls back to empty results when generateStaticParams is missing or invalid, with warnings instead of build failures.
    • Enhanced resilience and diagnostics when evaluation fails, including clearer timeout handling.

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.
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 51baaef5-f863-4e68-a504-e4c27fd2bd49

📥 Commits

Reviewing files that changed from the base of the PR and between 38a2755 and 0da40ec.

📒 Files selected for processing (1)
  • packages/rari/src/router/build/evaluate-static-params.ts

📝 Walkthrough

Walkthrough

Static 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.

Changes

Static params evaluation

Layer / File(s) Summary
Worker evaluator and resolve hook
packages/rari/src/router/build/evaluate-static-params.ts
Adds worker-based ESM evaluation of generateStaticParams, IPC result handling, timeout termination, and process diagnostics.
Static params pipeline integration
packages/rari/src/router/build/props-extractor.ts, packages/rari/src/router/build/vite-plugin.ts
Uses the evaluator for extraction and manifest enrichment, validates static-parameter arrays, warns on invalid results, and evaluates dynamic routes with bounded concurrency.

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
Loading

Possibly related PRs

  • rari-build/rari#305: Updates adjacent compiled dynamic-route module resolution in vite-plugin.ts.

Poem

I’m a rabbit hopping through the build,
While worker paths are safely filled.
Static params bloom in IPC light,
RSC imports resolve just right.
Routes gain their manifest cheer—
Hop, hop, clean builds are here! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is only a one-line summary and misses nearly all required template sections like Summary, Changes Made, Testing, and Checklist. Expand the PR description to follow the template, including Summary, Type of Change, Related Issues, Motivation, Changes Made, Testing, and Checklist.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: evaluating generateStaticParams under react-server conditions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch burning-damselfly

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread packages/rari/src/router/build/evaluate-static-params.ts Outdated
@codspeed-hq

codspeed-hq Bot commented Jul 29, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 12 untouched benchmarks


Comparing burning-damselfly (0da40ec) with main (732b71e)

Open in CodSpeed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Sequential subprocess spawn per dynamic route.

evaluateGenerateStaticParams spawns a fresh Node process per call; awaiting it sequentially for every dynamic route means N routes incur N sequential process-startup costs during closeBundle. Consider evaluating routes concurrently (e.g. Promise.all with 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

📥 Commits

Reviewing files that changed from the base of the PR and between 732b71e and 4e80d83.

📒 Files selected for processing (3)
  • packages/rari/src/router/build/evaluate-static-params.ts
  • packages/rari/src/router/build/props-extractor.ts
  • packages/rari/src/router/build/vite-plugin.ts

Comment thread packages/rari/src/router/build/evaluate-static-params.ts Outdated
Comment thread packages/rari/src/router/build/evaluate-static-params.ts Outdated
Comment thread packages/rari/src/router/build/evaluate-static-params.ts
Comment thread packages/rari/src/router/build/vite-plugin.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4e80d83 and a95a568.

📒 Files selected for processing (2)
  • packages/rari/src/router/build/evaluate-static-params.ts
  • packages/rari/src/router/build/vite-plugin.ts

Comment thread packages/rari/src/router/build/evaluate-static-params.ts Outdated
Comment thread packages/rari/src/router/build/evaluate-static-params.ts Outdated
Comment thread packages/rari/src/router/build/evaluate-static-params.ts
…cess disconnect occurs after message is sent
@skiniks
skiniks merged commit d44ed8d into main Jul 29, 2026
22 checks passed
@skiniks
skiniks deleted the burning-damselfly branch July 29, 2026 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant