-
Notifications
You must be signed in to change notification settings - Fork 27k
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: allow some recursion for middleware subrequests #60615
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 |
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 |
Stats from current PRDefault BuildGeneral Overall increase
|
vercel/next.js canary | juliusmarminge/next.js allow-subrequests | Change | |
---|---|---|---|
buildDuration | 11.9s | 11.9s | N/A |
buildDurationCached | 6s | 5.3s | N/A |
nodeModulesSize | 196 MB | 196 MB | |
nextStartRea..uration (ms) | 410ms | 409ms | N/A |
Client Bundles (main, webpack)
vercel/next.js canary | juliusmarminge/next.js allow-subrequests | Change | |
---|---|---|---|
3f784ff6-HASH.js gzip | 53.4 kB | 53.4 kB | ✓ |
423.HASH.js gzip | 185 B | 181 B | N/A |
68-HASH.js gzip | 29.7 kB | 29.7 kB | N/A |
framework-HASH.js gzip | 45.2 kB | 45.2 kB | ✓ |
main-app-HASH.js gzip | 240 B | 240 B | ✓ |
main-HASH.js gzip | 31.8 kB | 31.8 kB | N/A |
webpack-HASH.js gzip | 1.7 kB | 1.7 kB | ✓ |
Overall change | 101 kB | 101 kB | ✓ |
Legacy Client Bundles (polyfills)
vercel/next.js canary | juliusmarminge/next.js allow-subrequests | Change | |
---|---|---|---|
polyfills-HASH.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | juliusmarminge/next.js allow-subrequests | Change | |
---|---|---|---|
_app-HASH.js gzip | 194 B | 195 B | N/A |
_error-HASH.js gzip | 182 B | 181 B | N/A |
amp-HASH.js gzip | 502 B | 501 B | N/A |
css-HASH.js gzip | 320 B | 322 B | N/A |
dynamic-HASH.js gzip | 2.5 kB | 2.5 kB | N/A |
edge-ssr-HASH.js gzip | 255 B | 256 B | N/A |
head-HASH.js gzip | 350 B | 349 B | N/A |
hooks-HASH.js gzip | 368 B | 369 B | N/A |
image-HASH.js gzip | 4.19 kB | 4.18 kB | N/A |
index-HASH.js gzip | 257 B | 256 B | N/A |
link-HASH.js gzip | 2.61 kB | 2.61 kB | N/A |
routerDirect..HASH.js gzip | 310 B | 311 B | N/A |
script-HASH.js gzip | 384 B | 383 B | N/A |
withRouter-HASH.js gzip | 306 B | 308 B | N/A |
1afbb74e6ecf..834.css gzip | 106 B | 106 B | ✓ |
Overall change | 106 B | 106 B | ✓ |
Client Build Manifests
vercel/next.js canary | juliusmarminge/next.js allow-subrequests | Change | |
---|---|---|---|
_buildManifest.js gzip | 483 B | 484 B | N/A |
Overall change | 0 B | 0 B | ✓ |
Rendered Page Sizes
vercel/next.js canary | juliusmarminge/next.js allow-subrequests | Change | |
---|---|---|---|
index.html gzip | 529 B | 526 B | N/A |
link.html gzip | 540 B | 537 B | N/A |
withRouter.html gzip | 524 B | 521 B | N/A |
Overall change | 0 B | 0 B | ✓ |
Edge SSR bundle Size
vercel/next.js canary | juliusmarminge/next.js allow-subrequests | Change | |
---|---|---|---|
edge-ssr.js gzip | 94 kB | 94 kB | N/A |
page.js gzip | 149 kB | 149 kB | N/A |
Overall change | 0 B | 0 B | ✓ |
Middleware size
vercel/next.js canary | juliusmarminge/next.js allow-subrequests | Change | |
---|---|---|---|
middleware-b..fest.js gzip | 621 B | 626 B | N/A |
middleware-r..fest.js gzip | 151 B | 149 B | N/A |
middleware.js gzip | 47.4 kB | 47.4 kB | N/A |
edge-runtime..pack.js gzip | 1.94 kB | 1.94 kB | ✓ |
Overall change | 1.94 kB | 1.94 kB | ✓ |
Next Runtimes
vercel/next.js canary | juliusmarminge/next.js allow-subrequests | Change | |
---|---|---|---|
app-page-exp...dev.js gzip | 166 kB | 166 kB | ✓ |
app-page-exp..prod.js gzip | 95.1 kB | 95.1 kB | ✓ |
app-page-tur..prod.js gzip | 96.9 kB | 96.9 kB | ✓ |
app-page-tur..prod.js gzip | 91.4 kB | 91.4 kB | ✓ |
app-page.run...dev.js gzip | 135 kB | 135 kB | ✓ |
app-page.run..prod.js gzip | 90 kB | 90 kB | ✓ |
app-route-ex...dev.js gzip | 22 kB | 22 kB | ✓ |
app-route-ex..prod.js gzip | 14.8 kB | 14.8 kB | ✓ |
app-route-tu..prod.js gzip | 14.8 kB | 14.8 kB | ✓ |
app-route-tu..prod.js gzip | 14.6 kB | 14.6 kB | ✓ |
app-route.ru...dev.js gzip | 21.7 kB | 21.7 kB | ✓ |
app-route.ru..prod.js gzip | 14.6 kB | 14.6 kB | ✓ |
pages-api-tu..prod.js gzip | 9.43 kB | 9.43 kB | ✓ |
pages-api.ru...dev.js gzip | 9.7 kB | 9.7 kB | ✓ |
pages-api.ru..prod.js gzip | 9.43 kB | 9.43 kB | ✓ |
pages-turbo...prod.js gzip | 22 kB | 22 kB | ✓ |
pages.runtim...dev.js gzip | 22.7 kB | 22.7 kB | ✓ |
pages.runtim..prod.js gzip | 22 kB | 22 kB | ✓ |
server.runti..prod.js gzip | 49.7 kB | 49.7 kB | ✓ |
Overall change | 922 kB | 922 kB | ✓ |
let result: FetchEventResult | undefined = undefined | ||
await requestStore.run({ headers }, async () => { | ||
result = await edgeFunction({ | ||
request: { | ||
...params.request, | ||
body: | ||
cloned && requestToBodyStream(runtime.context, KUint8Array, cloned), | ||
}, | ||
}) | ||
for (const headerName of FORBIDDEN_HEADERS) { | ||
result.response.headers.delete(headerName) | ||
} | ||
}) | ||
for (const headerName of FORBIDDEN_HEADERS) { | ||
result.response.headers.delete(headerName) | ||
} | ||
if (!result) throw new Error('Edge function did not return a response') |
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.
this looks very sketchy - idk how far up the store.run
call can be hoisted though or if there a better way to do this...
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.
Hoisting to this level seems alright as it looks like we only need to access it in the same Node.js context.
const store = requestStore.getStore() | ||
if (store) { | ||
new Headers(init?.headers).forEach((value, key) => { | ||
store.headers.set(key, value) | ||
}) | ||
} |
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.
Why are we needing to augment the store from headers in a new Request()
, shouldn't this only be done from the initial request event in the sandbox?
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.
that does sound correct - should be able to remove this here then
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.
confirmed it was unnecessary, removed it 👍🏼
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.
Changes and added test look good, thanks for the PR!
This alters the behavior of the subrequest check to allow for 5 recursive calls to match Vercel production, ref Slack thread.
Note
Currently limited by fetches having to forward the subrequest header for each request which isn't ideal. Need some assistant on how to access the request in the module context fetch override.
No forwarding:
With forwarding: