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 { ...@@ -282,12 +282,11 @@ export default class DevServer extends Server {
wp.watch(files, directories, 0) wp.watch(files, directories, 0)
wp.on('aggregated', async () => { wp.on('aggregated', async () => {
const routedMiddleware: string[] = []
let middlewareMatcher: RegExp | undefined let middlewareMatcher: RegExp | undefined
const routedPages: string[] = [] const routedPages: string[] = []
const knownFiles = wp.getTimeInfoEntries() const knownFiles = wp.getTimeInfoEntries()
const appPaths: Record<string, string> = {} const appPaths: Record<string, string> = {}
const ssrMiddleware = new Set<string>() const edgeRoutesSet = new Set<string>()
for (const [fileName, meta] of knownFiles) { for (const [fileName, meta] of knownFiles) {
if ( if (
...@@ -319,7 +318,7 @@ export default class DevServer extends Server { ...@@ -319,7 +318,7 @@ export default class DevServer extends Server {
this.actualMiddlewareFile = rootFile this.actualMiddlewareFile = rootFile
middlewareMatcher = middlewareMatcher =
staticInfo.middleware?.pathMatcher || new RegExp('.*') staticInfo.middleware?.pathMatcher || new RegExp('.*')
routedMiddleware.push('/') edgeRoutesSet.add('/')
continue continue
} }
...@@ -357,10 +356,7 @@ export default class DevServer extends Server { ...@@ -357,10 +356,7 @@ export default class DevServer extends Server {
onClient: () => {}, onClient: () => {},
onServer: () => {}, onServer: () => {},
onEdgeServer: () => { onEdgeServer: () => {
if (!pageName.startsWith('/api/')) { edgeRoutesSet.add(pageName)
routedMiddleware.push(pageName)
}
ssrMiddleware.add(pageName)
}, },
}) })
routedPages.push(pageName) routedPages.push(pageName)
...@@ -376,13 +372,12 @@ export default class DevServer extends Server { ...@@ -376,13 +372,12 @@ export default class DevServer extends Server {
this.appPathRoutes = appPaths this.appPathRoutes = appPaths
this.edgeFunctions = [] this.edgeFunctions = []
getSortedRoutes(routedMiddleware).forEach((page) => { const edgeRoutes = Array.from(edgeRoutesSet)
getSortedRoutes(edgeRoutes).forEach((page) => {
const isRootMiddleware = page === '/' && !!middlewareMatcher const isRootMiddleware = page === '/' && !!middlewareMatcher
const middlewareRegex = isRootMiddleware const middlewareRegex = isRootMiddleware
? { re: middlewareMatcher!, groups: {} } ? { re: middlewareMatcher!, groups: {} }
: getMiddlewareRegex(page, { : getMiddlewareRegex(page, { catchAll: false })
catchAll: !ssrMiddleware.has(page),
})
const routeItem = { const routeItem = {
match: getRouteMatcher(middlewareRegex), match: getRouteMatcher(middlewareRegex),
page, page,
......
...@@ -61,6 +61,23 @@ describe('Switchable runtime', () => { ...@@ -61,6 +61,23 @@ describe('Switchable runtime', () => {
if ((global as any).isNextDev) { if ((global as any).isNextDev) {
describe('Switchable runtime (dev)', () => { 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 () => { it.skip('should support client side navigation to ssr rsc pages', async () => {
let flightRequest = null 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