Skip to content

Commit 1ffa21c

Browse files
committed
fix: ensure newly-created midldeware works
1 parent 721cc78 commit 1ffa21c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/runtime/src/templates/edge/next-dev.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const exists = async (relativePath) => {
1919
throw error
2020
}
2121
}
22+
let idx = 0
2223

2324
const handler = async (req, context) => {
2425
// Uncomment when CLI update lands
@@ -34,8 +35,9 @@ const handler = async (req, context) => {
3435
// because that would also throw if there's an error in the middleware,
3536
// which we would want to surface not ignore.
3637
if (await exists('../../middleware.js')) {
37-
// These will be user code
38-
const nextMiddleware = await import('../../middleware.js')
38+
// We need to cache-bust the import because otherwise it will claim it
39+
// doesn't exist if the user creates it after the server starts
40+
const nextMiddleware = await import(`../../middleware.js#${idx++}`)
3941
middleware = nextMiddleware.middleware
4042
} else {
4143
// No middleware, so we silently return

0 commit comments

Comments
 (0)