

AsyncLocalStorage + AsyncContext API
Jun 19, 2023
The hosts dive into AsyncLocalStorage, explaining its role in maintaining consistent contexts in server-side operations. They discuss why it's not widely adopted in frameworks yet and compare it to traditional context methods. Practical applications in modern frameworks like SvelteKit and React highlight its advantages for managing authentication tokens. Additionally, they address challenges and potential pitfalls, shedding light on how this evolving API can improve state management in asynchronous JavaScript applications.
AI Snips
Chapters
Transcript
Episode notes
AsyncLocalStorage vs. LocalStorage
- AsyncLocalStorage offers a way to manage context in server-side JavaScript, similar to React Context.
- It's not related to browser LocalStorage and helps share data across function calls without manual passing.
Understanding Context
- Context is data shared across a function call stack, like user info during a web request.
- AsyncLocalStorage simplifies this by providing a central store accessible to all nested functions.
Framework Adoption of AsyncLocalStorage
- Scott asks why more frameworks aren't using AsyncLocalStorage.
- Wes explains it's relatively new and some frameworks prioritize cross-platform compatibility, lacking a standardized API like the proposed Async Context API.