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'
import { cachedDelay, DebugRenderKind } from '../../../shared'
import { cacheLife } from 'next/cache'
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page() {
return (
<main>
......
......@@ -2,6 +2,11 @@ import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared'
import { cacheLife } from 'next/cache'
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page() {
return (
<main>
......
......@@ -2,6 +2,11 @@ import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared'
import { cacheLife } from 'next/cache'
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page() {
return (
<main>
......
......@@ -2,6 +2,11 @@ import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared'
import { cacheLife } from 'next/cache'
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page() {
return (
<main>
......
......@@ -2,6 +2,11 @@ import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared'
import { cacheLife } from 'next/cache'
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page() {
return (
<main>
......
......@@ -3,6 +3,11 @@ import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../shared'
import { ErrorBoundary } from '../../../../components/error-boundary'
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page() {
return (
<main>
......
......@@ -8,50 +8,29 @@ export default async function Page() {
<h2>thrown errors</h2>
<ul>
<li>
<DebugLinkAccordion
href="/errors/error-after-cookies"
prefetch={true}
/>
<DebugLinkAccordion href="/errors/error-after-cookies" />
</li>
</ul>
<h2>sync IO</h2>
<ul>
<li>
<DebugLinkAccordion
href="/errors/sync-io-after-runtime-api/cookies"
prefetch={true}
/>
<DebugLinkAccordion href="/errors/sync-io-after-runtime-api/cookies" />
</li>
<li>
<DebugLinkAccordion
href="/errors/sync-io-after-runtime-api/headers"
prefetch={true}
/>
<DebugLinkAccordion href="/errors/sync-io-after-runtime-api/headers" />
</li>
<li>
<DebugLinkAccordion
href="/errors/sync-io-after-runtime-api/dynamic-params/123"
prefetch={true}
/>
<DebugLinkAccordion href="/errors/sync-io-after-runtime-api/dynamic-params/123" />
</li>
<li>
<DebugLinkAccordion
href="/errors/sync-io-after-runtime-api/search-params?foo=bar"
prefetch={true}
/>
<DebugLinkAccordion href="/errors/sync-io-after-runtime-api/search-params?foo=bar" />
</li>
<li>
<DebugLinkAccordion
href="/errors/sync-io-after-runtime-api/private-cache"
prefetch={true}
/>
<DebugLinkAccordion href="/errors/sync-io-after-runtime-api/private-cache" />
</li>
<li>
<DebugLinkAccordion
href="/errors/sync-io-after-runtime-api/quickly-expiring-public-cache"
prefetch={true}
/>
<DebugLinkAccordion href="/errors/sync-io-after-runtime-api/quickly-expiring-public-cache" />
</li>
</ul>
</main>
......
......@@ -2,6 +2,11 @@ import { cookies } from 'next/headers'
import { Suspense } from 'react'
import { DebugRenderKind } from '../../../../shared'
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page() {
return (
<main>
......
......@@ -4,6 +4,11 @@ import { workUnitAsyncStorage } from 'next/dist/server/app-render/work-unit-asyn
type Params = { id: string }
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page({ params }: { params: Promise<Params> }) {
return (
<main>
......
......@@ -2,6 +2,11 @@ import { headers } from 'next/headers'
import { Suspense } from 'react'
import { DebugRenderKind } from '../../../../shared'
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page() {
return (
<main>
......
import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../../shared'
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page() {
return (
<main>
......
......@@ -2,6 +2,11 @@ import { Suspense } from 'react'
import { cachedDelay, DebugRenderKind } from '../../../../shared'
import { cacheLife } from 'next/cache'
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page() {
return (
<main>
......
......@@ -3,6 +3,11 @@ import { DebugRenderKind } from '../../../../shared'
type AnySearchParams = { [key: string]: string | string[] | undefined }
export const unstable_prefetch = {
mode: 'runtime',
samples: [{ cookies: [] }],
}
export default async function Page({
searchParams,
}: {
......
......@@ -175,16 +175,7 @@ export default async function Page() {
private, short stale
<ul>
<li>
<DebugLinkAccordion
href="/caches/private-short-stale"
prefetch={'auto'}
/>
</li>
<li>
<DebugLinkAccordion
href="/caches/private-short-stale"
prefetch={true}
/>
<DebugLinkAccordion href="/caches/private-short-stale" />
</li>
</ul>
</li>
......@@ -192,16 +183,7 @@ export default async function Page() {
public, short expire, long enough stale
<ul>
<li>
<DebugLinkAccordion
href="/caches/public-short-expire-long-stale"
prefetch={'auto'}
/>
</li>
<li>
<DebugLinkAccordion
href="/caches/public-short-expire-long-stale"
prefetch={true}
/>
<DebugLinkAccordion href="/caches/public-short-expire-long-stale" />
</li>
</ul>
</li>
......@@ -209,16 +191,7 @@ export default async function Page() {
public, short expire, short stale
<ul>
<li>
<DebugLinkAccordion
href="/caches/public-short-expire-short-stale"
prefetch={'auto'}
/>
</li>
<li>
<DebugLinkAccordion
href="/caches/public-short-expire-short-stale"
prefetch={true}
/>
<DebugLinkAccordion href="/caches/public-short-expire-short-stale" />
</li>
</ul>
</li>
......@@ -226,16 +199,7 @@ export default async function Page() {
public, cacheLife("seconds")
<ul>
<li>
<DebugLinkAccordion
href="/caches/public-seconds"
prefetch={'auto'}
/>
</li>
<li>
<DebugLinkAccordion
href="/caches/public-seconds"
prefetch={true}
/>
<DebugLinkAccordion href="/caches/public-seconds" />
</li>
</ul>
</li>
......@@ -243,16 +207,7 @@ export default async function Page() {
private, cacheLife("seconds")
<ul>
<li>
<DebugLinkAccordion
href="/caches/private-seconds"
prefetch={'auto'}
/>
</li>
<li>
<DebugLinkAccordion
href="/caches/private-seconds"
prefetch={true}
/>
<DebugLinkAccordion href="/caches/private-seconds" />
</li>
</ul>
</li>
......
......@@ -54,7 +54,7 @@ function getPrefetchKind(prefetch: LinkProps['prefetch']) {
case 'auto':
return 'auto'
case true:
return 'full'
return 'true'
default:
prefetch satisfies never
}
......
......@@ -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.skip('cache stale time handling', () => {
describe('cache stale time handling', () => {
it.each([
{
// If a cache has an expiration time under 5min (DYNAMIC_EXPIRE), we omit it from static prerenders.
......@@ -750,31 +749,16 @@ describe('runtime prefetching', () => {
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 () => {
const linkToggle = await browser.elementByCss(
`input[data-prefetch="auto"][data-link-accordion="${path}"]`
`input[data-link-accordion="${path}"]`
)
await linkToggle.click()
}, [
// Should include the static shell
{
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
{
includes: DYNAMICALLY_PREFETCHABLE_CONTENT,
......@@ -806,32 +790,10 @@ describe('runtime prefetching', () => {
const STATIC_CONTENT = 'This page uses a short-lived public cache'
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.
// 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 () => {
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()
}, [
......@@ -888,29 +850,10 @@ describe('runtime prefetching', () => {
const STATIC_CONTENT = 'This page uses a short-lived private cache'
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
await act(async () => {
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()
}, [
......@@ -956,12 +899,12 @@ describe('runtime prefetching', () => {
// Try navigating again. The cache is private, so we should see a different timestamp
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 () => {
const linkToggle = await browser.elementByCss(
`input[data-link-accordion="/caches/private-short-stale"]`
)
await linkToggle.click()
await linkToggle.hover()
}, 'no-requests')
// Navigate to the page again
......@@ -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.skip('errors', () => {
describe('errors', () => {
it.each([
{
description: 'when sync IO is used after awaiting cookies()',
......@@ -1005,17 +947,10 @@ describe('runtime prefetching', () => {
description: 'when sync IO is used after awaiting 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,
// meaning that we end up statically prerendering it with all the params included.
// 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 dynamic params',
path: '/errors/sync-io-after-runtime-api/dynamic-params/123',
},
{
description: 'when sync IO is used after awaiting searchParams',
path: '/errors/sync-io-after-runtime-api/search-params?foo=bar',
......@@ -1052,7 +987,7 @@ describe('runtime prefetching', () => {
// Reveal the link to trigger a runtime prefetch
await act(async () => {
const linkToggle = await browser.elementByCss(
`input[data-prefetch="runtime"][data-link-accordion="${path}"]`
`input[data-link-accordion="${path}"]`
)
await linkToggle.click()
}, [
......@@ -1119,7 +1054,7 @@ describe('runtime prefetching', () => {
// Reveal the link to trigger a runtime prefetch
await act(async () => {
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()
}, [
......
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