Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resolving dynamic routes when on returns a redirect #38079

Merged
merged 2 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/next/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1815,7 +1815,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
}
}
}
return null
return false
}

private async renderToResponse(
Expand All @@ -1831,7 +1831,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
// route correctly and not loaded immediately without parsing params.
if (!isDynamicRoute(page)) {
const result = await this.renderPageComponent(ctx, bubbleNoFallback)
if (result) return result
if (result !== false) return result
}

if (this.dynamicRoutes) {
Expand All @@ -1852,7 +1852,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
},
bubbleNoFallback
)
if (result) return result
if (result !== false) return result
}
}
} catch (error) {
Expand Down
27 changes: 27 additions & 0 deletions test/production/required-server-files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,33 @@ describe('should set-up next', () => {
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 () => {
const toRename = `standalone/.next/server/pages/auto-static.html`
await next.renameFile(toRename, `${toRename}.bak`)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page(props) {
return <p>/[slug]/[project]</p>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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,
}
}