Fix SPR always revalidating in production (#9091)
* Add failing tests for SPR * Fix SPR always revalidating in production * Remove extra changes
This commit is contained in:
parent
07502ba2dd
commit
d3cbb163be
2 changed files with 22 additions and 3 deletions
|
@ -35,7 +35,7 @@ export const calculateRevalidate = (pathname: string): number | false => {
|
||||||
// in development we don't have a prerender-manifest
|
// in development we don't have a prerender-manifest
|
||||||
// and default to always revalidating to allow easier debugging
|
// and default to always revalidating to allow easier debugging
|
||||||
const curTime = new Date().getTime()
|
const curTime = new Date().getTime()
|
||||||
if (!sprOptions.dev) return curTime
|
if (sprOptions.dev) return curTime
|
||||||
|
|
||||||
const { initialRevalidateSeconds } = prerenderManifest.routes[pathname] || {
|
const { initialRevalidateSeconds } = prerenderManifest.routes[pathname] || {
|
||||||
initialRevalidateSeconds: 1,
|
initialRevalidateSeconds: 1,
|
||||||
|
|
|
@ -259,17 +259,33 @@ const runTests = (dev = false) => {
|
||||||
expect(new Set(vals).size).toBe(1)
|
expect(new Set(vals).size).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should not revalidate when set to false', async () => {
|
||||||
|
const route = '/something'
|
||||||
|
const initialHtml = await renderViaHTTP(appPort, route)
|
||||||
|
let newHtml = await renderViaHTTP(appPort, route)
|
||||||
|
expect(initialHtml).toBe(newHtml)
|
||||||
|
|
||||||
|
newHtml = await renderViaHTTP(appPort, route)
|
||||||
|
expect(initialHtml).toBe(newHtml)
|
||||||
|
|
||||||
|
newHtml = await renderViaHTTP(appPort, route)
|
||||||
|
expect(initialHtml).toBe(newHtml)
|
||||||
|
})
|
||||||
|
|
||||||
it('should handle revalidating HTML correctly', async () => {
|
it('should handle revalidating HTML correctly', async () => {
|
||||||
const route = '/blog/post-1/comment-1'
|
const route = '/blog/post-1/comment-1'
|
||||||
const initialHtml = await renderViaHTTP(appPort, route)
|
const initialHtml = await renderViaHTTP(appPort, route)
|
||||||
expect(initialHtml).toMatch(/Post:.*?post-1/)
|
expect(initialHtml).toMatch(/Post:.*?post-1/)
|
||||||
expect(initialHtml).toMatch(/Comment:.*?comment-1/)
|
expect(initialHtml).toMatch(/Comment:.*?comment-1/)
|
||||||
|
|
||||||
|
let newHtml = await renderViaHTTP(appPort, route)
|
||||||
|
expect(newHtml).toBe(initialHtml)
|
||||||
|
|
||||||
await waitFor(2 * 1000)
|
await waitFor(2 * 1000)
|
||||||
await renderViaHTTP(appPort, route)
|
await renderViaHTTP(appPort, route)
|
||||||
|
|
||||||
await waitFor(2 * 1000)
|
await waitFor(2 * 1000)
|
||||||
const newHtml = await renderViaHTTP(appPort, route)
|
newHtml = await renderViaHTTP(appPort, route)
|
||||||
expect(newHtml === initialHtml).toBe(false)
|
expect(newHtml === initialHtml).toBe(false)
|
||||||
expect(newHtml).toMatch(/Post:.*?post-1/)
|
expect(newHtml).toMatch(/Post:.*?post-1/)
|
||||||
expect(newHtml).toMatch(/Comment:.*?comment-1/)
|
expect(newHtml).toMatch(/Comment:.*?comment-1/)
|
||||||
|
@ -281,11 +297,14 @@ const runTests = (dev = false) => {
|
||||||
expect(initialJson).toMatch(/post-2/)
|
expect(initialJson).toMatch(/post-2/)
|
||||||
expect(initialJson).toMatch(/comment-3/)
|
expect(initialJson).toMatch(/comment-3/)
|
||||||
|
|
||||||
|
let newJson = await renderViaHTTP(appPort, route)
|
||||||
|
expect(newJson).toBe(initialJson)
|
||||||
|
|
||||||
await waitFor(2 * 1000)
|
await waitFor(2 * 1000)
|
||||||
await renderViaHTTP(appPort, route)
|
await renderViaHTTP(appPort, route)
|
||||||
|
|
||||||
await waitFor(2 * 1000)
|
await waitFor(2 * 1000)
|
||||||
const newJson = await renderViaHTTP(appPort, route)
|
newJson = await renderViaHTTP(appPort, route)
|
||||||
expect(newJson === initialJson).toBe(false)
|
expect(newJson === initialJson).toBe(false)
|
||||||
expect(newJson).toMatch(/post-2/)
|
expect(newJson).toMatch(/post-2/)
|
||||||
expect(newJson).toMatch(/comment-3/)
|
expect(newJson).toMatch(/comment-3/)
|
||||||
|
|
Loading…
Reference in a new issue