Skip to content
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

check for an implementation of AsyncLocalStorage #866

Merged
merged 6 commits into from
May 2, 2022

Conversation

caass
Copy link
Contributor

@caass caass commented Apr 29, 2022

Certain runtime APIs are only available to workers during the "request context", which is any code that returns after receiving a request and before returning a response.

Miniflare emulates this behavior by using an AsyncLocalStorage and checking at runtime to see if you're using those APIs during the request context.

In certain environments AsyncLocalStorage is unavailable, such as in a webcontainer. This function figures out if we're able to run those "request context" checks and returns a set of options that indicate to miniflare whether to run the checks or not.

Closes #863

@changeset-bot
Copy link

changeset-bot bot commented Apr 29, 2022

🦋 Changeset detected

Latest commit: 22d59ef

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

This PR includes changesets to release 1 package
Name Type
wrangler 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

@github-actions
Copy link
Contributor

github-actions bot commented Apr 29, 2022

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/runs/2247677395/npm-package-wrangler-866

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/866/npm-package-wrangler-866

Or you can use npx with this latest build directly:

npx https://prerelease-registry.developers.workers.dev/runs/2247677395/npm-package-wrangler-866 dev path/to/script.js

@caass caass marked this pull request as ready for review April 29, 2022 20:35
@caass
Copy link
Contributor Author

caass commented Apr 29, 2022

I didn't write any tests for this since the functionality is behind wrangler dev, which we don't have -- I did however ask @eidam if to try out a version with this fix implemented and it seems to work for his projects.

@eidam
Copy link
Contributor

eidam commented Apr 29, 2022

Workers project
https://stackblitz.com/edit/node-gpc6rx?file=package.json

Pages project
https://stackblitz.com/edit/github-w5ovsh?file=package.json

@caass
Copy link
Contributor Author

caass commented May 2, 2022

For clarity: the @caass/wrangler package is just a version of this PR i published to NPM since stackblitz doesn't like git or URL deps

Copy link
Contributor

@JacobMGEvans JacobMGEvans left a comment

Choose a reason for hiding this comment

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

This looks great to me!! Another big step in Wrangler support in atypical environments.
🥳🥳🥳

@caass caass merged commit 8b227fc into main May 2, 2022
@caass caass deleted the request-context-options branch May 2, 2022 14:31
@github-actions github-actions bot mentioned this pull request May 2, 2022
@d3lm
Copy link
Contributor

d3lm commented May 2, 2022

Thanks for this PR 🙏 🙏 🙏

@caass We are working on git or url dependencies so hopefully that will work soonish.

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.

Miniflare (local mode) doesn't work in StackBlitz (and possibly other platforms)
5 participants