Unverified Commit 7dedd622 authored by Andrew Clark's avatar Andrew Clark Committed by GitHub

Un-skip tests in prefetch-runtime.test.ts (#86097)

These were temporarily disabled when removed the Link level opt-in for
runtime prefetching. I fixed the tests by switching to the file-based
API.

prefetch-layout-sharing.test.ts still needs to be updated, in a similar
way.
parent a8d73c25
...@@ -2,6 +2,11 @@ import { Suspense } from 'react' ...@@ -2,6 +2,11 @@ import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared' import { cachedDelay, DebugRenderKind } from '../../../shared'
import { cacheLife } from 'next/cache' import { cacheLife } from 'next/cache'
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page() { export default async function Page() {
return ( return (
<main> <main>
......
...@@ -2,6 +2,11 @@ import { Suspense } from 'react' ...@@ -2,6 +2,11 @@ import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared' import { cachedDelay, DebugRenderKind } from '../../../shared'
import { cacheLife } from 'next/cache' import { cacheLife } from 'next/cache'
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page() { export default async function Page() {
return ( return (
<main> <main>
......
...@@ -2,6 +2,11 @@ import { Suspense } from 'react' ...@@ -2,6 +2,11 @@ import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared' import { cachedDelay, DebugRenderKind } from '../../../shared'
import { cacheLife } from 'next/cache' import { cacheLife } from 'next/cache'
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page() { export default async function Page() {
return ( return (
<main> <main>
......
...@@ -2,6 +2,11 @@ import { Suspense } from 'react' ...@@ -2,6 +2,11 @@ import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared' import { cachedDelay, DebugRenderKind } from '../../../shared'
import { cacheLife } from 'next/cache' import { cacheLife } from 'next/cache'
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page() { export default async function Page() {
return ( return (
<main> <main>
......
...@@ -2,6 +2,11 @@ import { Suspense } from 'react' ...@@ -2,6 +2,11 @@ import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared' import { cachedDelay, DebugRenderKind } from '../../../shared'
import { cacheLife } from 'next/cache' import { cacheLife } from 'next/cache'
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page() { export default async function Page() {
return ( return (
<main> <main>
......
...@@ -3,6 +3,11 @@ import { Suspense } from 'react' ...@@ -3,6 +3,11 @@ import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared' import { cachedDelay, DebugRenderKind } from '../../../shared'
import { ErrorBoundary } from '../../../../components/error-boundary' import { ErrorBoundary } from '../../../../components/error-boundary'
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page() { export default async function Page() {
return ( return (
<main> <main>
......
...@@ -8,50 +8,29 @@ export default async function Page() { ...@@ -8,50 +8,29 @@ export default async function Page() {
<h2>thrown errors</h2> <h2>thrown errors</h2>
<ul> <ul>
<li> <li>
<DebugLinkAccordion <DebugLinkAccordion href="/errors/error-after-cookies" />
href="/errors/error-after-cookies"
prefetch={true}
/>
</li> </li>
</ul> </ul>
<h2>sync IO</h2> <h2>sync IO</h2>
<ul> <ul>
<li> <li>
<DebugLinkAccordion <DebugLinkAccordion href="/errors/sync-io-after-runtime-api/cookies" />
href="/errors/sync-io-after-runtime-api/cookies"
prefetch={true}
/>
</li> </li>
<li> <li>
<DebugLinkAccordion <DebugLinkAccordion href="/errors/sync-io-after-runtime-api/headers" />
href="/errors/sync-io-after-runtime-api/headers"
prefetch={true}
/>
</li> </li>
<li> <li>
<DebugLinkAccordion <DebugLinkAccordion href="/errors/sync-io-after-runtime-api/dynamic-params/123" />
href="/errors/sync-io-after-runtime-api/dynamic-params/123"
prefetch={true}
/>
</li> </li>
<li> <li>
<DebugLinkAccordion <DebugLinkAccordion href="/errors/sync-io-after-runtime-api/search-params?foo=bar" />
href="/errors/sync-io-after-runtime-api/search-params?foo=bar"
prefetch={true}
/>
</li> </li>
<li> <li>
<DebugLinkAccordion <DebugLinkAccordion href="/errors/sync-io-after-runtime-api/private-cache" />
href="/errors/sync-io-after-runtime-api/private-cache"
prefetch={true}
/>
</li> </li>
<li> <li>
<DebugLinkAccordion <DebugLinkAccordion href="/errors/sync-io-after-runtime-api/quickly-expiring-public-cache" />
href="/errors/sync-io-after-runtime-api/quickly-expiring-public-cache"
prefetch={true}
/>
</li> </li>
</ul> </ul>
</main> </main>
......
...@@ -2,6 +2,11 @@ import { cookies } from 'next/headers' ...@@ -2,6 +2,11 @@ import { cookies } from 'next/headers'
import { Suspense } from 'react' import { Suspense } from 'react'
import { DebugRenderKind } from '../../../../shared' import { DebugRenderKind } from '../../../../shared'
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page() { export default async function Page() {
return ( return (
<main> <main>
......
...@@ -4,6 +4,11 @@ import { workUnitAsyncStorage } from 'next/dist/server/app-render/work-unit-asyn ...@@ -4,6 +4,11 @@ import { workUnitAsyncStorage } from 'next/dist/server/app-render/work-unit-asyn
type Params = { id: string } type Params = { id: string }
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page({ params }: { params: Promise<Params> }) { export default async function Page({ params }: { params: Promise<Params> }) {
return ( return (
<main> <main>
......
...@@ -2,6 +2,11 @@ import { headers } from 'next/headers' ...@@ -2,6 +2,11 @@ import { headers } from 'next/headers'
import { Suspense } from 'react' import { Suspense } from 'react'
import { DebugRenderKind } from '../../../../shared' import { DebugRenderKind } from '../../../../shared'
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page() { export default async function Page() {
return ( return (
<main> <main>
......
import { Suspense } from 'react' import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../../shared' import { cachedDelay, DebugRenderKind } from '../../../../shared'
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page() { export default async function Page() {
return ( return (
<main> <main>
......
...@@ -2,6 +2,11 @@ import { Suspense } from 'react' ...@@ -2,6 +2,11 @@ import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../../shared' import { cachedDelay, DebugRenderKind } from '../../../../shared'
import { cacheLife } from 'next/cache' import { cacheLife } from 'next/cache'
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page() { export default async function Page() {
return ( return (
<main> <main>
......
...@@ -3,6 +3,11 @@ import { DebugRenderKind } from '../../../../shared' ...@@ -3,6 +3,11 @@ import { DebugRenderKind } from '../../../../shared'
type AnySearchParams = { [key: string]: string | string[] | undefined } type AnySearchParams = { [key: string]: string | string[] | undefined }
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page({ export default async function Page({
searchParams, searchParams,
}: { }: {
......
...@@ -175,16 +175,7 @@ export default async function Page() { ...@@ -175,16 +175,7 @@ export default async function Page() {
private, short stale private, short stale
<ul> <ul>
<li> <li>
<DebugLinkAccordion <DebugLinkAccordion href="/caches/private-short-stale" />
href="/caches/private-short-stale"
prefetch={'auto'}
/>
</li>
<li>
<DebugLinkAccordion
href="/caches/private-short-stale"
prefetch={true}
/>
</li> </li>
</ul> </ul>
</li> </li>
...@@ -192,16 +183,7 @@ export default async function Page() { ...@@ -192,16 +183,7 @@ export default async function Page() {
public, short expire, long enough stale public, short expire, long enough stale
<ul> <ul>
<li> <li>
<DebugLinkAccordion <DebugLinkAccordion href="/caches/public-short-expire-long-stale" />
href="/caches/public-short-expire-long-stale"
prefetch={'auto'}
/>
</li>
<li>
<DebugLinkAccordion
href="/caches/public-short-expire-long-stale"
prefetch={true}
/>
</li> </li>
</ul> </ul>
</li> </li>
...@@ -209,16 +191,7 @@ export default async function Page() { ...@@ -209,16 +191,7 @@ export default async function Page() {
public, short expire, short stale public, short expire, short stale
<ul> <ul>
<li> <li>
<DebugLinkAccordion <DebugLinkAccordion href="/caches/public-short-expire-short-stale" />
href="/caches/public-short-expire-short-stale"
prefetch={'auto'}
/>
</li>
<li>
<DebugLinkAccordion
href="/caches/public-short-expire-short-stale"
prefetch={true}
/>
</li> </li>
</ul> </ul>
</li> </li>
...@@ -226,16 +199,7 @@ export default async function Page() { ...@@ -226,16 +199,7 @@ export default async function Page() {
public, cacheLife("seconds") public, cacheLife("seconds")
<ul> <ul>
<li> <li>
<DebugLinkAccordion <DebugLinkAccordion href="/caches/public-seconds" />
href="/caches/public-seconds"
prefetch={'auto'}
/>
</li>
<li>
<DebugLinkAccordion
href="/caches/public-seconds"
prefetch={true}
/>
</li> </li>
</ul> </ul>
</li> </li>
...@@ -243,16 +207,7 @@ export default async function Page() { ...@@ -243,16 +207,7 @@ export default async function Page() {
private, cacheLife("seconds") private, cacheLife("seconds")
<ul> <ul>
<li> <li>
<DebugLinkAccordion <DebugLinkAccordion href="/caches/private-seconds" />
href="/caches/private-seconds"
prefetch={'auto'}
/>
</li>
<li>
<DebugLinkAccordion
href="/caches/private-seconds"
prefetch={true}
/>
</li> </li>
</ul> </ul>
</li> </li>
......
...@@ -54,7 +54,7 @@ function getPrefetchKind(prefetch: LinkProps['prefetch']) { ...@@ -54,7 +54,7 @@ function getPrefetchKind(prefetch: LinkProps['prefetch']) {
case 'auto': case 'auto':
return 'auto' return 'auto'
case true: case true:
return 'full' return 'true'
default: default:
prefetch satisfies never prefetch satisfies never
} }
......
...@@ -712,8 +712,7 @@ describe('runtime prefetching', () => { ...@@ -712,8 +712,7 @@ describe('runtime prefetching', () => {
) )
}) })
// TODO (runtime-prefetching): link-level opt-in has been removed. These tests need to be updated to use the segment configuration. describe('cache stale time handling', () => {
describe.skip('cache stale time handling', () => {
it.each([ it.each([
{ {
// If a cache has an expiration time under 5min (DYNAMIC_EXPIRE), we omit it from static prerenders. // If a cache has an expiration time under 5min (DYNAMIC_EXPIRE), we omit it from static prerenders.
...@@ -750,31 +749,16 @@ describe('runtime prefetching', () => { ...@@ -750,31 +749,16 @@ describe('runtime prefetching', () => {
const DYNAMICALLY_PREFETCHABLE_CONTENT = 'Short-lived cached content' const DYNAMICALLY_PREFETCHABLE_CONTENT = 'Short-lived cached content'
// Reveal the link to trigger a static prefetch // Reveal the link to trigger a runtime prefetch
await act(async () => { await act(async () => {
const linkToggle = await browser.elementByCss( const linkToggle = await browser.elementByCss(
`input[data-prefetch="auto"][data-link-accordion="${path}"]` `input[data-link-accordion="${path}"]`
) )
await linkToggle.click() await linkToggle.click()
}, [ }, [
// Should include the static shell
{ {
includes: staticContent, includes: staticContent,
}, },
// Should not include the short-lived cache
{
includes: DYNAMICALLY_PREFETCHABLE_CONTENT,
block: 'reject',
},
])
// Reveal the link to trigger a runtime prefetch
await act(async () => {
const linkToggle = await browser.elementByCss(
`input[data-prefetch="runtime"][data-link-accordion="${path}"]`
)
await linkToggle.click()
}, [
// Should include the short-lived cache // Should include the short-lived cache
{ {
includes: DYNAMICALLY_PREFETCHABLE_CONTENT, includes: DYNAMICALLY_PREFETCHABLE_CONTENT,
...@@ -806,32 +790,10 @@ describe('runtime prefetching', () => { ...@@ -806,32 +790,10 @@ describe('runtime prefetching', () => {
const STATIC_CONTENT = 'This page uses a short-lived public cache' const STATIC_CONTENT = 'This page uses a short-lived public cache'
const DYNAMIC_CONTENT = 'Short-lived cached content' const DYNAMIC_CONTENT = 'Short-lived cached content'
// Reveal the link to trigger a static prefetch
await act(async () => {
const linkToggle = await browser.elementByCss(
`input[data-prefetch="auto"][data-link-accordion="/caches/public-short-expire-short-stale"]`
)
await linkToggle.click()
}, [
// Should include the static shell
{
includes: STATIC_CONTENT,
},
// Should not include the short-lived cache
// (We set the `expire` value to be under 5min, so it will be excluded from prerenders)
{
includes: DYNAMIC_CONTENT,
block: 'reject',
},
])
// Reveal the link to trigger a runtime prefetch. // Reveal the link to trigger a runtime prefetch.
// It'll essentially be the same as the static prefetch, because the only dynamic hole
// will be omitted from both.
// (NOTE: in the future, we might prevent scenarios like this via `generatePrefetch`)
await act(async () => { await act(async () => {
const linkToggle = await browser.elementByCss( const linkToggle = await browser.elementByCss(
`input[data-prefetch="runtime"][data-link-accordion="/caches/public-short-expire-short-stale"]` `input[data-link-accordion="/caches/public-short-expire-short-stale"]`
) )
await linkToggle.click() await linkToggle.click()
}, [ }, [
...@@ -888,29 +850,10 @@ describe('runtime prefetching', () => { ...@@ -888,29 +850,10 @@ describe('runtime prefetching', () => {
const STATIC_CONTENT = 'This page uses a short-lived private cache' const STATIC_CONTENT = 'This page uses a short-lived private cache'
const DYNAMIC_CONTENT = 'Short-lived cached content' const DYNAMIC_CONTENT = 'Short-lived cached content'
// Reveal the link to trigger a static prefetch
await act(async () => {
const linkToggle = await browser.elementByCss(
`input[data-prefetch="auto"][data-link-accordion="/caches/private-short-stale"]`
)
await linkToggle.click()
}, [
// Should include the static shell
{
includes: STATIC_CONTENT,
},
// Should not include the short-lived cache
// (We set the `expire` value to be under 5min, so it will be excluded from prerenders)
{
includes: DYNAMIC_CONTENT,
block: 'reject',
},
])
// Reveal the link to trigger a runtime prefetch // Reveal the link to trigger a runtime prefetch
await act(async () => { await act(async () => {
const linkToggle = await browser.elementByCss( const linkToggle = await browser.elementByCss(
`input[data-prefetch="runtime"][data-link-accordion="/caches/private-short-stale"]` `input[data-link-accordion="/caches/private-short-stale"]`
) )
await linkToggle.click() await linkToggle.click()
}, [ }, [
...@@ -956,12 +899,12 @@ describe('runtime prefetching', () => { ...@@ -956,12 +899,12 @@ describe('runtime prefetching', () => {
// Try navigating again. The cache is private, so we should see a different timestamp // Try navigating again. The cache is private, so we should see a different timestamp
await browser.back() await browser.back()
// Reveal the link again. The prefetch should be cached, so we shouldn't see any requests // Hover the link again. The prefetch should be cached, so we shouldn't see any requests
await act(async () => { await act(async () => {
const linkToggle = await browser.elementByCss( const linkToggle = await browser.elementByCss(
`input[data-link-accordion="/caches/private-short-stale"]` `input[data-link-accordion="/caches/private-short-stale"]`
) )
await linkToggle.click() await linkToggle.hover()
}, 'no-requests') }, 'no-requests')
// Navigate to the page again // Navigate to the page again
...@@ -994,8 +937,7 @@ describe('runtime prefetching', () => { ...@@ -994,8 +937,7 @@ describe('runtime prefetching', () => {
}) })
}) })
// TODO (runtime-prefetching): link-level opt-in has been removed. These tests need to be updated to use the segment configuration. describe('errors', () => {
describe.skip('errors', () => {
it.each([ it.each([
{ {
description: 'when sync IO is used after awaiting cookies()', description: 'when sync IO is used after awaiting cookies()',
...@@ -1005,17 +947,10 @@ describe('runtime prefetching', () => { ...@@ -1005,17 +947,10 @@ describe('runtime prefetching', () => {
description: 'when sync IO is used after awaiting headers()', description: 'when sync IO is used after awaiting headers()',
path: '/errors/sync-io-after-runtime-api/headers', path: '/errors/sync-io-after-runtime-api/headers',
}, },
// TODO(dynamic-ppr): {
// A tree prefetch for "/dynamic-params/123" currently causes it to be prerendered on demand, description: 'when sync IO is used after awaiting dynamic params',
// meaning that we end up statically prerendering it with all the params included. path: '/errors/sync-io-after-runtime-api/dynamic-params/123',
// Because of this, `await params` doesn't hang in the static prerender, so we hit the sync IO error behind it. },
// This error somehow causes an infinite redirect loop between two different `?_rsc` URLs.
// Investigate this separately or wait until we start always using fallback params for route trees.
//
// {
// description: 'when sync IO is used after awaiting dynamic params',
// path: '/errors/sync-io-after-runtime-api/dynamic-params/123',
// },
{ {
description: 'when sync IO is used after awaiting searchParams', description: 'when sync IO is used after awaiting searchParams',
path: '/errors/sync-io-after-runtime-api/search-params?foo=bar', path: '/errors/sync-io-after-runtime-api/search-params?foo=bar',
...@@ -1052,7 +987,7 @@ describe('runtime prefetching', () => { ...@@ -1052,7 +987,7 @@ describe('runtime prefetching', () => {
// Reveal the link to trigger a runtime prefetch // Reveal the link to trigger a runtime prefetch
await act(async () => { await act(async () => {
const linkToggle = await browser.elementByCss( const linkToggle = await browser.elementByCss(
`input[data-prefetch="runtime"][data-link-accordion="${path}"]` `input[data-link-accordion="${path}"]`
) )
await linkToggle.click() await linkToggle.click()
}, [ }, [
...@@ -1119,7 +1054,7 @@ describe('runtime prefetching', () => { ...@@ -1119,7 +1054,7 @@ describe('runtime prefetching', () => {
// Reveal the link to trigger a runtime prefetch // Reveal the link to trigger a runtime prefetch
await act(async () => { await act(async () => {
const linkToggle = await browser.elementByCss( const linkToggle = await browser.elementByCss(
`input[data-prefetch="runtime"][data-link-accordion="/errors/error-after-cookies"]` `input[data-link-accordion="/errors/error-after-cookies"]`
) )
await linkToggle.click() await linkToggle.click()
}, [ }, [
......
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