fix(analyze): skip prerendering routes when building#1400
Conversation
commit: |
📝 WalkthroughWalkthroughThe Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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.
🧹 Nitpick comments (2)
packages/nuxt-cli/test/unit/commands/analyze.spec.ts (1)
90-112: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider adding a singular-route case.
Coverage looks solid overall, but no test exercises the
skippedPrerenderRoutes === 1branch ("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 winDocument why both
ignoreandroutes.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 intonitro.options.prerender.routesbefore this hook runs). Theignore: [() => true]is a backstop for any route re-added by another module'sprerender:routeslistener 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
📒 Files selected for processing (3)
packages/nuxt-cli/src/commands/analyze.tspackages/nuxt-cli/test/unit/commands/analyze.spec.tspackages/nuxt-cli/test/unit/help.spec.ts
🔗 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