fix(site-docs): return HTTP 404 for unknown routes (stop soft-404) - #383
Merged
Conversation
Prerender a dedicated 404 document to 404.html so Cloudflare Pages (and vite preview) stop SPA-falling unknown URLs back to the homepage. The page uses its own title and noindex, and does not canonicalize to /. Model: Cursor Grok 4.6 Co-authored-by: Zixuan Chen <zx@loro.dev>
A root splat and a Vite preview 404 middleware both broke TanStack prerender: the preview server is how pages are fetched before they exist on disk. Emulate Cloudflare Pages with preview:static instead. Model: Cursor Grok 4.6 Co-authored-by: Zixuan Chen <zx@loro.dev>
Pretty-URL mapping /404 → 404.html would serve the not-found file as HTTP 200. Cloudflare Pages uses that file as the 404 document. Model: Cursor Grok 4.6 Co-authored-by: Zixuan Chen <zx@loro.dev>
Serving the prerendered /404 document at an unknown URL booted the client router against that path and blanked the page. Strip app module scripts from 404.html after prerender. Model: Cursor Grok 4.6 Co-authored-by: Zixuan Chen <zx@loro.dev>
This was referenced Sep 4, 2026
zxch3n
marked this pull request as ready for review
September 4, 2026 10:57
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Unknown URLs on
https://lody.aiwere soft-404s: HTTP 200, homepage title/description/OG, and<link rel="canonical" href="https://lody.ai/">. Crawlers treated junk paths as duplicate homepage.Production repro (before):
Same for unknown
/docs/...paths.Root cause
site-docsis static (TanStack Start prerender →out/clienton Cloudflare Pages). There was no root404.html. Cloudflare then treats the site as an SPA and servesindex.htmlwith 200. Dev/SSR already returned 404; production static hosting did not./appis a separate product HTML on the same host (<title>Lody</title>). A catch-all_redirects/* /index.html 200would steal it. This PR does not add that.Fix
SiteNotFound,/404,/zh/404): titlePage not found | Lody/页面不存在 | Lody;noindex, follow; no canonical and noog:url./404→404.html(autoSubfolderIndex: false).404.htmlafter prerender (scripts/finalize-404-html.mjs). Hydrating the app on a junk URL blanked the page / showed "Something went wrong". Static 404 is now a complete HTML document.scripts/static-host.mjs+preview:static): missing files → HTTP 404 +404.html. Pretty/404also 404 (error document, not a 200 page).head()usesnotFoundHeadinstead of index/homepage head./404,/zh/404,/home,/zh/home.SEO choice: static
404.htmlcannot bake a per-request canonical.noindex, follow+ no canonical is correct. Homepage canonical was the bug.Local commands
Do not add Vite
configurePreviewServer404 middleware — TanStack prerender usesvite.preview()to fetch pages before they exist on disk.Curl evidence (
preview:static:4173)Adversarial review
/docs/.../nope/zh/+ zh docsindex, follow/404404.html/app_redirectsResidual risks
/* /index.html 200) could still win over404.html. Confirm Pages settings after deploy.404.htmlfor all unknown URLs (locale-specific first paint is a follow-up).vite dev404 title is still root"Lody Docs"(HTTP 404, no homepage canonical). Crawlers hit static404.html./404itself is HTTP 200 (failOnErrorrequiresres.ok).Walkthrough
Unknown URL shows dedicated Not Found page
Document title is Page not found | Lody
Homepage still 200 after visiting 404
Unknown docs path is Not Found
Real docs introduction still 200
Chinese homepage still 200
soft_404_fixed_unknown_url_and_known_pages.mp4
To show artifacts inline, enable in settings.