Unverified Commit be2104ae authored by Janka Uryga's avatar Janka Uryga Committed by GitHub

test: Remove unnecessary dynamic timestamp from instant-validation root layouts (#95105)

Extracted from #94595 . The root layout includes a timestamp that we use
to check if the root layout changed during a navigation, but it was
unnecessarily using `await connection(); Date.now()` when a
`performance.now()`would be enough. Changing it to not introduce a
random dynamic hole which could affect validation in some way.
  
This change revealed that some client component tests were implicitly
relying on the dynamic timestamp component as a workaround for NAR-800 .
I've added a workaround dynamic component to each of the relevant tests,
those can be removed when we fix the bug.
parent b0dde9cf
import { connection } from 'next/server' import { ReactNode } from 'react'
import { ReactNode, Suspense } from 'react' import { RootLayoutTimestamp } from '../shared'
export default function RootLayout({ children }: { children: ReactNode }) { export default function RootLayout({ children }: { children: ReactNode }) {
return ( return (
...@@ -16,17 +16,8 @@ export default function RootLayout({ children }: { children: ReactNode }) { ...@@ -16,17 +16,8 @@ export default function RootLayout({ children }: { children: ReactNode }) {
function Header() { function Header() {
return ( return (
<header> <header>
<a href="/">Home</a>{' '} <a href="/">Home</a>
<Suspense fallback="..."> <RootLayoutTimestamp />
<div id="root-layout-timestamp">
<Now />
</div>
</Suspense>
</header> </header>
) )
} }
async function Now() {
await connection()
return Date.now()
}
import { connection } from 'next/server'
import { cacheLife } from 'next/cache' import { cacheLife } from 'next/cache'
import Link from 'next/link' import Link from 'next/link'
import { Suspense } from 'react'
import { setTimeout } from 'timers/promises' import { setTimeout } from 'timers/promises'
export function HackilyPreventFullyStaticServerPrerender() {
return <Suspense>{connection().then(() => null)}</Suspense>
}
export function RootLayoutTimestamp() {
const timestamp = performance.timeOrigin + performance.now()
return <div id="root-layout-timestamp">{timestamp}</div>
}
export function DebugLinks({ href }: { href: string }) { export function DebugLinks({ href }: { href: string }) {
return ( return (
<span> <span>
......
import { connection } from 'next/server'
import { ReactNode, Suspense } from 'react' import { ReactNode, Suspense } from 'react'
import { RootLayoutTimestamp } from '../shared'
export default function RootLayout({ children }: { children: ReactNode }) { export default function RootLayout({ children }: { children: ReactNode }) {
return ( return (
...@@ -21,17 +21,8 @@ export default function RootLayout({ children }: { children: ReactNode }) { ...@@ -21,17 +21,8 @@ export default function RootLayout({ children }: { children: ReactNode }) {
function Header() { function Header() {
return ( return (
<header> <header>
<a href="/">Home</a>{' '} <a href="/">Home</a>
<Suspense fallback="..."> <RootLayoutTimestamp />
<div id="root-layout-timestamp">
<Now />
</div>
</Suspense>
</header> </header>
) )
} }
async function Now() {
await connection()
return Date.now()
}
import type { ReactNode } from 'react' import type { ReactNode } from 'react'
import { FetchesClientData } from './client' import { FetchesClientData } from './client'
import { DataCacheProvider } from '../../../../client-data-fetching-lib/server' import { DataCacheProvider } from '../../../../client-data-fetching-lib/server'
import { HackilyPreventFullyStaticServerPrerender } from '../../../shared'
// Make sure that the holes from this layout aren't factored in for validation // Make sure that the holes from this layout aren't factored in for validation
// (otherwise, we'd check a navigation into it from the root layout and fail) // (otherwise, we'd check a navigation into it from the root layout and fail)
...@@ -8,14 +9,18 @@ export const instant = false ...@@ -8,14 +9,18 @@ export const instant = false
export default function Layout({ children }: { children: ReactNode }) { export default function Layout({ children }: { children: ReactNode }) {
return ( return (
<DataCacheProvider> <>
<div> <HackilyPreventFullyStaticServerPrerender />
<p> <DataCacheProvider>
This layout renders a client component that suspends in SSR and blocks <div>
the children. This prevents us from validating the page below. <p>
</p> This layout renders a client component that suspends in SSR and
<FetchesClientData>{children}</FetchesClientData> blocks the children. This prevents us from validating the page
</div> below.
</DataCacheProvider> </p>
<FetchesClientData>{children}</FetchesClientData>
</div>
</DataCacheProvider>
</>
) )
} }
import type { ReactNode } from 'react' import type { ReactNode } from 'react'
import { ShouldNotSuspendDuringValidation } from './client' import { ShouldNotSuspendDuringValidation } from './client'
import { HackilyPreventFullyStaticServerPrerender } from '../../../../../shared'
// Make sure that the holes from this layout aren't factored in for validation // Make sure that the holes from this layout aren't factored in for validation
// (otherwise, we'd check a navigation into it from the root layout and fail) // (otherwise, we'd check a navigation into it from the root layout and fail)
...@@ -8,6 +9,7 @@ export const instant = false ...@@ -8,6 +9,7 @@ export const instant = false
export default function Layout({ children }: { children: ReactNode }) { export default function Layout({ children }: { children: ReactNode }) {
return ( return (
<> <>
<HackilyPreventFullyStaticServerPrerender />
<div> <div>
<p> <p>
This layout renders a client component that accesses usePathname() This layout renders a client component that accesses usePathname()
......
import type { ReactNode } from 'react' import type { ReactNode } from 'react'
import { ShouldNotSuspendDuringValidation } from './client' import { ShouldNotSuspendDuringValidation } from './client'
import { HackilyPreventFullyStaticServerPrerender } from '../../../../shared'
// Make sure that the holes from this layout aren't factored in for validation // Make sure that the holes from this layout aren't factored in for validation
// (otherwise, we'd check a navigation into it from the root layout and fail) // (otherwise, we'd check a navigation into it from the root layout and fail)
...@@ -8,6 +9,7 @@ export const instant = false ...@@ -8,6 +9,7 @@ export const instant = false
export default function Layout({ children }: { children: ReactNode }) { export default function Layout({ children }: { children: ReactNode }) {
return ( return (
<> <>
<HackilyPreventFullyStaticServerPrerender />
<div> <div>
<p> <p>
This layout renders a client component that accesses This layout renders a client component that accesses
......
import type { ReactNode } from 'react' import type { ReactNode } from 'react'
import { SyncIOInClient } from './client' import { SyncIOInClient } from './client'
import { HackilyPreventFullyStaticServerPrerender } from '../../../../shared'
// Make sure that the holes from this layout aren't factored in for validation // Make sure that the holes from this layout aren't factored in for validation
// (otherwise, we'd check a navigation into it from the root layout and fail) // (otherwise, we'd check a navigation into it from the root layout and fail)
...@@ -8,6 +9,7 @@ export const instant = false ...@@ -8,6 +9,7 @@ export const instant = false
export default function Layout({ children }: { children: ReactNode }) { export default function Layout({ children }: { children: ReactNode }) {
return ( return (
<> <>
<HackilyPreventFullyStaticServerPrerender />
<div> <div>
<p> <p>
This layout renders a client component that uses sync IO. We're This layout renders a client component that uses sync IO. We're
......
import type { ReactNode } from 'react' import type { ReactNode } from 'react'
import { FetchesClientData } from './client' import { FetchesClientData } from './client'
import { DataCacheProvider } from '../../../../client-data-fetching-lib/server' import { DataCacheProvider } from '../../../../client-data-fetching-lib/server'
import { HackilyPreventFullyStaticServerPrerender } from '../../../shared'
// Make sure that the holes from this layout aren't factored in for validation // Make sure that the holes from this layout aren't factored in for validation
// (otherwise, we'd check a navigation into it from the root layout and fail) // (otherwise, we'd check a navigation into it from the root layout and fail)
...@@ -8,16 +9,19 @@ export const instant = false ...@@ -8,16 +9,19 @@ export const instant = false
export default function Layout({ children }: { children: ReactNode }) { export default function Layout({ children }: { children: ReactNode }) {
return ( return (
<DataCacheProvider> <>
<div> <HackilyPreventFullyStaticServerPrerender />
<p> <DataCacheProvider>
This layout renders a client component that suspends in SSR, but it <div>
doesn't not block the children, so we can still validate them. <p>
</p> This layout renders a client component that suspends in SSR, but it
<FetchesClientData /> doesn't not block the children, so we can still validate them.
</div> </p>
<hr /> <FetchesClientData />
{children} </div>
</DataCacheProvider> <hr />
{children}
</DataCacheProvider>
</>
) )
} }
...@@ -1696,7 +1696,7 @@ describe('instant validation', () => { ...@@ -1696,7 +1696,7 @@ describe('instant validation', () => {
| ^", | ^",
"stack": [ "stack": [
"FetchesClientData app/suspense-in-root/static/invalid-client-data-blocks-validation/client.tsx (12:19)", "FetchesClientData app/suspense-in-root/static/invalid-client-data-blocks-validation/client.tsx (12:19)",
"Layout app/suspense-in-root/static/invalid-client-data-blocks-validation/layout.tsx (17:9)", "Layout app/suspense-in-root/static/invalid-client-data-blocks-validation/layout.tsx (21:11)",
], ],
} }
`) `)
......
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