Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Ensure unknown static paths 404 for data request #16401

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

Merged
merged 3 commits into from
Aug 20, 2020
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
39 changes: 20 additions & 19 deletions packages/next/next-server/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
26 changes: 26 additions & 0 deletions test/integration/prerender/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down