fix: make nextjs prefetches aware of custom domains#2941
Merged
huumn merged 1 commit intostackernews:masterfrom May 2, 2026
Merged
fix: make nextjs prefetches aware of custom domains#2941huumn merged 1 commit intostackernews:masterfrom
huumn merged 1 commit intostackernews:masterfrom
Conversation
Member
|
clean! |
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.
Description
Prefetch requests are ignored by our middleware, making custom domains lose their domain status when clicking to links that have been prefetched.
This PR ensures that prefetch requests still go through the custom domain middleware, while still skipping referral and CSP.
Additional Context
The patch revolves around running the custom domain middleware on prefetches too, on normal
stacker.newsnavigation prefetches are still ignored by the middleware.Checklist
Are your changes backward compatible? Please answer below:
For example, a change is not backward compatible if you removed a GraphQL field or dropped a database column.
On a scale of 1-10 how well and how have you QA'd this change and any features it might affect? Please answer below:
7, works correctly, fixes prefetched navigation in prod. Tested in a local production environment.
For frontend changes: Tested on mobile, light and dark mode? Please answer below:
n/a
Did you introduce any new environment variables? If so, call them out explicitly here:
n/a
Did you use AI for this? If so, how much did it assist you?
local production support
Note
Medium Risk
Changes request handling in edge middleware for prefetch traffic and alters how CSP/security headers are applied, which could affect navigation behavior and caching for custom domains if misdetected.
Overview
Ensures Next.js prefetch requests are custom-domain aware by detecting prefetches (
next-router-prefetch/purpose: prefetch) and routing them throughcustomDomainMiddlewarewhen a domain mapping exists.Prefetch requests now skip referrer attribution and CSP/security headers, and the middleware
matcherno longer excludes prefetches viamissingheader rules (prefetch handling is done in code instead).Reviewed by Cursor Bugbot for commit c507723. Bugbot is set up for automated code reviews on this repo. Configure here.