Unverified Commit 58033c4a authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix resolving dynamic routes when on returns a redirect (#38079)

* Fix resolving dynamic routes when on returns a redirect

* Update fix and add test case
parent ca621ced
...@@ -1815,7 +1815,7 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -1815,7 +1815,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
} }
} }
} }
return null return false
} }
private async renderToResponse( private async renderToResponse(
...@@ -1831,7 +1831,7 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -1831,7 +1831,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
// route correctly and not loaded immediately without parsing params. // route correctly and not loaded immediately without parsing params.
if (!isDynamicRoute(page)) { if (!isDynamicRoute(page)) {
const result = await this.renderPageComponent(ctx, bubbleNoFallback) const result = await this.renderPageComponent(ctx, bubbleNoFallback)
if (result) return result if (result !== false) return result
} }
if (this.dynamicRoutes) { if (this.dynamicRoutes) {
...@@ -1852,7 +1852,7 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -1852,7 +1852,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
}, },
bubbleNoFallback bubbleNoFallback
) )
if (result) return result if (result !== false) return result
} }
} }
} catch (error) { } catch (error) {
......
...@@ -138,6 +138,33 @@ describe('should set-up next', () => { ...@@ -138,6 +138,33 @@ describe('should set-up next', () => {
if (server) await killApp(server) if (server) await killApp(server)
}) })
it('should resolve correctly when a redirect is returned', async () => {
const toRename = `standalone/.next/server/pages/route-resolving/[slug]/[project].html`
await next.renameFile(toRename, `${toRename}.bak`)
try {
const res = await fetchViaHTTP(
appPort,
'/route-resolving/import/first',
undefined,
{
redirect: 'manual',
headers: {
'x-matched-path': '/route-resolving/import/[slug]',
},
}
)
expect(res.status).toBe(307)
expect(new URL(res.headers.get('location'), 'http://n').pathname).toBe(
'/somewhere'
)
await waitFor(3000)
expect(stderr).not.toContain('ENOENT')
} finally {
await next.renameFile(`${toRename}.bak`, toRename)
}
})
it('should show invariant when an automatic static page is requested', async () => { it('should show invariant when an automatic static page is requested', async () => {
const toRename = `standalone/.next/server/pages/auto-static.html` const toRename = `standalone/.next/server/pages/auto-static.html`
await next.renameFile(toRename, `${toRename}.bak`) await next.renameFile(toRename, `${toRename}.bak`)
......
export default function Page(props) {
return <p>/[slug]/[project]</p>
}
export default function Page(props) {
return <p>/import/[slug]</p>
}
export function getStaticProps() {
return {
redirect: {
destination: '/somewhere',
permanent: false,
},
}
}
export function getStaticPaths() {
return {
paths: [],
fallback: true,
}
}
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