rsnext/packages/next/build/webpack
Javi Velasco e52bee37af
Refactor sandbox module cache (#31822)
To run middleware we are using a **sandbox** that emulates the web runtime and keeps a module cache. This cache is shared for all of the modules that we run using the sandbox while there are some module-level APIs that must be scoped depending on the module we are running.

One example of this is `fetch` where we want to always inject a special header that indicate the module that is performing the fetch and use it to avoid getting into infinite loops for middleware. For those cases the cached implementation will be the first one that instantiates the module and therefore we can actually get into infinite loops. This is the reason why #31800 is failing.

With this PR we refactor the sandbox so that the module cache is scoped per module name. This means that one execution of a middleware will preserve its cache only for that module so that each execution will still have its own `fetch` implementation, fixing this issue. Also, with this refactor the code is more clear and we also provide an option to avoid using the cache.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2021-11-26 12:06:41 +00:00
..
config Lazy-load postcss (#31762) 2021-11-25 18:41:20 +01:00
loaders Lazy-load postcss (#31762) 2021-11-25 18:41:20 +01:00
plugins Refactor sandbox module cache (#31822) 2021-11-26 12:06:41 +00:00
require-hook.ts the way towards webpack 5 typings (#29105) 2021-09-21 19:17:16 +02:00
stringify-request.ts Update loader-utils (#30743) 2021-11-02 16:13:15 +01:00