Skip to content

Make waitUntil consistent for Node.js & Edge#11553

Merged
Kikobeats merged 15 commits into
mainfrom
waituntil
May 7, 2024
Merged

Make waitUntil consistent for Node.js & Edge#11553
Kikobeats merged 15 commits into
mainfrom
waituntil

Conversation

@Kikobeats

@Kikobeats Kikobeats commented May 7, 2024

Copy link
Copy Markdown
Contributor

This PR makes waitUntil consistent when interacting with it via vc dev. That includes:

be possible to call waitUntil from the context second argument in web handlers functions (Node.js & Edge):

export function GET(request, { waitUntil }) {
  waitUntil(fetch('https://vercel.com'));
  return new Response('OK');
}

be possible to call waitUntil imported from @vercel/functions (Node.js & Edge):

import { waitUntil } from '@vercel/functions';

export function GET(request) {
  waitUntil(fetch('https://vercel.com'));
  return new Response('OK');
}

Additionally, @vercel/functions can be adopted for other framework to take advantage of this pattern at Vercel.

@changeset-bot

changeset-bot Bot commented May 7, 2024

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ddcf99e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@vercel/functions Major
@vercel/node Minor
vercel Patch

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

Comment thread packages/functions/package.json Outdated
});
}

(NODE_MAJOR < 18 ? describe.skip : describe)('web handlers', () => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TooTallNate right now CI is only running for Node.js v16, so ALL this test file is skipped; How we can setup a Github Action job just for ensure to run this file using Node.js v18?

Comment thread .changeset/wild-ladybugs-leave.md Outdated
TooTallNate
TooTallNate previously approved these changes May 7, 2024
Comment thread packages/functions/index.d.ts
Comment thread packages/functions/package.json
Comment on lines +187 to +192
// @ts-expect-error
runtime.context.globalThis[Symbol.for('@vercel/request-context')] = {
get: () => ({
waitUntil: params.awaiter.waitUntil.bind(params.awaiter),
}),
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if we have two requests concurrently? do we need AsyncLocalStorage?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use Object.defineProperty here too?

Comment thread packages/functions/index.test.js Outdated
Comment thread packages/functions/index.js
Comment thread packages/functions/index.js Outdated
Comment thread packages/node/src/awaiter.ts
@Kikobeats Kikobeats merged commit a5ea041 into main May 7, 2024
@Kikobeats Kikobeats deleted the waituntil branch May 7, 2024 13:36
Kikobeats pushed a commit that referenced this pull request May 7, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @vercel/functions@1.0.0

### Major Changes

- Initial release
([#11553](#11553))

## @vercel/node@3.1.0

### Minor Changes

- Make waitUntil consistent for Node.js & Edge
([#11553](#11553))

## vercel@34.1.9

### Patch Changes

- Updated dependencies
\[[`5a532a5b9`](5a532a5),
[`50fc27ba5`](50fc27b),
[`c1d852295`](c1d8522),
[`a5ea04154`](a5ea041)]:
    -   @vercel/next@4.2.8
    -   @vercel/node@3.1.0

## @vercel/next@4.2.8

### Patch Changes

- Fix missing initial RSC headers
([#11552](#11552))

- Remove .prefetch.rsc rewrites for non-PPR
([#11540](#11540))

- [next] rename middleware manifest env
([#11549](#11549))

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants