Files
Benjamin WoodruffandGitHub eaf6ca4457 fix(test/e2e/prerender): Remove race condition in test (#77222)
Fixed `setTimeout`s in tests are bad for flakiness, as they introduce
potential race conditions.

https://vercel.slack.com/archives/C07UCHRBWGK/p1742074798403739

Instead of using a fixed timeout, check for a special marker file in a
loop every 100ms.
2025-03-18 09:22:12 +01:00

51 lines
1.0 KiB
JavaScript

import React from 'react'
import Link from 'next/link'
import { useRouter } from 'next/router'
import fs from 'node:fs/promises'
export async function getStaticPaths() {
return {
paths: [],
fallback: true,
}
}
export async function getStaticProps({ params }) {
while (true) {
try {
await fs.stat('resolve-static-props')
break
} catch (e) {}
await new Promise((resolve) => setTimeout(resolve, 100))
}
return {
props: {
params,
hello: 'world',
post: params.slug,
random: Math.random(),
time: (await import('perf_hooks')).performance.now(),
},
revalidate: 1,
}
}
export default ({ post, time, params }) => {
if (useRouter().isFallback) {
return <p>hi fallback</p>
}
return (
<>
<p>Post: {post}</p>
<span>time: {time}</span>
<div id="params">{JSON.stringify(params)}</div>
<div id="query">{JSON.stringify(useRouter().query)}</div>
<Link href="/" id="home">
to home
</Link>
</>
)
}