Emit HTTP 308 for published slug aliases before HTML - #9
Merged
Conversation
generateMetadata returned Not found + noindex and the root layout started the document, so page-level permanentRedirect could only stream a meta refresh. Look up the alias in generateMetadata and return NextResponse 308 from proxy before render. Co-authored-by: Chinmay Kabi <chinmay@blend.to>
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
Chinmay-KB
marked this pull request as ready for review
August 13, 2026 14:06
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
TL;DR
/g/microsoft-teams-tinderwas HTTP 200 HTML titled “Not found” withnoindex, then a streamed meta 308 to/g/microsoft-teams-tinder-1. Crawlers that only read the status line never saw a redirect.This PR returns a real HTTP 308 with
Locationbefore any HTML, using the existing{slug}→ lowest{slug}-{digits}alias lookup.Root cause
The user’s guess was right.
generateMetadataran first. The unsuffixed slug is not a generation row, so it returned{ title: "Not found", robots: { index: false, follow: false } }.permanentRedirectran afterward. In a streaming context Next can only injectNEXT_REDIRECT;replace;…;308;plus<meta http-equiv="refresh">— not a real status-line 308.permanentRedirectin a Server Component cannot change headers after HTML has started.What changed
src/proxy.ts— for/g/{slug}only, if the exact slug is not a published generation and a numeric alias exists,NextResponse.redirect(..., 308)runs before render. That is whatcurl -sIwill see.generateMetadata— same alias lookup before returning the not-found metadata, so we never commit “Not found” +noindexon an alias URL if render still happens.permanentRedirectkept as a fallback, via a shared helper.src/lib/published-slug-alias.tsso proxy does not import the heavy generation module. Exact published slugs are not redirected (/g/foostays when/g/foois live, even if/g/foo-1exists).No OG, sitemap, cards, watermarks, or other site-health work.
How to confirm
Expect 308 (or 301) and
Locationcontaining/g/microsoft-teams-tinder-1, with no HTML body on that first response.Locally:
yarn test(98 passed, including new alias-redirect cases) andyarn lint(0 errors).