a9b9e00703
Makes it possible to switch between edge/server runtime in dev without breaking the server. Fixes slack: [1](https://vercel.slack.com/archives/CGU8HUTUH/p1659082535540549) [2](https://vercel.slack.com/archives/C02CDC2ALJH/p1658978287244359) [3](https://vercel.slack.com/archives/C03KAR5DCKC/p1656869427468779) #### middleware-plugin.ts `middlewareManifest` moved from module scope to local scope. Stale state from earlier builds ended up in `middleware-manifest.json`. Functions that changed from edge to server runtime stayed in the manifest as edge functions. #### on-demand-entry-handler.ts When a server or edge entry is added we check if it has switched runtime. If that's the case the old entry is removed. #### Reproduce Create edge API route and visit `/api/hello` ```js // pages/api/hello.js export const config = { runtime: 'experimental-edge', } export default () => new Response('Hello') ``` Change it to a server api route and visit `/api/hello`, it will explode. ```js // pages/api/hello.js export default function (req, res) { res.send('Hello') } ``` #### Bug not fixed One EDGE case is not fixed. It occurs if you switch between edge and server runtime several times without changing the content of the file: Edge runtime ```js export const config = { runtime: 'experimental-edge', } export default () => new Response('Hello') ``` Change it to a server runtime ```js export default function (req, res) { res.send('Hello') } ``` Change back to edge runtime, the content of the file is the same as the first time we compiled the edge runtime version. ```js export const config = { runtime: 'experimental-edge', } export default () => new Response('Hello') ``` The reason is that both the edge and server compiler emits to the same file (/.next/server/pages/api/hello.js) which makes this check fail in webpack: https://github.com/webpack/webpack/blob/main/lib/Compiler.js#L849-L861 Possible solution is to use different output folders for edge and server https://vercel.slack.com/archives/CGU8HUTUH/p1661163106667559 Co-authored-by: JJ Kasper <jj@jjsweb.site> |
||
---|---|---|
.. | ||
app-dir | ||
basepath | ||
browserslist | ||
browserslist-extends | ||
config-promise-export | ||
dynamic-route-interpolation | ||
edge-api-endpoints-can-receive-body | ||
edge-can-use-wasm-files | ||
edge-compiler-can-import-blob-assets | ||
edge-compiler-module-exports-preference | ||
edge-render-getserversideprops | ||
getserversideprops | ||
handle-non-hoisted-swc-helpers | ||
i18n-api-support | ||
i18n-data-fetching-redirect | ||
i18n-ignore-redirect-source-locale | ||
i18n-ignore-rewrite-source-locale | ||
ignore-invalid-popstateevent | ||
link-with-api-rewrite | ||
manual-client-base-path | ||
middleware-base-path | ||
middleware-custom-matchers | ||
middleware-custom-matchers-basepath | ||
middleware-custom-matchers-i18n | ||
middleware-fetches-with-any-http-method | ||
middleware-general | ||
middleware-matcher | ||
middleware-redirects | ||
middleware-responses | ||
middleware-rewrites | ||
middleware-trailing-slash | ||
new-link-behavior | ||
next-head | ||
next-script | ||
no-eslint-warn-with-no-eslint-config | ||
nonce-head-manager | ||
postcss-config-cjs | ||
prerender | ||
prerender-native-module | ||
proxy-request-with-middleware | ||
reload-scroll-backforward-restoration | ||
ssr-react-context | ||
streaming-ssr | ||
styled-jsx | ||
swc-warnings | ||
switchable-runtime | ||
type-module-interop | ||
yarn-pnp/test | ||
basepath-trailing-slash.test.ts | ||
basepath.test.ts | ||
example.txt | ||
prerender-crawler.test.ts | ||
prerender-native-module.test.ts | ||
prerender.test.ts |