Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@danielroe
Copy link
Member

@danielroe danielroe commented Oct 17, 2025

πŸ”— Linked issue

πŸ“š Description

previously import.meta.prerender was being replaced by undefined in 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.

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@coderabbitai
Copy link

coderabbitai bot commented Oct 17, 2025

Walkthrough

The 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)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
βœ… Passed checks (2 passed)
Check name Status Explanation
Title Check βœ… Passed The pull request title "fix(webpack,rspack): preserve prerender + nitro flags in server builds" directly and precisely describes the main objective of the changeset. According to the raw summary, the changes to packages/webpack/src/presets/base.ts specifically focus on preserving prerender and nitro flags by setting them to string literals on the server path, which aligns perfectly with the title's description. The title is concise, clear, and avoids vague terminology, making it easy for someone reviewing the repository history to understand the primary change at a glance.
Description Check βœ… Passed The pull request description is directly related to the changeset and provides meaningful context about the issue being fixed. It explains that import.meta.prerender was previously being replaced with undefined in server webpack/rspack builds, which prevented Nitro from replacing the value during prerender/build, and states that the fix preserves the value. This description accurately reflects the core changes documented in the raw summary, where the env type is widened and prerender/nitro flags are preserved by setting them to string literals in the server build path.
✨ Finishing touches
  • πŸ“ Generate docstrings
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/preserve-prerender

πŸ“œ Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between ac93177 and 9fe0c8f.

πŸ“’ Files selected for processing (1)
  • packages/webpack/src/presets/base.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/webpack/src/presets/base.ts

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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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.runtimeValue to inject the flag names as code references, allowing Nitro to replace them with actual boolean values during prerender/build

This 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

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 39dd9b6 and 3d063e2.

πŸ“’ 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.ts
  • test/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.runtimeValue fix that preserves prerender references for Nitro.

packages/webpack/src/presets/base.ts (1)

230-230: Type widened to accommodate DefinePlugin.runtimeValue.

The type correctly includes webpack's DefinePlugin definitions to support the runtime value references added below for server builds.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 17, 2025

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@33503

nuxt

npm i https://pkg.pr.new/nuxt@33503

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@33503

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@33503

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@33503

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@33503

commit: 9fe0c8f

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 17, 2025

CodSpeed Performance Report

Merging #33503 will not alter performance

Comparing fix/preserve-prerender (9fe0c8f) with main (dd52239)

Summary

βœ… 10 untouched

@danielroe danielroe force-pushed the fix/preserve-prerender branch from ac93177 to 9fe0c8f Compare October 17, 2025 19:46
@danielroe danielroe merged commit 185025b into main Oct 17, 2025
55 checks passed
@danielroe danielroe deleted the fix/preserve-prerender branch October 17, 2025 20:25
This was referenced Oct 17, 2025
@github-actions github-actions bot mentioned this pull request Oct 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants