Unverified Commit cbb9c2ca authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Add error message when rewriting to dynamic SSG page (#10458)

* Add error message when rewriting to dynamic SSG page

* Update comment
Co-authored-by: 's avatarJoe Haddad <timer150@gmail.com>
parent f6e7a381
......@@ -297,6 +297,7 @@ export async function renderToHTML(
const bodyTags = (...args: any) => callMiddleware('bodyTags', args)
const htmlProps = (...args: any) => callMiddleware('htmlProps', args, true)
const didRewrite = (req as any)._nextDidRewrite
const isFallback = !!query.__nextFallback
delete query.__nextFallback
......@@ -314,15 +315,21 @@ export async function renderToHTML(
if (
process.env.NODE_ENV !== 'production' &&
isAutoExport &&
(isAutoExport || isFallback) &&
isDynamicRoute(pathname) &&
(req as any)._nextDidRewrite
didRewrite
) {
// TODO: add err.sh when rewrites go stable
// Behavior might change before then (prefer SSR in this case)
// Behavior might change before then (prefer SSR in this case).
// If we decide to ship rewrites to the client we could solve this
// by running over the rewrites and getting the params.
throw new Error(
`Rewrites don't support auto-exported dynamic pages yet. ` +
`Using this will cause the page to fail to parse the params on the client`
`Rewrites don't support${
isFallback ? ' ' : ' auto-exported '
}dynamic pages${isFallback ? ' with getStaticProps ' : ' '}yet. ` +
`Using this will cause the page to fail to parse the params on the client${
isFallback ? ' for the fallback page ' : ''
}`
)
}
......
......@@ -378,6 +378,14 @@ const runTests = (dev = false) => {
})
if (dev) {
it('should show error when rewriting to dynamic SSG page', async () => {
const item = Math.round(Math.random() * 100)
const html = await renderViaHTTP(appPort, `/some-rewrite/${item}`)
expect(html).toContain(
`Rewrites don't support dynamic pages with getStaticProps yet. Using this will cause the page to fail to parse the params on the client for the fallback page`
)
})
it('should always call getStaticProps without caching in dev', async () => {
const initialRes = await fetchViaHTTP(appPort, '/something')
expect(initialRes.headers.get('cache-control')).toBeFalsy()
......@@ -595,8 +603,27 @@ const runTests = (dev = false) => {
}
describe('SPR Prerender', () => {
afterAll(() => fs.remove(nextConfig))
describe('dev mode', () => {
beforeAll(async () => {
await fs.writeFile(
nextConfig,
`
module.exports = {
experimental: {
rewrites() {
return [
{
source: "/some-rewrite/:item",
destination: "/blog/post-:item"
}
]
}
}
}
`
)
appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStderr: msg => {
......
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