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

Add frameworks use cases #117

Merged
merged 2 commits into from
Mar 24, 2025
Merged

Add frameworks use cases #117

merged 2 commits into from
Mar 24, 2025

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Mar 17, 2025

Marking as draft because we are still waiting on a quote-style explanation from React & Angular.

They are all sorted alphabetically, because I tried choosing which framework is the best to put it first and failed 😛

@nicolo-ribaudo nicolo-ribaudo force-pushed the frameworks branch 4 times, most recently from a34b492 to 19d020f Compare March 17, 2025 16:20
@slorber
Copy link

slorber commented Mar 17, 2025

Note: ALS is also widely used in Next.js for various features (cookies(), headers(), after() and more)
Not an official ref but still an interesting read: https://raphael.badia.cc/posts/next-13-cookies-and-headers-explained


Also an interesting "future of React" tweet worth asking the team about? (now deleted, unfortunately)

https://x.com/sebastienlorber/status/1639183216799100928

image

@nicolo-ribaudo
Copy link
Member Author

All those Next.js features are server-side, right? I'm trying to include frontend examples from all frameworks since it's the browsers we have to convince :)

-->

> The Svelte team are eagerly awaiting the day we can use `AsyncContext`. The widespread adoption of `AsyncLocalStorage` across different packages (and runtimes, despite its non-standard status) is clear evidence that real use cases exist; there is no a priori reason to assume that those use cases are restricted to server runtimes, and indeed there are two concrete examples where our hands are currently tied by the lack of this capability in the browser: **[server]** we're introducing a `getRequestEvent` function in SvelteKit that allows functions on the server to read information about the current request context (including things like the requested URL, cookies, headers etc), even if the function isn't called synchronously (which is necessary for it to be generally useful).
>

Choose a reason for hiding this comment

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

@Rich-Harris what's the plan to remove the .enterWith() call SvelteKit have in https://github.com/sveltejs/kit/blob/ee214121cb0ae38824c29b25ab36ef48e754705b/packages/kit/src/exports/vite/dev/index.js#L561? This kind of pattern would not be available with AsyncContext (as the spec is currently defined, Svelte would need to refactor to use a run() callback in AsyncLocalStorage lingo).

Choose a reason for hiding this comment

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

We'll cross that bridge when we come to it — assuming AsyncLocalStorage isn't immediately removed from Node if/when AsyncContext lands we have years before we need to worry about it. The codebase could look entirely different by then, so no need to spend any cycles on it now.

For clarity, this bit isn't new — the feature I mention in the comment was added in sveltejs/kit#13582 and lives in this file, and it uses .run(...)

Choose a reason for hiding this comment

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

I have no idea if AsyncLocalStorage and AsyncContext can coexist and have different semantics. From a maintenance point of view maintaining both looks hard.

@nicolo-ribaudo nicolo-ribaudo marked this pull request as ready for review March 24, 2025 11:24
@legendecas legendecas merged commit f1c041e into tc39:master Mar 24, 2025
5 checks passed
@nicolo-ribaudo nicolo-ribaudo deleted the frameworks branch March 24, 2025 16:02
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.

6 participants