Unverified Commit 766b7cbf authored by Josh Story's avatar Josh Story Committed by GitHub

Stabilize `unstable_io` (#93621)

Removes the unstable prefix from `unstable_io`. Since this was only
shipped in canaries with the unstable prefix we are going to just remove
it without retaining the unstable prefix simultaneously.
parent 30099378
--- ---
title: unstable_io title: io
description: API Reference for the unstable_io function. description: API Reference for the io function.
version: draft version: draft
--- ---
`unstable_io()` informs Next.js that an IO operation will follow this call. When [Cache Components](/docs/app/api-reference/config/next-config-js/cacheComponents) is not enabled or when rendering in Pages Router, signifying IO in this way is not meaningful and the call will always resolve immediately. When Cache Components is enabled, you may be required to add `await unstable_io()` preceding synchronous IO that is encountered while prerendering pages (`new Date()` for example). Additionally, if you want to avoid having genuine uncached IO invoked while prerendering, you shield it by preceeding it with `await unstable_io()`. `io()` informs Next.js that an IO operation will follow this call. When [Cache Components](/docs/app/api-reference/config/next-config-js/cacheComponents) is not enabled or when rendering in Pages Router, signifying IO in this way is not meaningful and the call will always resolve immediately. When Cache Components is enabled, you may be required to add `await io()` preceding synchronous IO that is encountered while prerendering pages (`new Date()` for example). Additionally, if you want to avoid having genuine uncached IO invoked while prerendering, you shield it by preceeding it with `await io()`.
```ts filename="app/page.tsx" switcher ```ts filename="app/page.tsx" switcher
import { unstable_io } from 'next/cache' import { io } from 'next/cache'
import { db } from '@/lib/db' import { db } from '@/lib/db'
export default async function Page() { export default async function Page() {
// Synchronous IO: new Date() would fail during prerender without this // Synchronous IO: new Date() would fail during prerender without this
await unstable_io() await io()
const now = new Date().toISOString() const now = new Date().toISOString()
// Async IO: the query would run and be discarded during prerender; // Async IO: the query would run and be discarded during prerender;
// unstable_io() above lets Next.js skip it entirely // io() above lets Next.js skip it entirely
const orders = await db.query('SELECT * FROM orders LIMIT 10') const orders = await db.query('SELECT * FROM orders LIMIT 10')
return ( return (
...@@ -33,16 +33,16 @@ export default async function Page() { ...@@ -33,16 +33,16 @@ export default async function Page() {
``` ```
```js filename="app/page.js" switcher ```js filename="app/page.js" switcher
import { unstable_io } from 'next/cache' import { io } from 'next/cache'
import { db } from '@/lib/db' import { db } from '@/lib/db'
export default async function Page() { export default async function Page() {
// Synchronous IO: new Date() would fail during prerender without this // Synchronous IO: new Date() would fail during prerender without this
await unstable_io() await io()
const now = new Date().toISOString() const now = new Date().toISOString()
// Async IO: the query would run and be discarded during prerender; // Async IO: the query would run and be discarded during prerender;
// unstable_io() above lets Next.js skip it entirely // io() above lets Next.js skip it entirely
const orders = await db.query('SELECT * FROM orders LIMIT 10') const orders = await db.query('SELECT * FROM orders LIMIT 10')
return ( return (
...@@ -62,16 +62,16 @@ export default async function Page() { ...@@ -62,16 +62,16 @@ export default async function Page() {
[`connection()`](/docs/app/api-reference/functions/connection) requires an active HTTP request context and signals that the component needs request-specific data. It is imported from `next/server`. [`connection()`](/docs/app/api-reference/functions/connection) requires an active HTTP request context and signals that the component needs request-specific data. It is imported from `next/server`.
`unstable_io()` does not require a request context. It can be used inside `"use cache"` scopes, client components, and anywhere you perform IO that should not be included in a static prerender. It is imported from `next/cache`. `io()` does not require a request context. It can be used inside `"use cache"` scopes, client components, and anywhere you perform IO that should not be included in a static prerender. It is imported from `next/cache`.
Use `connection()` when you need the request itself (cookies, headers, etc.). Use `unstable_io()` when you perform IO that is independent of the request but should still prevent static prerendering. Use `connection()` when you need the request itself (cookies, headers, etc.). Use `io()` when you perform IO that is independent of the request but should still prevent static prerendering.
## Reference ## Reference
### Type ### Type
```ts ```ts
function unstable_io(): Promise<void> function io(): Promise<void>
``` ```
### Parameters ### Parameters
...@@ -84,12 +84,12 @@ function unstable_io(): Promise<void> ...@@ -84,12 +84,12 @@ function unstable_io(): Promise<void>
## Good to know ## Good to know
- `unstable_io()` is imported from `next/cache`, not `next/server`. - `io()` is imported from `next/cache`, not `next/server`.
- Inside `"use cache"` scopes, `unstable_io()` resolves immediately. The cache captures the IO result at fill time. - Inside `"use cache"` scopes, `io()` resolves immediately. The cache captures the IO result at fill time.
- In client components, `unstable_io()` resolves immediately since there is no prerender context in the browser. - In client components, `io()` resolves immediately since there is no prerender context in the browser.
### Version History ### Version History
| Version | Changes | | Version | Changes |
| --------- | -------------------- | | --------- | ----------- |
| `v16.x.x` | `unstable_io` added. | | `v16.x.x` | `io` added. |
...@@ -9,7 +9,7 @@ export { ...@@ -9,7 +9,7 @@ export {
export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store' export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store'
export { unstable_io } from 'next/dist/server/request/io' export { io } from 'next/dist/server/request/io'
import { cacheTag } from 'next/dist/server/use-cache/cache-tag' import { cacheTag } from 'next/dist/server/use-cache/cache-tag'
......
...@@ -17,7 +17,7 @@ if (process.env.NEXT_RUNTIME === '') { ...@@ -17,7 +17,7 @@ if (process.env.NEXT_RUNTIME === '') {
} }
}, },
unstable_noStore: function unstable_noStore() {}, unstable_noStore: function unstable_noStore() {},
unstable_io: require('next/dist/client/request/io.browser').unstable_io, io: require('next/dist/client/request/io.browser').io,
updateTag: notAvailableInClient('updateTag'), updateTag: notAvailableInClient('updateTag'),
revalidateTag: notAvailableInClient('revalidateTag'), revalidateTag: notAvailableInClient('revalidateTag'),
...@@ -46,7 +46,7 @@ if (process.env.NEXT_RUNTIME === '') { ...@@ -46,7 +46,7 @@ if (process.env.NEXT_RUNTIME === '') {
unstable_noStore: unstable_noStore:
require('next/dist/server/web/spec-extension/unstable-no-store') require('next/dist/server/web/spec-extension/unstable-no-store')
.unstable_noStore, .unstable_noStore,
unstable_io: require('next/dist/server/request/io').unstable_io, io: require('next/dist/server/request/io').io,
cacheLife: require('next/dist/server/use-cache/cache-life').cacheLife, cacheLife: require('next/dist/server/use-cache/cache-life').cacheLife,
cacheTag: require('next/dist/server/use-cache/cache-tag').cacheTag, cacheTag: require('next/dist/server/use-cache/cache-tag').cacheTag,
} }
...@@ -94,4 +94,4 @@ exports.unstable_cacheLife = cacheExports.unstable_cacheLife ...@@ -94,4 +94,4 @@ exports.unstable_cacheLife = cacheExports.unstable_cacheLife
exports.cacheTag = cacheExports.cacheTag exports.cacheTag = cacheExports.cacheTag
exports.unstable_cacheTag = cacheExports.unstable_cacheTag exports.unstable_cacheTag = cacheExports.unstable_cacheTag
exports.refresh = cacheExports.refresh exports.refresh = cacheExports.refresh
exports.unstable_io = cacheExports.unstable_io exports.io = cacheExports.io
...@@ -5,9 +5,9 @@ const resolvedIOPromise: Promise<void> = Promise.resolve(undefined) ...@@ -5,9 +5,9 @@ const resolvedIOPromise: Promise<void> = Promise.resolve(undefined)
;(resolvedIOPromise as any).value = undefined ;(resolvedIOPromise as any).value = undefined
/** /**
* Browser implementation of unstable_io(). On the client there is no * Browser implementation of io(). On the client there is no
* prerender context so we always resolve immediately. * prerender context so we always resolve immediately.
*/ */
export function unstable_io(): Promise<void> { export function io(): Promise<void> {
return resolvedIOPromise return resolvedIOPromise
} }
...@@ -29,7 +29,7 @@ describe('cache-life-type-utils', () => { ...@@ -29,7 +29,7 @@ describe('cache-life-type-utils', () => {
refresh, refresh,
} from 'next/dist/server/web/spec-extension/revalidate' } from 'next/dist/server/web/spec-extension/revalidate'
export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store' export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store'
export { unstable_io } from 'next/dist/server/request/io' export { io } from 'next/dist/server/request/io'
/** /**
...@@ -187,7 +187,7 @@ describe('cache-life-type-utils', () => { ...@@ -187,7 +187,7 @@ describe('cache-life-type-utils', () => {
refresh, refresh,
} from 'next/dist/server/web/spec-extension/revalidate' } from 'next/dist/server/web/spec-extension/revalidate'
export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store' export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store'
export { unstable_io } from 'next/dist/server/request/io' export { io } from 'next/dist/server/request/io'
/** /**
...@@ -265,7 +265,7 @@ describe('cache-life-type-utils', () => { ...@@ -265,7 +265,7 @@ describe('cache-life-type-utils', () => {
refresh, refresh,
} from 'next/dist/server/web/spec-extension/revalidate' } from 'next/dist/server/web/spec-extension/revalidate'
export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store' export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store'
export { unstable_io } from 'next/dist/server/request/io' export { io } from 'next/dist/server/request/io'
/** /**
...@@ -342,7 +342,7 @@ describe('cache-life-type-utils', () => { ...@@ -342,7 +342,7 @@ describe('cache-life-type-utils', () => {
refresh, refresh,
} from 'next/dist/server/web/spec-extension/revalidate' } from 'next/dist/server/web/spec-extension/revalidate'
export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store' export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store'
export { unstable_io } from 'next/dist/server/request/io' export { io } from 'next/dist/server/request/io'
/** /**
...@@ -420,7 +420,7 @@ describe('cache-life-type-utils', () => { ...@@ -420,7 +420,7 @@ describe('cache-life-type-utils', () => {
refresh, refresh,
} from 'next/dist/server/web/spec-extension/revalidate' } from 'next/dist/server/web/spec-extension/revalidate'
export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store' export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store'
export { unstable_io } from 'next/dist/server/request/io' export { io } from 'next/dist/server/request/io'
/** /**
...@@ -502,7 +502,7 @@ describe('cache-life-type-utils', () => { ...@@ -502,7 +502,7 @@ describe('cache-life-type-utils', () => {
refresh, refresh,
} from 'next/dist/server/web/spec-extension/revalidate' } from 'next/dist/server/web/spec-extension/revalidate'
export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store' export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store'
export { unstable_io } from 'next/dist/server/request/io' export { io } from 'next/dist/server/request/io'
/** /**
......
...@@ -177,7 +177,7 @@ declare module 'next/cache' { ...@@ -177,7 +177,7 @@ declare module 'next/cache' {
refresh, refresh,
} from 'next/dist/server/web/spec-extension/revalidate' } from 'next/dist/server/web/spec-extension/revalidate'
export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store' export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store'
export { unstable_io } from 'next/dist/server/request/io' export { io } from 'next/dist/server/request/io'
${overloads} ${overloads}
......
...@@ -21,10 +21,10 @@ const resolvedIOPromise: Promise<void> = Promise.resolve(undefined) ...@@ -21,10 +21,10 @@ const resolvedIOPromise: Promise<void> = Promise.resolve(undefined)
* point, creating a dynamic boundary. Inside `"use cache"` scopes or during * point, creating a dynamic boundary. Inside `"use cache"` scopes or during
* a real request it resolves immediately. * a real request it resolves immediately.
* *
* Unlike `connection()`, `unstable_io()` does not require an actual HTTP * Unlike `connection()`, `io()` does not require an actual HTTP request and
* request and can be used freely inside cache scopes and client components. * can be used freely inside cache scopes and client components.
*/ */
export function unstable_io(): Promise<void> { export function io(): Promise<void> {
const workStore = workAsyncStorage.getStore() const workStore = workAsyncStorage.getStore()
const workUnitStore = workUnitAsyncStorage.getStore() const workUnitStore = workUnitAsyncStorage.getStore()
...@@ -59,7 +59,7 @@ export function unstable_io(): Promise<void> { ...@@ -59,7 +59,7 @@ export function unstable_io(): Promise<void> {
return makeHangingPromise( return makeHangingPromise(
workUnitStore.renderSignal, workUnitStore.renderSignal,
workStore.route, workStore.route,
'`unstable_io()`' '`io()`'
) )
case 'prerender-ppr': case 'prerender-ppr':
// Dead code to be removed when we eliminate legacy ppr code // Dead code to be removed when we eliminate legacy ppr code
...@@ -68,7 +68,7 @@ export function unstable_io(): Promise<void> { ...@@ -68,7 +68,7 @@ export function unstable_io(): Promise<void> {
case 'cache': case 'cache':
case 'private-cache': case 'private-cache':
case 'unstable-cache': case 'unstable-cache':
// Inside cache scopes, unstable_io() resolves immediately. // Inside cache scopes, io() resolves immediately.
// Caches can contain IO-dependent code like new Date() — it will // Caches can contain IO-dependent code like new Date() — it will
// simply return the value at cache-fill time. // simply return the value at cache-fill time.
// ... // ...
...@@ -79,7 +79,7 @@ export function unstable_io(): Promise<void> { ...@@ -79,7 +79,7 @@ export function unstable_io(): Promise<void> {
// ... // ...
// intentional fallthrough // intentional fallthrough
case 'validation-client': case 'validation-client':
// unstable_io() is usable in client components, resolve immediately. // io() is usable in client components, resolve immediately.
// The reason we take this position is most io shielding you would do // The reason we take this position is most io shielding you would do
// in a browser is for sync IO as there aren't many non-fetch based IO // in a browser is for sync IO as there aren't many non-fetch based IO
// operations you can do in the browser that have meaningful latency. // operations you can do in the browser that have meaningful latency.
......
...@@ -373,7 +373,7 @@ ...@@ -373,7 +373,7 @@
"test/production/app-dir/resume-data-cache/resume-data-cache.test.ts", "test/production/app-dir/resume-data-cache/resume-data-cache.test.ts",
"test/production/app-dir/unstable-cache-foreground-revalidate/unstable-cache-foreground-revalidate.test.ts", "test/production/app-dir/unstable-cache-foreground-revalidate/unstable-cache-foreground-revalidate.test.ts",
"test/e2e/app-dir/parallel-routes-root-param-dynamic-child/parallel-routes-root-param-dynamic-child.test.ts", "test/e2e/app-dir/parallel-routes-root-param-dynamic-child/parallel-routes-root-param-dynamic-child.test.ts",
"test/e2e/app-dir/unstable-io/unstable-io.test.ts" "test/e2e/app-dir/io/io.test.ts"
] ]
} }
} }
import { Suspense } from 'react' import { Suspense } from 'react'
import { unstable_io } from 'next/cache' import { io } from 'next/cache'
import { getSentinelValue } from '../getSentinelValue' import { getSentinelValue } from '../getSentinelValue'
export default function Page() { export default function Page() {
return ( return (
<> <>
<p> <p>
This page uses unstable_io() inside a Suspense boundary. Without cache This page uses io() inside a Suspense boundary. With cache components
components unstable_io() is a no-op during prerendering so the entire the content after io() should be dynamic and rendered at request time,
page should be fully static. not during the build prerender.
</p> </p>
<div id="before">{getSentinelValue()}</div> <div id="before">{getSentinelValue()}</div>
<Suspense fallback={<div id="fallback">loading...</div>}> <Suspense fallback={<div id="fallback">loading...</div>}>
...@@ -20,6 +20,6 @@ export default function Page() { ...@@ -20,6 +20,6 @@ export default function Page() {
} }
async function DynamicComponent() { async function DynamicComponent() {
await unstable_io() await io()
return <div id="after-io">{getSentinelValue()}</div> return <div id="after-io">{getSentinelValue()}</div>
} }
import { Suspense } from 'react' import { Suspense } from 'react'
import { unstable_io } from 'next/cache' import { io } from 'next/cache'
import { getSentinelValue } from '../getSentinelValue' import { getSentinelValue } from '../getSentinelValue'
export default function Page() { export default function Page() {
return ( return (
<> <>
<p> <p>
This page uses unstable_io() inside a "use cache" function. Inside cache This page uses io() inside a "use cache" function. Inside cache scopes
scopes unstable_io() resolves immediately so the cached value should be io() resolves immediately so the cached value should be computed at
computed at cache-fill time during the build. cache-fill time during the build.
</p> </p>
<Suspense fallback="loading..."> <Suspense fallback="loading...">
<CachedComponent /> <CachedComponent />
...@@ -25,6 +25,6 @@ async function CachedComponent() { ...@@ -25,6 +25,6 @@ async function CachedComponent() {
async function getCachedValue() { async function getCachedValue() {
'use cache' 'use cache'
await unstable_io() await io()
return getSentinelValue() return getSentinelValue()
} }
import { unstable_io } from 'next/cache' import { io } from 'next/cache'
export default function PagesGSP({ rendered }: { rendered: string }) { export default function PagesGSP({ rendered }: { rendered: string }) {
return ( return (
<> <>
<p>This page uses unstable_io() in getStaticProps.</p> <p>This page uses io() in getStaticProps.</p>
<div id="pages-content">{rendered}</div> <div id="pages-content">{rendered}</div>
</> </>
) )
} }
export async function getStaticProps() { export async function getStaticProps() {
await unstable_io() await io()
return { props: { rendered: 'ok' } } return { props: { rendered: 'ok' } }
} }
import { unstable_io } from 'next/cache' import { io } from 'next/cache'
export default function PagesGSSP({ rendered }: { rendered: string }) { export default function PagesGSSP({ rendered }: { rendered: string }) {
return ( return (
<> <>
<p>This page uses unstable_io() in getServerSideProps.</p> <p>This page uses io() in getServerSideProps.</p>
<div id="pages-content">{rendered}</div> <div id="pages-content">{rendered}</div>
</> </>
) )
} }
export async function getServerSideProps() { export async function getServerSideProps() {
await unstable_io() await io()
return { props: { rendered: 'ok' } } return { props: { rendered: 'ok' } }
} }
import React from 'react' import React from 'react'
import { unstable_io } from 'next/cache' import { io } from 'next/cache'
export default function PagesUse() { export default function PagesUse() {
if (typeof React.use === 'function') { if (typeof React.use === 'function') {
React.use(unstable_io()) React.use(io())
} }
return ( return (
<> <>
<p>This page calls React.use(unstable_io()) in the component body.</p> <p>This page calls React.use(io()) in the component body.</p>
<div id="pages-content">ok</div> <div id="pages-content">ok</div>
</> </>
) )
......
import { Suspense } from 'react' import { Suspense } from 'react'
import { unstable_io } from 'next/cache' import { io } from 'next/cache'
import { getSentinelValue } from '../getSentinelValue' import { getSentinelValue } from '../getSentinelValue'
export default function Page() { export default function Page() {
return ( return (
<> <>
<p> <p>
This page uses unstable_io() inside a Suspense boundary. With cache This page uses io() inside a Suspense boundary. Without cache components
components the content after unstable_io() should be dynamic and io() is a no-op during prerendering so the entire page should be fully
rendered at request time, not during the build prerender. static.
</p> </p>
<div id="before">{getSentinelValue()}</div> <div id="before">{getSentinelValue()}</div>
<Suspense fallback={<div id="fallback">loading...</div>}> <Suspense fallback={<div id="fallback">loading...</div>}>
...@@ -20,6 +20,6 @@ export default function Page() { ...@@ -20,6 +20,6 @@ export default function Page() {
} }
async function DynamicComponent() { async function DynamicComponent() {
await unstable_io() await io()
return <div id="after-io">{getSentinelValue()}</div> return <div id="after-io">{getSentinelValue()}</div>
} }
import { unstable_io } from 'next/cache' import { io } from 'next/cache'
export default function PagesGSP({ rendered }: { rendered: string }) { export default function PagesGSP({ rendered }: { rendered: string }) {
return ( return (
<> <>
<p>This page uses unstable_io() in getStaticProps.</p> <p>This page uses io() in getStaticProps.</p>
<div id="pages-content">{rendered}</div> <div id="pages-content">{rendered}</div>
</> </>
) )
} }
export async function getStaticProps() { export async function getStaticProps() {
await unstable_io() await io()
return { props: { rendered: 'ok' } } return { props: { rendered: 'ok' } }
} }
import { unstable_io } from 'next/cache' import { io } from 'next/cache'
export default function PagesGSSP({ rendered }: { rendered: string }) { export default function PagesGSSP({ rendered }: { rendered: string }) {
return ( return (
<> <>
<p>This page uses unstable_io() in getServerSideProps.</p> <p>This page uses io() in getServerSideProps.</p>
<div id="pages-content">{rendered}</div> <div id="pages-content">{rendered}</div>
</> </>
) )
} }
export async function getServerSideProps() { export async function getServerSideProps() {
await unstable_io() await io()
return { props: { rendered: 'ok' } } return { props: { rendered: 'ok' } }
} }
import React from 'react' import React from 'react'
import { unstable_io } from 'next/cache' import { io } from 'next/cache'
export default function PagesUse() { export default function PagesUse() {
if (typeof React.use === 'function') { if (typeof React.use === 'function') {
React.use(unstable_io()) React.use(io())
} }
return ( return (
<> <>
<p>This page calls React.use(unstable_io()) in the component body.</p> <p>This page calls React.use(io()) in the component body.</p>
<div id="pages-content">ok</div> <div id="pages-content">ok</div>
</> </>
) )
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
describe('unstable_io with cache components', () => { describe('io with cache components', () => {
const { next, isNextDev, skipped } = nextTestSetup({ const { next, isNextDev, skipped } = nextTestSetup({
files: __dirname + '/fixtures/cache-components', files: __dirname + '/fixtures/cache-components',
skipDeployment: true, skipDeployment: true,
...@@ -10,7 +10,7 @@ describe('unstable_io with cache components', () => { ...@@ -10,7 +10,7 @@ describe('unstable_io with cache components', () => {
return return
} }
it('should make content after unstable_io() dynamic during prerender', async () => { it('should make content after io() dynamic during prerender', async () => {
const $ = await next.render$('/io-boundary') const $ = await next.render$('/io-boundary')
if (isNextDev) { if (isNextDev) {
// In dev mode everything renders at runtime // In dev mode everything renders at runtime
...@@ -18,9 +18,9 @@ describe('unstable_io with cache components', () => { ...@@ -18,9 +18,9 @@ describe('unstable_io with cache components', () => {
expect($('#after-io').text()).toBe('at runtime') expect($('#after-io').text()).toBe('at runtime')
expect($('#page').text()).toBe('at runtime') expect($('#page').text()).toBe('at runtime')
} else { } else {
// In production with cache components, unstable_io() creates a dynamic // In production with cache components, io() creates a dynamic
// boundary. Content in the static shell is rendered at buildtime. // boundary. Content in the static shell is rendered at buildtime.
// Content after unstable_io() is rendered at request time because the // Content after io() is rendered at request time because the
// hanging promise prevented it from executing during the build prerender. // hanging promise prevented it from executing during the build prerender.
expect($('#before').text()).toBe('at buildtime') expect($('#before').text()).toBe('at buildtime')
expect($('#page').text()).toBe('at buildtime') expect($('#page').text()).toBe('at buildtime')
...@@ -34,7 +34,7 @@ describe('unstable_io with cache components', () => { ...@@ -34,7 +34,7 @@ describe('unstable_io with cache components', () => {
expect($('#cached-value').text()).toBe('at runtime') expect($('#cached-value').text()).toBe('at runtime')
expect($('#page').text()).toBe('at runtime') expect($('#page').text()).toBe('at runtime')
} else { } else {
// unstable_io() inside "use cache" is a no-op so the cached value is // io() inside "use cache" is a no-op so the cached value is
// computed at cache-fill time during the build // computed at cache-fill time during the build
expect($('#cached-value').text()).toBe('at buildtime') expect($('#cached-value').text()).toBe('at buildtime')
expect($('#page').text()).toBe('at buildtime') expect($('#page').text()).toBe('at buildtime')
...@@ -57,7 +57,7 @@ describe('unstable_io with cache components', () => { ...@@ -57,7 +57,7 @@ describe('unstable_io with cache components', () => {
}) })
}) })
describe('unstable_io without cache components', () => { describe('io without cache components', () => {
const { next, isNextDev, skipped } = nextTestSetup({ const { next, isNextDev, skipped } = nextTestSetup({
files: __dirname + '/fixtures/default', files: __dirname + '/fixtures/default',
skipDeployment: true, skipDeployment: true,
...@@ -74,7 +74,7 @@ describe('unstable_io without cache components', () => { ...@@ -74,7 +74,7 @@ describe('unstable_io without cache components', () => {
expect($('#after-io').text()).toBe('at runtime') expect($('#after-io').text()).toBe('at runtime')
expect($('#page').text()).toBe('at runtime') expect($('#page').text()).toBe('at runtime')
} else { } else {
// Without cache components, unstable_io() resolves immediately during // Without cache components, io() resolves immediately during
// prerendering so the entire page is fully static // prerendering so the entire page is fully static
expect($('#before').text()).toBe('at buildtime') expect($('#before').text()).toBe('at buildtime')
expect($('#after-io').text()).toBe('at buildtime') expect($('#after-io').text()).toBe('at buildtime')
......
...@@ -8159,17 +8159,17 @@ ...@@ -8159,17 +8159,17 @@
"flakey": [], "flakey": [],
"runtimeError": false "runtimeError": false
}, },
"test/e2e/app-dir/unstable-io/unstable-io.test.ts": { "test/e2e/app-dir/io/io.test.ts": {
"passed": [ "passed": [
"unstable_io with cache components should make content after unstable_io() dynamic during prerender", "io with cache components should make content after io() dynamic during prerender",
"unstable_io with cache components should resolve immediately inside a \"use cache\" scope", "io with cache components should resolve immediately inside a \"use cache\" scope",
"unstable_io with cache components should work in pages router with React.use() (CC)", "io with cache components should work in pages router with React.use() (CC)",
"unstable_io with cache components should work in pages router with getServerSideProps (CC)", "io with cache components should work in pages router with getServerSideProps (CC)",
"unstable_io with cache components should work in pages router with getStaticProps (CC)", "io with cache components should work in pages router with getStaticProps (CC)",
"unstable_io without cache components should be a no-op during prerender without cache components", "io without cache components should be a no-op during prerender without cache components",
"unstable_io without cache components should work in pages router with React.use()", "io without cache components should work in pages router with React.use()",
"unstable_io without cache components should work in pages router with getServerSideProps", "io without cache components should work in pages router with getServerSideProps",
"unstable_io without cache components should work in pages router with getStaticProps" "io without cache components should work in pages router with getStaticProps"
], ],
"failed": [], "failed": [],
"pending": [], "pending": [],
...@@ -10533,17 +10533,17 @@ ...@@ -10533,17 +10533,17 @@
"flakey": [], "flakey": [],
"runtimeError": false "runtimeError": false
}, },
"test/e2e/app-dir/unstable-io/unstable-io.test.ts": { "test/e2e/app-dir/io/io.test.ts": {
"passed": [ "passed": [
"unstable_io with cache components should make content after unstable_io() dynamic during prerender", "io with cache components should make content after io() dynamic during prerender",
"unstable_io with cache components should resolve immediately inside a \"use cache\" scope", "io with cache components should resolve immediately inside a \"use cache\" scope",
"unstable_io with cache components should work in pages router with React.use() (CC)", "io with cache components should work in pages router with React.use() (CC)",
"unstable_io with cache components should work in pages router with getServerSideProps (CC)", "io with cache components should work in pages router with getServerSideProps (CC)",
"unstable_io with cache components should work in pages router with getStaticProps (CC)", "io with cache components should work in pages router with getStaticProps (CC)",
"unstable_io without cache components should be a no-op during prerender without cache components", "io without cache components should be a no-op during prerender without cache components",
"unstable_io without cache components should work in pages router with React.use()", "io without cache components should work in pages router with React.use()",
"unstable_io without cache components should work in pages router with getServerSideProps", "io without cache components should work in pages router with getServerSideProps",
"unstable_io without cache components should work in pages router with getStaticProps" "io without cache components should work in pages router with getStaticProps"
], ],
"failed": [], "failed": [],
"pending": [], "pending": [],
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