superflare
superflare copied to clipboard
Use AsyncLocalStorage
Now that Cloudflare supports ALS using the nodejs_compat
compatibility flag, this allows us to attach Superflare config to a request-local context. This is way better than assigning a bunch of variables to a global singleton because:
- It no longer bleeds between requests
- We can assign per-request information like
Session
andRequest
andAuth
- We no longer require the use of Remix loader context (which obvs isn't available in other frameworks anyway)
This means we can start providing helpers like session()
and auth()
, and use them from within Superflare internals as well 🎉
We've been waiting on a patch to Remix which just landed in dev
https://github.com/remix-run/remix/pull/5773
TODO:
- [x] Fix tests to be able to run with ALS. This is a thing which is difficult apparently across other Node.js projects and testing frameworks.