未验证 提交 ec700962 编写于 作者: J Joe Haddad 提交者: GitHub

Ensure unknown static paths 404 for data request (#16401)

We were accidentally allowing data requests to be rendered unconditionally. Instead, we should also check them against the staticPaths result and 404 when appropriate.

---

Fixes #15383
上级 fc98c13a
......@@ -1156,7 +1156,6 @@ export default class Server {
fallbackMode !== 'blocking' &&
ssgCacheKey &&
!didRespond &&
!isDataReq &&
!isPreviewMode &&
isDynamicPathname &&
// Development should trigger fallback when the path is not in
......@@ -1173,27 +1172,29 @@ export default class Server {
throw new NoFallbackError()
}
let html: string
if (!isDataReq) {
let html: string
// Production already emitted the fallback as static HTML.
if (isProduction) {
html = await this.incrementalCache.getFallback(pathname)
}
// We need to generate the fallback on-demand for development.
else {
query.__nextFallback = 'true'
if (isLikeServerless) {
prepareServerlessUrl(req, query)
// Production already emitted the fallback as static HTML.
if (isProduction) {
html = await this.incrementalCache.getFallback(pathname)
}
// We need to generate the fallback on-demand for development.
else {
query.__nextFallback = 'true'
if (isLikeServerless) {
prepareServerlessUrl(req, query)
}
const { value: renderResult } = await doRender()
html = renderResult.html
}
const { value: renderResult } = await doRender()
html = renderResult.html
}
sendPayload(req, res, html, 'html', {
generateEtags: this.renderOpts.generateEtags,
poweredByHeader: this.renderOpts.poweredByHeader,
})
return null
sendPayload(req, res, html, 'html', {
generateEtags: this.renderOpts.generateEtags,
poweredByHeader: this.renderOpts.poweredByHeader,
})
return null
}
}
const {
......
......@@ -576,6 +576,32 @@ const runTests = (dev = false, isEmulatedServerless = false) => {
expect(value).toMatch(/Hi \[second\]!/)
})
if (!isEmulatedServerless) {
it('should not return data for fallback: false and missing dynamic page', async () => {
const res1 = await fetchViaHTTP(
appPort,
`/_next/data/${buildId}/dynamic/oopsie.json`
)
expect(res1.status).toBe(404)
await waitFor(500)
const res2 = await fetchViaHTTP(
appPort,
`/_next/data/${buildId}/dynamic/oopsie.json`
)
expect(res2.status).toBe(404)
await waitFor(500)
const res3 = await fetchViaHTTP(
appPort,
`/_next/data/${buildId}/dynamic/oopsie.json`
)
expect(res3.status).toBe(404)
})
}
it('should SSR catch-all page with brackets in param as string', async () => {
const html = await renderViaHTTP(
appPort,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册