Unverified Commit e42c88d8 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Fix missing edge routes in dev middleware manifest (#39199)

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
parent 97ab23fb
......@@ -282,12 +282,11 @@ export default class DevServer extends Server {
wp.watch(files, directories, 0)
wp.on('aggregated', async () => {
const routedMiddleware: string[] = []
let middlewareMatcher: RegExp | undefined
const routedPages: string[] = []
const knownFiles = wp.getTimeInfoEntries()
const appPaths: Record<string, string> = {}
const ssrMiddleware = new Set<string>()
const edgeRoutesSet = new Set<string>()
for (const [fileName, meta] of knownFiles) {
if (
......@@ -319,7 +318,7 @@ export default class DevServer extends Server {
this.actualMiddlewareFile = rootFile
middlewareMatcher =
staticInfo.middleware?.pathMatcher || new RegExp('.*')
routedMiddleware.push('/')
edgeRoutesSet.add('/')
continue
}
......@@ -357,10 +356,7 @@ export default class DevServer extends Server {
onClient: () => {},
onServer: () => {},
onEdgeServer: () => {
if (!pageName.startsWith('/api/')) {
routedMiddleware.push(pageName)
}
ssrMiddleware.add(pageName)
edgeRoutesSet.add(pageName)
},
})
routedPages.push(pageName)
......@@ -376,13 +372,12 @@ export default class DevServer extends Server {
this.appPathRoutes = appPaths
this.edgeFunctions = []
getSortedRoutes(routedMiddleware).forEach((page) => {
const edgeRoutes = Array.from(edgeRoutesSet)
getSortedRoutes(edgeRoutes).forEach((page) => {
const isRootMiddleware = page === '/' && !!middlewareMatcher
const middlewareRegex = isRootMiddleware
? { re: middlewareMatcher!, groups: {} }
: getMiddlewareRegex(page, {
catchAll: !ssrMiddleware.has(page),
})
: getMiddlewareRegex(page, { catchAll: false })
const routeItem = {
match: getRouteMatcher(middlewareRegex),
page,
......
......@@ -61,6 +61,23 @@ describe('Switchable runtime', () => {
if ((global as any).isNextDev) {
describe('Switchable runtime (dev)', () => {
it('should include edge api routes and edge ssr routes into dev middleware manifest', async () => {
const res = await fetchViaHTTP(
next.url,
`/_next/static/${next.buildId}/_devMiddlewareManifest.json`
)
const routesMatchers = await res.json()
expect(
routesMatchers.some((matcher) =>
matcher[0].startsWith('^\\/api\\/edge')
)
).toBe(true)
expect(
routesMatchers.some((matcher) => matcher[0].startsWith('^\\/edge'))
).toBe(true)
})
it.skip('should support client side navigation to ssr rsc pages', async () => {
let flightRequest = null
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment