superflare icon indicating copy to clipboard operation
superflare copied to clipboard

Use AsyncLocalStorage

Open jplhomer opened this issue 1 year ago • 1 comments

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 and Request and Auth
  • 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.

jplhomer avatar Mar 23 '23 09:03 jplhomer