Skip to content

fix(analyze): skip prerendering routes when building#1400

Merged
danielroe merged 1 commit into
mainfrom
fix/disable-prerender
Jul 26, 2026
Merged

fix(analyze): skip prerendering routes when building#1400
danielroe merged 1 commit into
mainfrom
fix/disable-prerender

Conversation

@danielroe

Copy link
Copy Markdown
Member

🔗 Linked issue

resolves #328

📚 Description

mostly when running analysis, users do not want their whole site to be prerendered. this can be overridden with nuxt analyze --prerender

@pkg-pr-new

pkg-pr-new Bot commented Jul 26, 2026

Copy link
Copy Markdown
  • nuxt-cli-playground

    npm i https://pkg.pr.new/create-nuxt@1400
    
    npm i https://pkg.pr.new/nuxi@1400
    
    npm i https://pkg.pr.new/@nuxt/cli@1400
    

commit: 01c7607

@codspeed-hq

codspeed-hq Bot commented Jul 26, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing fix/disable-prerender (01c7607) with main (b6f5b11)

Open in CodSpeed

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The nuxt analyze command adds a --prerender option. By default, Nitro route crawling and prerendered routes are disabled while skipped routes are counted and reported. Passing --prerender preserves prerendering. Unit tests cover both modes and output behavior, and the help snapshot documents the new option.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the analyze prerendering behavior change.
Description check ✅ Passed The description matches the change and explains the new --prerender override.
Linked Issues check ✅ Passed The changes prevent analyze from prerendering routes by default, including routeRules-driven prerendering.
Out of Scope Changes check ✅ Passed The added tests and help snapshot are directly related to the analyze prerendering change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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 fix/disable-prerender

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.

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

🧹 Nitpick comments (2)
packages/nuxt-cli/test/unit/commands/analyze.spec.ts (1)

90-112: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider adding a singular-route case.

Coverage looks solid overall, but no test exercises the skippedPrerenderRoutes === 1 branch ("1 route" vs "2 routes" in the message at analyze.ts Line 154).

✅ Suggested addition
+  it('should use singular wording for a single skipped route', async () => {
+    const { output } = await runAnalyze({ routes: ['/'] })
+    expect(output).toContain('Skipped prerendering 1 route.')
+  })
🤖 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/nuxt-cli/test/unit/commands/analyze.spec.ts` around lines 90 - 112,
Extend the analyze command tests around the existing “should report the routes
it skipped prerendering” case to cover exactly one skipped route. Use runAnalyze
with a single route, then assert the output uses the singular “1 route” wording
and still references --prerender, without expecting the plural form.
packages/nuxt-cli/src/commands/analyze.ts (1)

108-131: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document why both ignore and routes.clear() are needed.

This combination is correct but non-obvious: routes.clear() handles Nitro's early-return path (routes.size === 0 && !crawlLinks → skip prerendering entirely), which is what actually blocks routeRules-derived routes (including wildcard /** rules that Nitro/Nuxt expand into nitro.options.prerender.routes before this hook runs). The ignore: [() => true] is a backstop for any route re-added by another module's prerender:routes listener registered after this one in the hook chain. Without a comment, a future refactor could drop one of the two, silently reintroducing the exact routeRules-prerendering bug this PR fixes.

📝 Suggested comment
+        // Belt-and-braces: `routes.clear()` below stops Nitro's early-return
+        // path (covers routeRules-derived routes, including wildcards), while
+        // `ignore` guards against routes re-added by other modules' later
+        // `prerender:routes` listeners.
         ...(!ctx.args.prerender && {
           nitro: {
             prerender: {
🤖 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/nuxt-cli/src/commands/analyze.ts` around lines 108 - 131, Add a
concise explanatory comment beside the non-prerender Nitro configuration and
prerender:routes hook, documenting that ignore blocks routes re-added by later
listeners while routes.clear() triggers Nitro’s early-return path and prevents
routeRules-derived routes from being prerendered. Keep both safeguards
unchanged.
🤖 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.

Nitpick comments:
In `@packages/nuxt-cli/src/commands/analyze.ts`:
- Around line 108-131: Add a concise explanatory comment beside the
non-prerender Nitro configuration and prerender:routes hook, documenting that
ignore blocks routes re-added by later listeners while routes.clear() triggers
Nitro’s early-return path and prevents routeRules-derived routes from being
prerendered. Keep both safeguards unchanged.

In `@packages/nuxt-cli/test/unit/commands/analyze.spec.ts`:
- Around line 90-112: Extend the analyze command tests around the existing
“should report the routes it skipped prerendering” case to cover exactly one
skipped route. Use runAnalyze with a single route, then assert the output uses
the singular “1 route” wording and still references --prerender, without
expecting the plural form.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c87cee36-e45f-4070-a368-417f2e718b51

📥 Commits

Reviewing files that changed from the base of the PR and between b6f5b11 and 01c7607.

📒 Files selected for processing (3)
  • packages/nuxt-cli/src/commands/analyze.ts
  • packages/nuxt-cli/test/unit/commands/analyze.spec.ts
  • packages/nuxt-cli/test/unit/help.spec.ts

@danielroe
danielroe merged commit c3c9e90 into main Jul 26, 2026
20 checks passed
@danielroe
danielroe deleted the fix/disable-prerender branch July 26, 2026 22:05
@github-actions github-actions Bot mentioned this pull request Jul 26, 2026
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.

analyze should not prerender routes when specified via routeRules

1 participant