Skip to content

fix: resolve /404 route collision and prerender header warnings#313

Merged
rachaelrenk merged 2 commits into
mainfrom
rrenk/fix-404-route-collision
Jul 9, 2026
Merged

fix: resolve /404 route collision and prerender header warnings#313
rachaelrenk merged 2 commits into
mainfrom
rrenk/fix-404-route-collision

Conversation

@rachaelrenk

@rachaelrenk rachaelrenk commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Two build-health fixes for the docs site, both surfaced while investigating the token-usage guide PR (#269) Vercel preview:

  1. Resolves the /404 route collision (which Astro warns will become a hard error in a future version).
  2. Eliminates the Astro.request.headers-on-prerendered-pages warning (~692 per build).

Changes

1. /404 route collision

  • Delete src/pages/404.astro — a second /404 route that collided with Starlight's built-in one (@astrojs/starlight/routes/static/404.astro).
  • Add src/content/docs/404.mdx — Starlight's supported content-collection 404 override (get404RoutegetEntry('docs', '404')), so there is a single prerendered /404 route.
  • Add src/components/Docs404Tracking.astro — holds the docs_404 Rudderstack tracking script (kept in an .astro component because MDX parses {/} as expressions).

2. Astro.request.headers warning

  • src/middleware.ts (content negotiation) called shouldServeMarkdown(request), reading request.headers on every route. During the static prerender pass there is no real request, so Astro warned "Astro.request.headers is not available on prerendered pages" ~692 times per build. Guarded with context.isPrerendered so the header read only runs for on-demand (SSR) requests. Runtime markdown content negotiation is unchanged.

Preserves the 404 monitoring pipeline

The custom 404 fires a docs_404 Rudderstack event with the broken URL, consumed by the weekly-404-monitor agent (queries docs_404 from BigQuery). This PR keeps that contract identical — same docs_404 event name and broken_url / referrer properties — so the monitor is unaffected. Verified the built 404.html still contains the tracking.

Validation

  • npm run build passes (346 pages).
  • /404 route-collision warning: gone.
  • Astro.request.headers warnings: 692 → 0.
  • docs_404 present in both dist/404.html and .vercel/output/static/404.html.
  • style_lint: 0 issues on the new page.

Context

Follow-up from the token-usage guide PR (#269): its failing Vercel preview led to investigating these. That Vercel failure was transient and is now green; this PR proactively removes the latent collision and clears the header-warning noise.

Conversation: https://staging.warp.dev/conversation/a00f71f5-5c1a-450b-ada7-0d6180380fe3

Co-Authored-By: Oz oz-agent@warp.dev

Replace src/pages/404.astro (a second /404 route that collided with Starlight's built-in one, which Astro warns will become a hard error) with src/content/docs/404.mdx, Starlight's supported content-collection 404 override. The docs_404 Rudderstack tracking consumed by the weekly-404-monitor moves into a small Docs404Tracking.astro component and is preserved unchanged (event name + broken_url). Local build passes; the /404 collision warning is gone and docs_404 is present in the built 404.html.

Co-Authored-By: Oz <oz-agent@warp.dev>
@cla-bot cla-bot Bot added the cla-signed label Jul 9, 2026
@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Jul 9, 2026 8:26pm

Request Review

@oz-for-oss

oz-for-oss Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

@rachaelrenk

I'm starting a first review of this pull request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@oz-for-oss oz-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This PR removes the project-level src/pages/404.astro route that collides with Starlight's injected /404 route, replaces it with Starlight's supported src/content/docs/404.mdx content override, and preserves the existing docs_404 Rudderstack tracking payload in a dedicated Astro component.

Concerns

  • No blocking correctness, security, or spec-alignment concerns found in the annotated diff.
  • spec_context.md reports that no approved or repository spec context was found, so there was no spec contract to validate beyond the PR description and diff.

Verdict

Found: 0 critical, 0 important, 0 suggestions

Approve

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

The content-negotiation middleware read request.headers on every route, which warned 'Astro.request.headers not available on prerendered pages' ~692x during the static build. Guard with context.isPrerendered so headers are only read for on-demand (SSR) requests; runtime markdown negotiation is unchanged. Build warnings drop from 692 to 0.

Co-Authored-By: Oz <oz-agent@warp.dev>
@rachaelrenk rachaelrenk changed the title fix(404): resolve /404 route collision via Starlight content 404 fix: resolve /404 route collision and prerender header warnings Jul 9, 2026
@rachaelrenk rachaelrenk self-assigned this Jul 9, 2026

@hongyi-chen hongyi-chen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice fix, ty!

@rachaelrenk rachaelrenk merged commit 2c026a1 into main Jul 9, 2026
8 checks passed
@rachaelrenk rachaelrenk deleted the rrenk/fix-404-route-collision branch July 9, 2026 22:04
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