-
Notifications
You must be signed in to change notification settings - Fork 131
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 Next.js calling a non-bound waitUntil method #917
Conversation
🦋 Changeset detectedLatest commit: a2d4de8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🧪 Prereleases are available for testing 🧪 @cloudflare/next-on-pagesYou can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/next-on-pages/runs/12225063689/npm-package-next-on-pages-917 @cloudflare/eslint-plugin-next-on-pagesYou can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/next-on-pages/runs/12225063689/npm-package-eslint-plugin-next-on-pages-917 |
/this\[(.)\]=(\w)\?{kind:"external",function:\2}:{kind:"internal",promises:\[(.*?)\]}/gm, | ||
`this[$1]=e?{kind:"external",function:globalThis[Symbol.for('__cloudflare-request-context__')].ctx.waitUntil.bind(globalThis[Symbol.for('__cloudflare-request-context__')].ctx)}:{kind:"internal",promises:[$3]}`, |
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.
Where does e
come from? Should this value be from the capture group?
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 wow! thanks a lot for spotting this! yeah it should be $2
!
I changed this regex a couple of times so I must have messed that up here! 😓 good eye! 🫶
// We need to update it so that uses a `waitUntil` bound to our `ctx` object | ||
// (source https://github.com/vercel/next.js/blob/b7c271d7/packages/next/src/server/web/spec-extension/fetch-event.ts#L21) | ||
contents = contents.replace( | ||
/this\[(.)\]=(\w)\?{kind:"external",function:\2}:{kind:"internal",promises:\[(.*?)\]}/gm, |
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 end the regex we're replacing at the end of the promises string instead of trying to capture everything in that array as well maybe? just to be a bit less brittle
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.
yes... it could be either way, arguably capturing the array and closing bracket gives us more confidence that we're matching the right thing?
Anyways it's a good callout 👍 I don't mind either version so if you prefer not to match promises:
that's fine by me 🙂
resolves #912