rsnext/packages/next/build/webpack/plugins
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
..
terser-webpack-plugin Add minify debug env var to investigate minifier bugs (#31417) 2021-11-15 14:15:18 +01:00
wellknown-errors-plugin Add new target for middleware (#30299) 2021-10-26 18:50:56 +02:00
build-manifest-plugin.ts Improve and refactor some types (#31704) 2021-11-25 10:46:00 +01:00
copy-file-plugin.ts use loader-utils 2 for resolve-url-loader to fix ./data: urls in sass (#31134) 2021-11-08 18:37:25 +00:00
css-minimizer-plugin.ts partially migrate to webpack 5 types (#30189) 2021-10-24 23:04:26 +02:00
flight-manifest-plugin.ts Fix code splitting and build target for the server-web build (#30972) 2021-11-05 03:27:02 +00:00
font-stylesheet-gathering-plugin.ts Remove isWebpack5 checks (#29677) 2021-10-06 18:46:46 -05:00
jsconfig-paths-plugin.ts feat(jsconfig-paths-plugin): Resolve paths synchronously (#29467) 2021-10-13 12:17:54 +02:00
middleware-plugin.ts Improve and refactor some types (#31704) 2021-11-25 10:46:00 +01:00
mini-css-extract-plugin.ts use official mini-css-extract-plugin and experimentalUseImportModule (#24573) 2021-05-12 16:04:01 +00:00
next-drop-client-page-plugin.ts Remove isWebpack5 checks (#29677) 2021-10-06 18:46:46 -05:00
next-trace-entrypoints-plugin.ts Update resolving for node_modules trace pass (#30985) 2021-11-04 20:09:37 -05:00
nextjs-require-cache-hot-reloader.ts Refactor sandbox module cache (#31822) 2021-11-26 12:06:41 +00:00
nextjs-ssr-import.ts feat: webpack inlining with configuration for v4 / v5 (#20598) 2021-01-13 20:59:08 -05:00
pages-manifest-plugin.ts Remove isWebpack5 checks (#29677) 2021-10-06 18:46:46 -05:00
profiling-plugin.ts partially migrate to webpack 5 types (#30189) 2021-10-24 23:04:26 +02:00
react-loadable-plugin.ts Add new target for middleware (#30299) 2021-10-26 18:50:56 +02:00
serverless-plugin.ts update serverless plugin to use webpack 5 apis (#31058) 2021-11-06 01:19:25 +01:00
telemetry-plugin.ts Track usage of swc features (#30297) 2021-10-26 09:37:38 +02:00