Skip to content

feat(seo): serve a build-time docs API snapshot during prerender capture - #4531

Merged
PierreBrisorgueil merged 5 commits into
masterfrom
feat/4530-prerender-api-snapshot
Aug 3, 2026
Merged

feat(seo): serve a build-time docs API snapshot during prerender capture#4531
PierreBrisorgueil merged 5 commits into
masterfrom
feat/4530-prerender-api-snapshot

Conversation

@PierreBrisorgueil

@PierreBrisorgueil PierreBrisorgueil commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • What changed: prerendered routes whose components fetch content from the API at runtime used to capture the empty fail-soft state during prerender capture, because the page's API fetch depends on the API being reachable from the build environment (container builds and origin mismatches routinely break that reachability). docs-seo.js already 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). prerenderPlugin serves 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.
  • Why: closes the gap where a build environment (CI runner, container, different origin) can't reach the live API, silently shipping empty prerendered pages for any route that fetches API content client-side.
  • Related issues: Closes 🐛 Prerender captures empty API-dependent pages — serve a build-time content snapshot during capture #4530

Scope

  • Modules impacted: src/lib/plugins/docs-seo.js, src/lib/plugins/prerender.js (+ their unit test files)
  • Cross-module impact: none
  • Risk level: low

Validation

  • npm run lint
  • npm run test:unit
  • npm run build
  • Manual checks done (if applicable) — verified end-to-end on a downstream consumer's production-mode build (prerendered article pages ship real bodies + nav, not the empty fail-soft state)

68 unit tests added/updated across the two plugin test files; full suite 2551 tests green; coverage 99% statements.

Guardrails check

  • No secrets or credentials introduced (.env*, secrets/**, keys, tokens)
  • No risky rename/move of core stack paths
  • Changes remain merge-friendly for downstream projects
  • Tests added or updated when behavior changed

Notes for reviewers

  • Security considerations: the interception only serves build-time-fetched, same-repo guide content back to the prerender browser context during the build step itself — it never runs at request-serving time and introduces no new runtime attack surface. CORS preflight responses reflect the request's own origin/credentials, matching the runtime API's existing CORS behavior rather than widening it.
  • Mergeability considerations: additive-only change to the two plugin files; no touched shared config surface.
  • Follow-up tasks (optional): none

Summary by CodeRabbit

  • New Features

    • Added snapshot-backed API responses during prerendering for documentation pages.
    • Documentation guides can now include prerendered Markdown article content.
    • Supports endpoint URL normalization, encoded guide slugs, and CORS preflight requests.
    • Unmatched requests continue normally during prerendering.
  • Bug Fixes

    • Added fail-soft handling for malformed URLs, unavailable fetch functionality, failed requests, and missing content.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@PierreBrisorgueil, you've reached your PR review limit, so we couldn't start this review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a185c3be-1f43-4886-a6c6-9856819a28c9

📥 Commits

Reviewing files that changed from the base of the PR and between 96007c9 and 3a56ed5.

📒 Files selected for processing (2)
  • src/lib/plugins/prerender.js
  • src/lib/plugins/tests/prerender.unit.tests.js

Walkthrough

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

Changes

Documentation snapshot prerendering

Layer / File(s) Summary
Build-time snapshot collection
src/lib/plugins/docs-seo.js, src/lib/plugins/tests/docs-seo.unit.tests.js
Docs SEO derives tree and article snapshot entries, fetches Markdown articles, handles failures fail-soft, and adds apiSnapshot to the prerender configuration.
Prerender request interception
src/lib/plugins/prerender.js, src/lib/plugins/tests/prerender.unit.tests.js
Prerendering matches valid GET requests by pathname, serves snapshot responses, handles CORS preflights, and continues unmatched requests.

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
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: serving a build-time docs API snapshot during SEO prerender capture.
Description check ✅ Passed The description covers the required summary, scope, validation, guardrails, risks, and reviewer notes with specific implementation details.
Linked Issues check ✅ Passed The changes satisfy issue #4530 by fetching docs content, serving pathname-based snapshots, preserving fail-soft behavior, and adding tests.
Out of Scope Changes check ✅ Passed All changes are limited to docs SEO snapshot generation, prerender interception, and related unit tests required by issue #4530.
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 feat/4530-prerender-api-snapshot

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.

@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.58%. Comparing base (cbf4947) to head (3a56ed5).
⚠️ Report is 2 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@PierreBrisorgueil
PierreBrisorgueil marked this pull request as ready for review August 3, 2026 11:56

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1ab89c4 and 96007c9.

📒 Files selected for processing (4)
  • src/lib/plugins/docs-seo.js
  • src/lib/plugins/prerender.js
  • src/lib/plugins/tests/docs-seo.unit.tests.js
  • src/lib/plugins/tests/prerender.unit.tests.js

Comment thread src/lib/plugins/prerender.js Outdated
Comment thread src/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.
@PierreBrisorgueil
PierreBrisorgueil merged commit ea3e6b9 into master Aug 3, 2026
7 checks passed
@PierreBrisorgueil
PierreBrisorgueil deleted the feat/4530-prerender-api-snapshot branch August 3, 2026 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Prerender captures empty API-dependent pages — serve a build-time content snapshot during capture

1 participant