mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
Currently we error if you cannot produce a shell unless you have a Suspense boundary above the root. This is fine for normal IO but sync IO like Math.random() and new Date() have much more significant bad consequences for prerendering. Instead of treating these errors as another flavor of "must have a shell" validation we should instead treat them like they must be guarded behind something else dynamic like `await connection()`. In addition to unconditionally erroring for Sync IO in Server Components when prerendering this change also removes the Sync IO warning for runtime prefetches. This is because at the moment there is no way to debug these errors in dev. In the future we will add validation for prefetches and need to add back in some ability to warn for these cases but until then we will leave this case as a silent deopt.
84 lines
2.9 KiB
TypeScript
84 lines
2.9 KiB
TypeScript
import { nextTestSetup } from 'e2e-utils'
|
|
import expect from 'expect'
|
|
|
|
describe('cache-components', () => {
|
|
const { next, isNextDev, skipped } = nextTestSetup({
|
|
files: __dirname,
|
|
skipDeployment: true,
|
|
})
|
|
|
|
if (skipped) {
|
|
return
|
|
}
|
|
|
|
it('should not have route specific errors', async () => {
|
|
expect(next.cliOutput).not.toMatch('Error: Route "/')
|
|
expect(next.cliOutput).not.toMatch('Error occurred prerendering page')
|
|
})
|
|
|
|
it('should prerender pages with cached `Date.now()` calls', async () => {
|
|
let $ = await next.render$('/date/now/cached', {})
|
|
if (isNextDev) {
|
|
expect($('#layout').text()).toBe('at runtime')
|
|
expect($('#page').text()).toBe('at runtime')
|
|
expect($('#value').text()).toMatch(/^\d+$/)
|
|
} else {
|
|
expect($('#layout').text()).toBe('at buildtime')
|
|
expect($('#page').text()).toBe('at buildtime')
|
|
expect($('#value').text()).toMatch(/^\d+$/)
|
|
}
|
|
})
|
|
|
|
it('should prerender pages with cached `Date()` calls', async () => {
|
|
let $ = await next.render$('/date/date/cached', {})
|
|
if (isNextDev) {
|
|
expect($('#layout').text()).toBe('at runtime')
|
|
expect($('#page').text()).toBe('at runtime')
|
|
expect($('#value').text()).toContain('GMT')
|
|
} else {
|
|
expect($('#layout').text()).toBe('at buildtime')
|
|
expect($('#page').text()).toBe('at buildtime')
|
|
expect($('#value').text()).toContain('GMT')
|
|
}
|
|
})
|
|
|
|
it('should prerender pages with cached `new Date()` calls', async () => {
|
|
let $ = await next.render$('/date/new-date/cached', {})
|
|
if (isNextDev) {
|
|
expect($('#layout').text()).toBe('at runtime')
|
|
expect($('#page').text()).toBe('at runtime')
|
|
expect($('#value').text()).toContain('GMT')
|
|
} else {
|
|
expect($('#layout').text()).toBe('at buildtime')
|
|
expect($('#page').text()).toBe('at buildtime')
|
|
expect($('#value').text()).toContain('GMT')
|
|
}
|
|
})
|
|
|
|
it('should prerender pages with cached static Date instances like `new Date(0)`', async () => {
|
|
let $ = await next.render$('/date/static-date/cached', {})
|
|
if (isNextDev) {
|
|
expect($('#layout').text()).toBe('at runtime')
|
|
expect($('#page').text()).toBe('at runtime')
|
|
expect($('#value').text()).toContain('GMT')
|
|
} else {
|
|
expect($('#layout').text()).toBe('at buildtime')
|
|
expect($('#page').text()).toBe('at buildtime')
|
|
expect($('#value').text()).toContain('GMT')
|
|
}
|
|
})
|
|
|
|
it('should not prerender pages with uncached static Date instances like `new Date(0)`', async () => {
|
|
let $ = await next.render$('/date/static-date/uncached', {})
|
|
if (isNextDev) {
|
|
expect($('#layout').text()).toBe('at runtime')
|
|
expect($('#page').text()).toBe('at runtime')
|
|
expect($('#value').text()).toContain('GMT')
|
|
} else {
|
|
expect($('#layout').text()).toBe('at buildtime')
|
|
expect($('#page').text()).toBe('at buildtime')
|
|
expect($('#value').text()).toContain('GMT')
|
|
}
|
|
})
|
|
})
|