Skip to content

Commit

Permalink
fix: handle cases of chunked middleware (#2574)
Browse files Browse the repository at this point in the history
* test: make middleware fixture produce chunked middleware

* fix: handle cases of chunked middleware
  • Loading branch information
pieh authored Aug 26, 2024
1 parent b352918 commit 666fe5a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/build/functions/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const copyHandlerDependencies = async (
const entrypoint = await readFile(join(srcDir, file), 'utf8')
parts.push(`;// Concatenated file: ${file} \n`, entrypoint)
}
const exports = `export default _ENTRIES["middleware_${name}"].default;`
const exports = `const middlewareEntryKey = Object.keys(_ENTRIES).find(entryKey => entryKey.startsWith("middleware_${name}")); export default _ENTRIES[middlewareEntryKey].default;`
await mkdir(dirname(join(destDir, `server/${name}.js`)), { recursive: true })

await writeFile(join(destDir, `server/${name}.js`), [...parts, exports].join('\n'))
Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures/middleware/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ const nextConfig = {
eslint: {
ignoreDuringBuilds: true,
},
webpack: (config) => {
// this is a trigger to generate multiple `.next/server/middleware-[hash].js` files instead of
// single `.next/server/middleware.js` file
config.optimization.splitChunks.maxSize = 100_000

return config
},
}

module.exports = nextConfig

0 comments on commit 666fe5a

Please sign in to comment.