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

Replace server context with AsyncLocalStorage and client context #20

Merged
merged 1 commit into from
Oct 31, 2023

Conversation

unstubbable
Copy link
Owner

Because server context has been deprecated, we needed to find a replacement for sharing the current location.

Using conditional exports, we can create a universal useRouterLocation hook that utilizes AsyncLocalStorage on the server, and normal client context in the browser. Even though the client context would also be accessible in the SSR client (we could render the context provider in ServerRoot), we are instead using AsyncLocalStorage here as well, primarily for its convenience. Although this does require placing the module containing the AsyncLocalStorage instance into a shared webpack layer.

@vercel
Copy link

vercel bot commented Oct 31, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
mfng ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 31, 2023 8:22am

Because [server context has been
deprecated](facebook/react#27424), we needed to
find a replacement for sharing the current location.

Using conditional exports, we can create a universal `useRouterLocation`
hook that utilizes `AsyncLocalStorage` on the server, and normal client
context in the browser. Even though the client context would also be
accessible in the SSR client (we could render the context provider in
`ServerRoot`), we are instead using `AsyncLocalStorage` here as well,
primarily for its convenience. Although this does require placing the
module containing the `AsyncLocalStorage` instance into a shared webpack
layer.
@unstubbable unstubbable merged commit d954c08 into main Oct 31, 2023
3 checks passed
@unstubbable unstubbable deleted the replace-server-context branch October 31, 2023 08:25
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.

None yet

1 participant