next.js
174fc2fe - [after] remove createCacheScope (#68744)

Commit
1 year ago
[after] remove createCacheScope (#68744) This PR removes `createCacheScope` and the associated React monkeypatching 🥳 As discussed, the patch isn't really necessary, and extending the lifetime of `cache()` works by just staying in the same async context (i.e. chaining promises so that AsyncLocalStorage is preserved). I added a note in `after-context` to highlight the place where this happens. Note that, for now, we're still shadowing requestAsyncStorage when running the callbacks (but this may change in the future). What we DIDN'T know is that it **already sometimes worked this way** -- the react patch was partially broken in some scenarios (HMR in dev mode) causing cache scopeto do nothing, but we were already staying in the same async context, and that's how `cache()` still worked. Removing `createCacheScope` also removes the (currently undesireable, because it's inconsistent) side-effect of making `cache()` work in actions. Follow up work will be needed to make sure things like `cookies.set()` are always blocked in `after` (mostly for the `const c = cookies(); after(() => c.set(...))` case) Note that this obsoletes https://github.com/vercel/next.js/pull/68547, which was attempting to fix the brokenness of the react patch in HMR.
Author
Parents
Loading