-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
fix(webpack,rspack): preserve prerender + nitro flags in server builds #33503
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
Conversation
|
|
WalkthroughThe PR extends the internal env type for DefinePlugin to accept runtimeValue-derived entries and updates getEnv to inject client/server-specific environment globals. For client builds it defines process.prerender, process.nitro, import.meta.prerender and import.meta.nitro as false; for server builds it defines those keys as string references via runtimeValue and wraps runtime-evaluated values in an IIFE for runtime evaluation. Existing env entries and aggressiveCodeRemoval behaviour are preserved. Tests were adjusted to skip prerender-related cases only in development (removing isWebpack) and an error-boundary assertion now uses .first().waitFor() before asserting text. Estimated code review effortπ― 3 (Moderate) | β±οΈ ~25 minutes Pre-merge checks and finishing touchesβ Failed checks (1 warning)
β Passed checks (2 passed)
β¨ Finishing touches
π§ͺ Generate unit tests (beta)
π Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro π Files selected for processing (1)
π§ Files skipped from review as they are similar to previous changes (1)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
π§Ή Nitpick comments (1)
packages/webpack/src/presets/base.ts (1)
247-257: Client/server-aware environment variable handling correctly preserves prerender flags.The implementation correctly distinguishes between client and server builds:
- Client: Prerender and Nitro flags set to
false(clients don't participate in prerendering)- Server: Uses
DefinePlugin.runtimeValueto inject the flag names as code references, allowing Nitro to replace them with actual boolean values during prerender/buildThis solves the core issue where these values were previously replaced with
undefined, preventing Nitro from properly handling them.Consider adding a brief comment explaining why server builds use
runtimeValue:} else { + // Preserve prerender/nitro references for Nitro to replace at build/prerender time _env['process.prerender'] = webpack.DefinePlugin.runtimeValue(() => 'import.meta.prerender', true) _env['process.nitro'] = webpack.DefinePlugin.runtimeValue(() => 'process.nitro', true) _env['import.meta.prerender'] = webpack.DefinePlugin.runtimeValue(() => 'import.meta.prerender', true) _env['import.meta.nitro'] = webpack.DefinePlugin.runtimeValue(() => 'import.meta.nitro', true) }
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (2)
packages/webpack/src/presets/base.ts(2 hunks)test/basic.test.ts(3 hunks)
π§° Additional context used
π Path-based instructions (2)
**/*.{ts,tsx}
π CodeRabbit inference engine (.github/copilot-instructions.md)
Follow standard TypeScript conventions and best practices
Files:
packages/webpack/src/presets/base.tstest/basic.test.ts
**/*.{test,spec}.{ts,tsx,js,jsx}
π CodeRabbit inference engine (.github/copilot-instructions.md)
Write unit tests for core functionality using
vitest
Files:
test/basic.test.ts
𧬠Code graph analysis (2)
packages/webpack/src/presets/base.ts (1)
packages/webpack/builder.d.ts (1)
webpack(6-6)
test/basic.test.ts (1)
test/matrix.ts (1)
isDev(6-6)
β° Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
- GitHub Check: test-fixtures (windows-latest, dev, vite, default, manifest-off, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, rspack, async, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, rspack, default, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-off, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, webpack, default, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-on, js, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-off, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-off, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, vite-env-api, async, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, dev, vite-env-api, async, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, dev, vite-env-api, default, manifest-on, json, lts/-1)
- GitHub Check: test-benchmark
- GitHub Check: release-pkg-pr-new
- GitHub Check: typecheck (ubuntu-latest, bundler)
- GitHub Check: typecheck (windows-latest, bundler)
- GitHub Check: test-size
- GitHub Check: code
π Additional comments (4)
test/basic.test.ts (3)
624-627: Test now runs for webpack builds.With the fix in
packages/webpack/src/presets/base.ts, prerender flags are correctly preserved in webpack server builds, allowing this test to run successfully.
1234-1234: Improved selector specificity with.first().Adding
.first()before.waitFor()ensures a single element is selected before waiting, which is good practice when the text selector might match multiple elements.Was there a specific flakiness issue that prompted this change, or is it a defensive improvement?
2046-2054: Test now runs for webpack builds.Server-only components can now correctly set prerender hints with webpack builds, thanks to the
DefinePlugin.runtimeValuefix that preserves prerender references for Nitro.packages/webpack/src/presets/base.ts (1)
230-230: Type widened to accommodateDefinePlugin.runtimeValue.The type correctly includes webpack's DefinePlugin definitions to support the runtime value references added below for server builds.
@nuxt/kit
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
CodSpeed Performance ReportMerging #33503 will not alter performanceComparing Summary
|
ac93177 to
9fe0c8f
Compare
π Linked issue
π Description
previously
import.meta.prerenderwas being replaced byundefinedin the server webpack/rspack build and so nitro couldn't replace this with true/false during prerender/built, meaning a whole host of server code wasn't working properly in prerender mode.this fixes the issue by preserving the value.