-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
fix: set x-deployment-id to every middleware prefetch request #71193
fix: set x-deployment-id to every middleware prefetch request #71193
Conversation
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
isPrefetch && hasMiddleware | ||
? { | ||
'x-middleware-prefetch': '1', | ||
'x-deployment-id': process.env.NEXT_DEPLOYMENT_ID, |
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.
I think we should just ensure this header is always passed for requests, even if they're not prefetch / middleware is present.
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.
Just bumping this, if you're able to make this change we could re-review!
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.
Thanks for bumping! Updated the PR 👍
Co-authored-by: JJ Kasper <jj@jjsweb.site>
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.
Looks like lint fixes just need applied can run pnpm lint-fix
for this. Seems we can't as it's a PR from an organization which doesn't allow us to push.
Failing test suitesCommit: c2a77f1
Expand output● deployment-id-handling enabled with NEXT_DEPLOYMENT_ID › should contain deployment id in prefetch request
● deployment-id-handling enabled with CUSTOM_DEPLOYMENT_ID › should contain deployment id in prefetch request
Read more about building and testing Next.js in contributing.md.
Expand output● AMP Validation on Export › production mode › should have shown errors during build
Read more about building and testing Next.js in contributing.md. |
Stats from current PRDefault BuildGeneral
Client Bundles (main, webpack)
Legacy Client Bundles (polyfills)
Client Pages
Client Build Manifests
Rendered Page Sizes
Edge SSR bundle Size
Middleware size
Next Runtimes
build cache
Diff detailsDiff for middleware.jsDiff too large to display Diff for edge-ssr.jsDiff too large to display Diff for 1187-HASH.jsDiff too large to display Diff for main-HASH.jsDiff too large to display Diff for app-page-exp..ntime.dev.jsfailed to diff Diff for app-page-exp..time.prod.jsDiff too large to display Diff for app-page-tur..time.prod.jsDiff too large to display Diff for app-page-tur..time.prod.jsDiff too large to display Diff for app-page.runtime.dev.jsfailed to diff Diff for app-page.runtime.prod.jsDiff too large to display Diff for app-route-ex..ntime.dev.jsDiff too large to display Diff for app-route-ex..time.prod.jsDiff too large to display Diff for app-route-tu..time.prod.jsDiff too large to display Diff for app-route-tu..time.prod.jsDiff too large to display Diff for app-route.runtime.dev.jsDiff too large to display Diff for app-route.ru..time.prod.jsDiff too large to display Diff for pages-turbo...time.prod.jsDiff too large to display Diff for pages.runtime.dev.jsDiff too large to display Diff for pages.runtime.prod.jsDiff too large to display Diff for server.runtime.prod.jsfailed to diff |
No problem, ran prettier-lint again, and also fixed the test so that it actually forces the router to make a nextjs-data request. |
What?
x-deployment-id
is missing on prefetch requestsWhy?
To handle version skew on the pages router. When version skew is turned on,
x-deployment-id
should be used on prefetch otherwise the server will return 404. But with middleware enabled, the 404 does not appear to hard-refresh the page.How?
next.js seems to be relying on the 404 to perform a hard navigation and auto-refresh the client. But that doesn't appear to happen when middleware is in use (separate issue, not addressed in this PR), which is causing the client to navigate to 404 whenever we deploy a new version of the site to vercel.
instead of sending the client to 404, passing the
x-deployment-id
helps guarantee that next-data requests respect version skew protection.