feat(seo): serve a build-time docs API snapshot during prerender capture - #4531
Conversation
…rerender snapshot (#4530)
|
Warning Review limit reached
Next review available in: 54 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
WalkthroughThe change adds build-time API and Markdown snapshots for documentation SEO prerendering. The prerender plugin matches snapshot-backed GET requests by pathname and handles matching CORS preflights. ChangesDocumentation snapshot prerendering
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant DocsSEO
participant DocsAPI
participant PrerenderPlugin
participant BrowserRequest
DocsSEO->>DocsAPI: fetch docs tree and Markdown articles
DocsSEO->>PrerenderPlugin: provide apiSnapshot
PrerenderPlugin->>BrowserRequest: enable request interception
BrowserRequest->>PrerenderPlugin: send GET request
PrerenderPlugin-->>BrowserRequest: return matching snapshot response
🚥 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4531 +/- ##
==========================================
+ Coverage 99.57% 99.58% +0.01%
==========================================
Files 36 36
Lines 1411 1462 +51
Branches 439 457 +18
==========================================
+ Hits 1405 1456 +51
Misses 6 6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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 `@src/lib/plugins/prerender.js`:
- Around line 235-261: Guard both req.respond() calls in the prerender handler
with a rejected-promise catch, matching the existing req.continue() handling. In
src/lib/plugins/tests/prerender.unit.tests.js lines 273-326 and 328-365, update
the respond fakes for hit, hitNoOrigin, miss, preflight, and preflightMiss to
return resolved promises via mockResolvedValue(undefined).
In `@src/lib/plugins/tests/prerender.unit.tests.js`:
- Around line 238-271: Add a test alongside the existing prerender interception
tests that configures apiSnapshot as an empty object, invokes
prerenderPlugin(...).closeBundle(), and verifies mockPage.setRequestInterception
and mockPage.on are not called. Preserve the existing console.log mocking and
restoration pattern.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 67e781d8-518d-4a98-ab75-c0a387a83401
📒 Files selected for processing (4)
src/lib/plugins/docs-seo.jssrc/lib/plugins/prerender.jssrc/lib/plugins/tests/docs-seo.unit.tests.jssrc/lib/plugins/tests/prerender.unit.tests.js
Puppeteer's HTTPRequest.respond() returns a promise that can reject
(e.g. request already handled, page closed). Both respond() calls in
the snapshot interception handler were unguarded while the sibling
req.continue() already carried a .catch(() => {}). Chain the same
no-op catch on both, and stop faking respond() as synchronous in the
unit tests (mockResolvedValue) so the gap is test-detectable. Also add
coverage for the apiSnapshot: {} branch, pinning that interception
stays off for an empty (but present) snapshot object.
Addresses CodeRabbit review on PR #4531.
Summary
docs-seo.jsalready fetches the guide tree at build time; it now also fetches each guide's raw markdown and attaches a build-time API snapshot (app.seo.prerender.apiSnapshot, keyed by URL pathname →{ body, contentType }, with a wire-shape envelope for the tree matching the runtime API response).prerenderPluginserves that snapshot via Puppeteer request interception: GET requests are matched by pathname only (origin-agnostic), guide slugs are URL-encoded the same way the runtime client encodes them, CORS preflights (OPTIONS) are self-served, and the reflected origin + credentials are echoed back. Prerender capture becomes hermetic — it no longer depends on the API being reachable from wherever the build runs. Missing/failed per-guide fetches fail soft (that one route falls back to the empty state) rather than failing the whole prerender pass.Scope
src/lib/plugins/docs-seo.js,src/lib/plugins/prerender.js(+ their unit test files)nonelowValidation
npm run lintnpm run test:unitnpm run build68 unit tests added/updated across the two plugin test files; full suite 2551 tests green; coverage 99% statements.
Guardrails check
.env*,secrets/**, keys, tokens)Notes for reviewers
Summary by CodeRabbit
New Features
Bug Fixes