-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(nextjs): Give app router prefetch requests a http.server.prefetch
op
#13600
Conversation
size-limit report 📦
|
This is a probabilistic feature because for various reasons I wasn't able to write tests for it:
Timebox overflow -> abort mission. Highly frustrating, I am done trying to get this to work. |
*/ | ||
function isKnownPrefetchRequest(req: HTTPModuleRequestIncomingMessage): boolean { | ||
// Currently only handles Next.js prefetch requests but may check other frameworks in the future. | ||
return req.headers['next-router-prefetch'] === '1'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we look at the Sec-Purpose
header instead? This should work with all header types.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-Purpose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wait it's not standardized 😭 https://chromestatus.com/feature/6247959677108224
Ref (not complete fix) #13596
This gives Next.js prefetch requests a
http.server.prefetch
op, when aNext-Router-Prefetch: 1
header is present.In some situations Next.js doesn't seem to attach the header for prefetch requests. Seems like it is only attached when the current route is a dynamic route.