mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
Implements instant validation for `partialPrefetching`. In this mode, `<Link>` prefetches an App Shell, which cannot access link data, and we need to warn for that. The changes in `instant-validation.tsx` are relatively simple: for an App Shell, we simply use `ShellRuntime` for all the new segments. We might also force them into `Runtime` for the purposes of discriminating dynamic holes. If a hole is present in `ShellRuntime` but disappears in `Runtime`, then we know it's caused by **link data** (as opposed to runtime or dynamic data). I've added some new error messages for this case. Note that the implementation here is incomplete: it uses the chunks from the dev render, which resolves static params in the `Static` stage. We use `ShellRuntime` for validating the App Shell, so as a result, static params are incorrectly included in it and don't trigger link data errors. This will be implemented in a follow-up. Note: It seems like we have some pre-existing bug in build validation where `fallbackParams` aren't populated, so params resolve statically when they shouldn't. I've marked two tests with `// TODO(app-shells): missing fallback params in build validation` so we can follow up and fix those.
40 lines
908 B
TypeScript
40 lines
908 B
TypeScript
import { Instant } from 'next'
|
|
import { cookies } from 'next/headers'
|
|
|
|
export const instant: Instant = {
|
|
level: 'experimental-error',
|
|
unstable_samples: [{ cookies: [] }],
|
|
}
|
|
|
|
export const prefetch = 'partial'
|
|
|
|
export default async function Page() {
|
|
return (
|
|
<main>
|
|
<p>
|
|
This page has an unguarded session data access. This is allowed in a
|
|
shell, so it should pass validation. It does not contain any link or
|
|
dynamic data, so it is completely prefetchable.
|
|
</p>
|
|
<SessionData1 />
|
|
<SessionData2 />
|
|
</main>
|
|
)
|
|
}
|
|
|
|
async function SessionData1() {
|
|
await cookies()
|
|
return <div>Session data 1 (cookies)</div>
|
|
}
|
|
|
|
async function SessionData2() {
|
|
await privateCache()
|
|
return <div>Session data 2 (private cache)</div>
|
|
}
|
|
|
|
async function privateCache() {
|
|
'use cache: private'
|
|
await new Promise((resolve) => setTimeout(resolve))
|
|
return Date.now()
|
|
}
|