Skip to content

Commit

Permalink
Remove invalid fallback revalidate value (#69990)
Browse files Browse the repository at this point in the history
This removes our invalid revalidate default fallback when a revalidate
value isn't returned from render as render should always return a valid
value. We also already have an invariant when an invalid revalidate
value is returned we just need to ensure that case could be hit
properly. This also fixes some invalid test cases which were sending
invalid headers.

x-ref: [slack
thread](https://vercel.slack.com/archives/C0676QZBWKS/p1726061828198529?thread_ts=1720714625.621179&cid=C0676QZBWKS)
  • Loading branch information
ijjk committed Sep 11, 2024
1 parent 99de057 commit 7ed7f12
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
5 changes: 1 addition & 4 deletions packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2573,10 +2573,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {

return {
...result,
revalidate:
result.revalidate !== undefined
? result.revalidate
: /* default to minimum revalidate (this should be an invariant) */ 1,
revalidate: result.revalidate,
}
},
{
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/server/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,7 @@ export async function renderToHTMLImpl(
})
)
canAccessRes = false
metadata.revalidate = 0
} catch (serverSidePropsError: any) {
// remove not found error code to prevent triggering legacy
// 404 rendering
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,16 @@ describe('required server files i18n', () => {
expect(isNaN(data2.random)).toBe(false)
expect(data2.random).not.toBe(data.random)

const html3 = await renderViaHTTP(appPort, '/some-other-path', undefined, {
headers: {
'x-matched-path': '/dynamic/[slug]?slug=%5Bslug%5D.json',
'x-now-route-matches': '1=second&nxtPslug=second',
},
})
const html3 = await renderViaHTTP(
appPort,
'/some-other-path?nxtPslug=second',
undefined,
{
headers: {
'x-matched-path': '/dynamic/[slug]?slug=%5Bslug%5D.json',
},
}
)
const $3 = cheerio.load(html3)
const data3 = JSON.parse($3('#props').text())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,12 +622,16 @@ describe('required server files', () => {
expect(isNaN(data2.random)).toBe(false)
expect(data2.random).not.toBe(data.random)

const html3 = await renderViaHTTP(appPort, '/some-other-path', undefined, {
headers: {
'x-matched-path': '/dynamic/[slug]',
'x-now-route-matches': '1=second&nxtPslug=second',
},
})
const html3 = await renderViaHTTP(
appPort,
'/some-other-path?nxtPslug=second',
undefined,
{
headers: {
'x-matched-path': '/dynamic/[slug]',
},
}
)
const $3 = cheerio.load(html3)
const data3 = JSON.parse($3('#props').text())

Expand Down

0 comments on commit 7ed7f12

Please sign in to comment.