Unverified Commit 64c414fd authored by Josh Story's avatar Josh Story Committed by GitHub

[dynamicIO] Instrument crypto ranadom APIs to be dynamic (#70939)

crypto random bytes are IO semantically even if they are synchronous. We
instrument the sync crypto APIs that allow access to randomness to be be
dynamic while prerendering.
parent 4ae6d033
/** /**
* We extend `Date` during builds and revalidates to ensure that prerenders don't observe the clock as a source of IO * We extend `Date` during builds and revalidates to ensure that prerenders don't observe the clock as a source of IO
* When dynamicIO is enabled. The current time is a form of IO even though it resolves synchronously. When dyanmicIO is * When dynamicIO is enabled. The current time is a form of IO even though it resolves synchronously. When dyanmicIO is
* enabled we need to ensure that clock time is excluded from prerenders. * enabled we need to ensure that clock time is excluded from prerenders unless it is cached.
* *
* There is tension here because time is used for both output and introspection. While arbitrary we intend to reserve * There is tension here because time is used for both output and introspection. While arbitrary we intend to reserve
* `Date` for output use cases and `performance` for introspection use cases. If you want to measure * `Date` for output use cases and `performance` for introspection use cases. If you want to measure
...@@ -9,27 +9,7 @@ ...@@ -9,27 +9,7 @@
* *
* The extensions here never error nor alter the underlying Date objects, strings, and numbers created and thus should be transparent to callers. * The extensions here never error nor alter the underlying Date objects, strings, and numbers created and thus should be transparent to callers.
*/ */
import { workAsyncStorage } from '../../client/components/work-async-storage.external' import { io } from './utils'
import {
isDynamicIOPrerender,
workUnitAsyncStorage,
} from '../app-render/work-unit-async-storage.external'
import { abortOnSynchronousDynamicDataAccess } from '../app-render/dynamic-rendering'
function io(expression: string) {
const workUnitStore = workUnitAsyncStorage.getStore()
if (
workUnitStore &&
workUnitStore.type === 'prerender' &&
isDynamicIOPrerender(workUnitStore)
) {
const workStore = workAsyncStorage.getStore()
const route = workStore ? workStore.route : ''
if (workStore) {
abortOnSynchronousDynamicDataAccess(route, expression, workUnitStore)
}
}
}
function createNow(originalNow: typeof Date.now) { function createNow(originalNow: typeof Date.now) {
return { return {
......
/**
* We extend node:crypto APIs during builds and revalidates to ensure that prerenders don't observe random bytes
* When dynamicIO is enabled. Random bytes are a form of IO even if they resolve synchronously. When dyanmicIO is
* enabled we need to ensure that random bytes are excluded from prerenders unless they are cached.
*
*
* The extensions here never error nor alter the underlying return values and thus should be transparent to callers.
*/
import { io } from './utils'
if (process.env.NEXT_RUNTIME === 'edge') {
// nothing to patch
} else {
const nodeCrypto = require('node:crypto')
// require('node:crypto').getRandomValues is an alias for
// crypto.getRandomValues which is extended in web-crypto.tsx
// require('node:crypto').randomUUID is not an alias for crypto.randomUUID
const _randomUUID = nodeCrypto.randomUUID
nodeCrypto.randomUUID = function randomUUID() {
io("`require('node:crypto').randomUUID()`")
return _randomUUID.apply(this, arguments as any)
}
const _randomBytes = nodeCrypto.randomBytes
nodeCrypto.randomBytes = function randomBytes() {
if (typeof arguments[1] !== 'function') {
// randomBytes is sync if the second arg is undefined
io("`require('node:crypto').randomBytes(size)`")
}
return _randomBytes.apply(this, arguments as any)
}
const _randomFillSync = nodeCrypto.randomFillSync
nodeCrypto.randomFillSync = function randomFillSync() {
io("`require('node:crypto').randomFillSync(...)`")
return _randomFillSync.apply(this, arguments as any)
}
const _randomInt = nodeCrypto.randomInt
nodeCrypto.randomInt = function randomInt() {
if (typeof arguments[2] !== 'function') {
// randomInt is sync if the third arg is undefined
io("`require('node:crypto').randomInt(min, max)`")
}
return _randomInt.apply(this, arguments as any)
}
const _generatePrimeSync = nodeCrypto.generatePrimeSync
nodeCrypto.generatePrimeSync = function generatePrimeSync() {
io("`require('node:crypto').generatePrimeSync(...)`")
return _generatePrimeSync.apply(this, arguments as any)
}
const _generateKeyPairSync = nodeCrypto.generateKeyPairSync
nodeCrypto.generateKeyPairSync = function generateKeyPairSync() {
io("`require('node:crypto').generateKeyPairSync(...)`")
return _generateKeyPairSync.apply(this, arguments as any)
}
const _generateKeySync = nodeCrypto.generateKeySync
nodeCrypto.generateKeySync = function generateKeySync() {
io("`require('node:crypto').generateKeySync(...)`")
return _generateKeySync.apply(this, arguments as any)
}
}
...@@ -6,31 +6,13 @@ ...@@ -6,31 +6,13 @@
* The extensions here never error nor alter the random generation itself and thus should be transparent to callers. * The extensions here never error nor alter the random generation itself and thus should be transparent to callers.
*/ */
import { workAsyncStorage } from '../../client/components/work-async-storage.external' import { io } from './utils'
import {
isDynamicIOPrerender,
workUnitAsyncStorage,
} from '../app-render/work-unit-async-storage.external'
import { abortOnSynchronousDynamicDataAccess } from '../app-render/dynamic-rendering'
const originalRandom = Math.random const _random = Math.random
Math.random = function random() { Math.random = function random() {
const workUnitStore = workUnitAsyncStorage.getStore() io('`Math.random()`')
if ( return _random.apply(null, arguments as any)
workUnitStore &&
workUnitStore.type === 'prerender' &&
isDynamicIOPrerender(workUnitStore)
) {
const workStore = workAsyncStorage.getStore()
const route = workStore ? workStore.route : ''
const expression = '`Math.random()`'
if (workStore) {
abortOnSynchronousDynamicDataAccess(route, expression, workUnitStore)
}
}
return originalRandom.apply(null, arguments as any)
// We bind here to alter the `toString` printing to match `Math.random`'s native `toString`. // We bind here to alter the `toString` printing to match `Math.random`'s native `toString`.
// eslint-disable-next-line no-extra-bind // eslint-disable-next-line no-extra-bind
......
import { workAsyncStorage } from '../../client/components/work-async-storage.external'
import {
isDynamicIOPrerender,
workUnitAsyncStorage,
} from '../app-render/work-unit-async-storage.external'
import { abortOnSynchronousDynamicDataAccess } from '../app-render/dynamic-rendering'
export function io(expression: string) {
const workUnitStore = workUnitAsyncStorage.getStore()
if (
workUnitStore &&
workUnitStore.type === 'prerender' &&
isDynamicIOPrerender(workUnitStore)
) {
const workStore = workAsyncStorage.getStore()
const route = workStore ? workStore.route : ''
if (workStore) {
abortOnSynchronousDynamicDataAccess(route, expression, workUnitStore)
}
}
}
/**
* We extend Web Crypto APIs during builds and revalidates to ensure that prerenders don't observe random bytes
* When dynamicIO is enabled. Random bytes are a form of IO even if they resolve synchronously. When dyanmicIO is
* enabled we need to ensure that random bytes are excluded from prerenders unless they are cached.
*
*
* The extensions here never error nor alter the underlying return values and thus should be transparent to callers.
*/
import { io } from './utils'
let webCrypto: typeof crypto
if (process.env.NEXT_RUNTIME === 'edge') {
webCrypto = crypto
} else {
if (typeof crypto === 'undefined') {
webCrypto = require('node:crypto').webcrypto
} else {
webCrypto = crypto
}
}
const originalGetRandomValues = webCrypto.getRandomValues
webCrypto.getRandomValues = function getRandomValues() {
io('`crypto.getRandomValues()`')
return originalGetRandomValues.apply(webCrypto, arguments as any)
}
const _randomUUID = webCrypto.randomUUID
webCrypto.randomUUID = function randomUUID() {
io('`crypto.randomUUID()`')
return _randomUUID.apply(webCrypto, arguments as any)
} as typeof _randomUUID
...@@ -4,3 +4,5 @@ ...@@ -4,3 +4,5 @@
import './node-environment-baseline' import './node-environment-baseline'
import './node-environment-extensions/random' import './node-environment-extensions/random'
import './node-environment-extensions/date' import './node-environment-extensions/date'
import './node-environment-extensions/web-crypto'
import './node-environment-extensions/node-crypto'
import crypto from 'node:crypto'
import { SentinelValue } from '../../../getSentinelValue'
export default async function Page() {
const first = await getGeneratedKeyPair(1)
const second = await getGeneratedKeyPair(2)
return (
<div>
<dl>
<dt>
[first] require('node:crypto').generateKeyPairSync(type, options)
</dt>
<dd id="first">{first.publicKey}</dd>
<dt>
[second] require('node:crypto').generateKeyPairSync(type, options)
</dt>
<dd id="second">{second.publicKey}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
async function getGeneratedKeyPair(_nonce: number) {
'use cache'
return crypto.generateKeyPairSync('rsa', {
modulusLength: 512,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
},
})
}
import crypto from 'node:crypto'
import { SentinelValue } from '../../../getSentinelValue'
export default async function Page() {
await new Promise((r) => process.nextTick(r))
const first = crypto.generateKeyPairSync('rsa', keyGenOptions)
const second = crypto.generateKeyPairSync('rsa', keyGenOptions)
return (
<div>
<dl>
<dt>
[first] require('node:crypto').generateKeyPairSync(type, options)
</dt>
<dd id="first">{first.publicKey}</dd>
<dt>
[second] require('node:crypto').generateKeyPairSync(type, options)
</dt>
<dd id="second">{second.publicKey}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
const keyGenOptions = {
modulusLength: 512,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
},
} as const
import crypto from 'node:crypto'
import { SentinelValue } from '../../../getSentinelValue'
export default async function Page() {
const first = await getGeneratedKey(1)
const second = await getGeneratedKey(2)
return (
<div>
<dl>
<dt>[first] require('node:crypto').generateKeySync(type, options)</dt>
<dd id="first">{first.toString()}</dd>
<dt>[second] require('node:crypto').generateKeySync(type, options)</dt>
<dd id="second">{second.toString()}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
async function getGeneratedKey(_nonce: number) {
'use cache'
return crypto
.generateKeySync('hmac', {
length: 512,
})
.export()
}
import crypto from 'node:crypto'
import { SentinelValue } from '../../../getSentinelValue'
export default async function Page() {
await new Promise((r) => process.nextTick(r))
const first = crypto
.generateKeySync('hmac', {
length: 512,
})
.export()
const second = crypto
.generateKeySync('hmac', {
length: 512,
})
.export()
return (
<div>
<dl>
<dt>[first] require('node:crypto').generateKeySync(type, options)</dt>
<dd id="first">{first.toString('hex')}</dd>
<dt>[second] require('node:crypto').generateKeySync(type, options)</dt>
<dd id="second">{second.toString('hex')}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
import crypto from 'node:crypto'
import { SentinelValue } from '../../../getSentinelValue'
export default async function Page() {
const first = await getGeneratedPrime(1)
const second = await getGeneratedPrime(2)
return (
<div>
<dl>
<dt>[first] require('node:crypto').generatePrimeSync(size)</dt>
<dd id="first">{first.toString()}</dd>
<dt>[second] require('node:crypto').generatePrimeSync(size)</dt>
<dd id="second">{second.toString()}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
async function getGeneratedPrime(_nonce: number) {
'use cache'
return new Uint8Array(crypto.generatePrimeSync(128))
}
import crypto from 'node:crypto'
import { SentinelValue } from '../../../getSentinelValue'
export default async function Page() {
await new Promise((r) => process.nextTick(r))
const first = new Uint8Array(crypto.generatePrimeSync(128))
const second = new Uint8Array(crypto.generatePrimeSync(128))
return (
<div>
<dl>
<dt>[first] require('node:crypto').generatePrimeSync(size)</dt>
<dd id="first">{first.toString()}</dd>
<dt>[second] require('node:crypto').generatePrimeSync(size)</dt>
<dd id="second">{second.toString()}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
import crypto from 'node:crypto'
import { SentinelValue } from '../../../getSentinelValue'
export default async function Page() {
const first = await getRandomValues(1)
const second = await getRandomValues(2)
return (
<div>
<dl>
<dt>[first] require('node:crypto').getRandomValues()</dt>
<dd id="first">{first.toString()}</dd>
<dt>[second] require('node:crypto').getRandomValues()</dt>
<dd id="second">{second.toString()}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
async function getRandomValues(_nonce: number) {
'use cache'
const randomBytes = new Uint8Array(8)
crypto.getRandomValues(randomBytes)
return randomBytes
}
import crypto from 'node:crypto'
import { SentinelValue } from '../../../getSentinelValue'
export default async function Page() {
await new Promise((r) => process.nextTick(r))
const first = new Uint8Array(8)
const second = new Uint8Array(8)
await crypto.getRandomValues(first)
await crypto.getRandomValues(second)
return (
<div>
<dl>
<dt>[first] require('node:crypto').getRandomValues()</dt>
<dd id="first">{first.toString()}</dd>
<dt>[second] require('node:crypto').getRandomValues()</dt>
<dd id="second">{second.toString()}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
import { Suspense } from 'react'
export default async function Layout({
children,
}: {
children: React.ReactNode
}) {
return (
<Suspense fallback={<div data-fallback="">loading...</div>}>
{children}
</Suspense>
)
}
import crypto from 'node:crypto'
import { SentinelValue } from '../../../getSentinelValue'
export default async function Page() {
const first = await getRandomBytes(1)
const second = await getRandomBytes(2)
return (
<div>
<dl>
<dt>[first] require('node:crypto').randomBytes(size)</dt>
<dd id="first">{first.toString()}</dd>
<dt>[second] require('node:crypto').randomBytes(size)</dt>
<dd id="second">{second.toString()}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
async function getRandomBytes(nonce: number) {
'use cache'
if (nonce === 2) {
return crypto.randomBytes(8, undefined) as unknown as Buffer
} else {
return crypto.randomBytes(8)
}
}
import crypto from 'node:crypto'
import { SentinelValue } from '../../../getSentinelValue'
export default async function Page() {
await new Promise((r) => process.nextTick(r))
const first = crypto.randomBytes(8, undefined) as unknown as Buffer
const second = crypto.randomBytes(8)
return (
<div>
<dl>
<dt>[first] require('node:crypto').randomBytes(size)</dt>
<dd id="first">{first.toString('hex')}</dd>
<dt>[second] require('node:crypto').randomUUID(size)</dt>
<dd id="second">{second.toString('hex')}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
import crypto from 'node:crypto'
import { SentinelValue } from '../../../getSentinelValue'
export default async function Page() {
const first = await getFilledSync(1)
const second = await getFilledSync(2)
return (
<div>
<dl>
<dt>[first] require('node:crypto').randomFillSync(buffer)</dt>
<dd id="first">{first.toString()}</dd>
<dt>[second] require('node:crypto').randomBytes(buffer)</dt>
<dd id="second">{second.toString()}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
async function getFilledSync(_nonce: number) {
'use cache'
const randomBytes = new Uint8Array(16)
crypto.randomFillSync(randomBytes, 4, 8)
return randomBytes
}
import crypto from 'node:crypto'
import { SentinelValue } from '../../../getSentinelValue'
export default async function Page() {
await new Promise((r) => process.nextTick(r))
const first = new Uint8Array(16)
const second = new Uint8Array(16)
crypto.randomFillSync(first, 4, 8)
crypto.randomFillSync(second, 4, 8)
return (
<div>
<dl>
<dt>[first] require('node:crypto').randomFillSync(buffer)</dt>
<dd id="first">{first.toString()}</dd>
<dt>[second] require('node:crypto').randomBytes(buffer)</dt>
<dd id="second">{second.toString()}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
import crypto from 'node:crypto'
import { SentinelValue } from '../../../../getSentinelValue'
export default async function Page() {
const first = await getRandomIntBetween(1)
const second = await getRandomIntBetween(2)
return (
<div>
<dl>
<dt>[first] require('node:crypto').randomInt(min, max)</dt>
<dd id="first">{first}</dd>
<dt>[second] require('node:crypto').randomInt(min, max)</dt>
<dd id="second">{second}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
async function getRandomIntBetween(nonce: number) {
'use cache'
if (nonce === 2) {
// We want to exercise the case where the function arguments are length 3
// but the third arg is still not a callback so it runs sync
return crypto.randomInt(128, 256, undefined) as undefined as number
} else {
return crypto.randomInt(128, 256)
}
}
import crypto from 'node:crypto'
import { SentinelValue } from '../../../../getSentinelValue'
export default async function Page() {
await new Promise((r) => process.nextTick(r))
const first = crypto.randomInt(128, 256)
const second = crypto.randomInt(128, 256, undefined) as undefined as number
return (
<div>
<dl>
<dt>[first] require('node:crypto').randomInt(min, max)</dt>
<dd id="first">{first}</dd>
<dt>[second] require('node:crypto').randomInt(min, max)</dt>
<dd id="second">{second}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
import crypto from 'node:crypto'
import { SentinelValue } from '../../../../getSentinelValue'
export default async function Page() {
const first = await getRandomIntUpTo(1)
const second = await getRandomIntUpTo(2)
return (
<div>
<dl>
<dt>[first] require('node:crypto').randomInt(max)</dt>
<dd id="first">{first}</dd>
<dt>[second] require('node:crypto').randomInt(max)</dt>
<dd id="second">{second}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
async function getRandomIntUpTo(_nonce: number) {
'use cache'
return crypto.randomInt(128)
}
import crypto from 'node:crypto'
import { SentinelValue } from '../../../../getSentinelValue'
export default async function Page() {
await new Promise((r) => process.nextTick(r))
const first = crypto.randomInt(128)
const second = crypto.randomInt(128)
return (
<div>
<dl>
<dt>[first] require('node:crypto').randomInt(max)</dt>
<dd id="first">{first}</dd>
<dt>[second] require('node:crypto').randomInt(max)</dt>
<dd id="second">{second}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
import crypto from 'node:crypto'
import { SentinelValue } from '../../../getSentinelValue'
export default async function Page() {
const first = await getRandomUUID(1)
const second = await getRandomUUID(2)
return (
<div>
<dl>
<dt>[first] require('node:crypto').randomUUID()</dt>
<dd id="first">{first.toString()}</dd>
<dt>[second] require('node:crypto').randomUUID()</dt>
<dd id="second">{second.toString()}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
async function getRandomUUID(_nonce: number) {
'use cache'
return crypto.randomUUID()
}
import crypto from 'node:crypto'
import { SentinelValue } from '../../../getSentinelValue'
export default async function Page() {
await new Promise((r) => process.nextTick(r))
const first = crypto.randomUUID()
const second = crypto.randomUUID()
return (
<div>
<dl>
<dt>[first] require('node:crypto').randomUUID()</dt>
<dd id="first">{first.toString()}</dd>
<dt>[second] require('node:crypto').randomUUID()</dt>
<dd id="second">{second.toString()}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
import { SentinelValue } from '../../../getSentinelValue'
export default async function Page() {
const first = await getRandomValues(1)
const second = await getRandomValues(2)
return (
<div>
<dl>
<dt>[first] crypto.getRandomValues()</dt>
<dd id="first">{first.toString()}</dd>
<dt>[second] crypto.getRandomValues()</dt>
<dd id="second">{second.toString()}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
async function getRandomValues(_nonce: number) {
'use cache'
const randomBytes = new Uint8Array(8)
crypto.getRandomValues(randomBytes)
return randomBytes
}
import { SentinelValue } from '../../../getSentinelValue'
export default async function Page() {
await new Promise((r) => process.nextTick(r))
const first = new Uint8Array(8)
const second = new Uint8Array(8)
await crypto.getRandomValues(first)
await crypto.getRandomValues(second)
return (
<div>
<dl>
<dt>[first] crypto.getRandomValues()</dt>
<dd id="first">{first.toString()}</dd>
<dt>[second] crypto.getRandomValues()</dt>
<dd id="second">{second.toString()}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
import { Suspense } from 'react'
export default async function Layout({
children,
}: {
children: React.ReactNode
}) {
return (
<Suspense fallback={<div data-fallback="">loading...</div>}>
{children}
</Suspense>
)
}
import { SentinelValue } from '../../../getSentinelValue'
export default async function Page() {
const first = await getRandomUUID(1)
const second = await getRandomUUID(2)
return (
<div>
<dl>
<dt>[first] crypto.randomUUID()</dt>
<dd id="first">{first.toString()}</dd>
<dt>[second] crypto.randomUUID()</dt>
<dd id="second">{second.toString()}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
async function getRandomUUID(_nonce: number) {
'use cache'
return crypto.randomUUID()
}
import { SentinelValue } from '../../../getSentinelValue'
export default async function Page() {
await new Promise((r) => process.nextTick(r))
const first = crypto.randomUUID()
const second = crypto.randomUUID()
return (
<div>
<dl>
<dt>[first] crypto.randomUUID()</dt>
<dd id="first">{first.toString()}</dd>
<dt>[second] crypto.randomUUID()</dt>
<dd id="second">{second.toString()}</dd>
</dl>
<span id="page">
<SentinelValue />
</span>
</div>
)
}
This diff is collapsed.
import { nextTestSetup } from 'e2e-utils'
const WITH_PPR = !!process.env.__NEXT_EXPERIMENTAL_PPR
describe('dynamic-io', () => {
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 `crypto.getRandomValues(...)` calls', async () => {
let $ = await next.render$('/web-crypto/get-random-values/cached', {})
if (isNextDev) {
expect($('#layout').text()).toBe('at runtime')
expect($('#page').text()).toBe('at runtime')
expect($('#first').text()).not.toEqual($('#second').text())
} else {
expect($('#layout').text()).toBe('at buildtime')
expect($('#page').text()).toBe('at buildtime')
expect($('#first').text()).not.toEqual($('#second').text())
}
})
it('should not prerender pages with uncached `crypto.getRandomValues(...)` calls', async () => {
let $ = await next.render$('/web-crypto/get-random-values/uncached', {})
if (isNextDev) {
expect($('#layout').text()).toBe('at runtime')
expect($('#page').text()).toBe('at runtime')
expect($('#first').text()).not.toEqual($('#second').text())
} else if (WITH_PPR) {
expect($('#layout').text()).toBe('at buildtime')
expect($('#page').text()).toBe('at runtime')
expect($('#first').text()).not.toEqual($('#second').text())
} else {
expect($('#layout').text()).toBe('at runtime')
expect($('#page').text()).toBe('at runtime')
expect($('#first').text()).not.toEqual($('#second').text())
}
})
it('should prerender pages with cached `crypto.randomUUID()` calls', async () => {
let $ = await next.render$('/web-crypto/random-uuid/cached', {})
if (isNextDev) {
expect($('#layout').text()).toBe('at runtime')
expect($('#page').text()).toBe('at runtime')
expect($('#first').text()).not.toEqual($('#second').text())
} else {
expect($('#layout').text()).toBe('at buildtime')
expect($('#page').text()).toBe('at buildtime')
expect($('#first').text()).not.toEqual($('#second').text())
}
})
it('should not prerender pages with uncached `crypto.randomUUID()` calls', async () => {
let $ = await next.render$('/web-crypto/random-uuid/uncached', {})
if (isNextDev) {
expect($('#layout').text()).toBe('at runtime')
expect($('#page').text()).toBe('at runtime')
expect($('#first').text()).not.toEqual($('#second').text())
} else if (WITH_PPR) {
expect($('#layout').text()).toBe('at buildtime')
expect($('#page').text()).toBe('at runtime')
expect($('#first').text()).not.toEqual($('#second').text())
} else {
expect($('#layout').text()).toBe('at runtime')
expect($('#page').text()).toBe('at runtime')
expect($('#first').text()).not.toEqual($('#second').text())
}
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment