Commit 4a3c5198 authored by Janka Uryga's avatar Janka Uryga

some working wip

parent cdd12b21
...@@ -296,14 +296,19 @@ export function abortOnSynchronousPlatformIOAccess( ...@@ -296,14 +296,19 @@ export function abortOnSynchronousPlatformIOAccess(
} }
export function trackSynchronousPlatformIOAccessInDev( export function trackSynchronousPlatformIOAccessInDev(
requestStore: RequestStore requestStore: RequestStore,
expression: string,
type: string
): void { ): void {
// We don't actually have a controller to abort but we do the semantic equivalent by // We don't actually have a controller to abort but we do the semantic equivalent by
// advancing the request store out of the prerender stage // advancing the request store out of the prerender stage
if (requestStore.stagedRendering) { if (requestStore.stagedRendering) {
// TODO: error for sync IO in the runtime stage // TODO: error for sync IO in the runtime stage
// (which is not currently covered by the validation render in `spawnDynamicValidationInDev`) // (which is not currently covered by the validation render in `spawnDynamicValidationInDev`)
requestStore.stagedRendering.advanceStage(RenderStage.Dynamic) console.trace(
`sync IO error (type: ${type}): ${expression}, NOT advancing to dynamic stage (fixme)`
)
// requestStore.stagedRendering.advanceStage(RenderStage.Dynamic)
} }
} }
...@@ -721,6 +726,11 @@ const hasViewportRegex = new RegExp( ...@@ -721,6 +726,11 @@ const hasViewportRegex = new RegExp(
) )
const hasOutletRegex = new RegExp(`\\n\\s+at ${OUTLET_BOUNDARY_NAME}[\\n\\s]`) const hasOutletRegex = new RegExp(`\\n\\s+at ${OUTLET_BOUNDARY_NAME}[\\n\\s]`)
export enum DynamicErrorKind {
SyncDynamic,
MissingSuspense,
}
export function trackAllowedDynamicAccess( export function trackAllowedDynamicAccess(
workStore: WorkStore, workStore: WorkStore,
componentStack: string, componentStack: string,
...@@ -729,13 +739,13 @@ export function trackAllowedDynamicAccess( ...@@ -729,13 +739,13 @@ export function trackAllowedDynamicAccess(
) { ) {
if (hasOutletRegex.test(componentStack)) { if (hasOutletRegex.test(componentStack)) {
// We don't need to track that this is dynamic. It is only so when something else is also dynamic. // We don't need to track that this is dynamic. It is only so when something else is also dynamic.
return return null
} else if (hasMetadataRegex.test(componentStack)) { } else if (hasMetadataRegex.test(componentStack)) {
dynamicValidation.hasDynamicMetadata = true dynamicValidation.hasDynamicMetadata = true
return return null
} else if (hasViewportRegex.test(componentStack)) { } else if (hasViewportRegex.test(componentStack)) {
dynamicValidation.hasDynamicViewport = true dynamicValidation.hasDynamicViewport = true
return return null
} else if ( } else if (
hasSuspenseBeforeRootLayoutWithoutBodyOrImplicitBodyRegex.test( hasSuspenseBeforeRootLayoutWithoutBodyOrImplicitBodyRegex.test(
componentStack componentStack
...@@ -746,23 +756,23 @@ export function trackAllowedDynamicAccess( ...@@ -746,23 +756,23 @@ export function trackAllowedDynamicAccess(
// is an explicit signal from the user that they acknowledge the empty shell and want dynamic rendering. // is an explicit signal from the user that they acknowledge the empty shell and want dynamic rendering.
dynamicValidation.hasAllowedDynamic = true dynamicValidation.hasAllowedDynamic = true
dynamicValidation.hasSuspenseAboveBody = true dynamicValidation.hasSuspenseAboveBody = true
return return null
} else if (hasSuspenseRegex.test(componentStack)) { } else if (hasSuspenseRegex.test(componentStack)) {
// this error had a Suspense boundary above it so we don't need to report it as a source // this error had a Suspense boundary above it so we don't need to report it as a source
// of disallowed // of disallowed
dynamicValidation.hasAllowedDynamic = true dynamicValidation.hasAllowedDynamic = true
return return null
} else if (clientDynamic.syncDynamicErrorWithStack) { } else if (clientDynamic.syncDynamicErrorWithStack) {
// This task was the task that called the sync error. // This task was the task that called the sync error.
dynamicValidation.dynamicErrors.push( dynamicValidation.dynamicErrors.push(
clientDynamic.syncDynamicErrorWithStack clientDynamic.syncDynamicErrorWithStack
) )
return return DynamicErrorKind.SyncDynamic
} else { } else {
const message = `Route "${workStore.route}": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense` const message = `Route "${workStore.route}": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it. See more info: https://nextjs.org/docs/messages/next-prerender-missing-suspense`
const error = createErrorWithComponentOrOwnerStack(message, componentStack) const error = createErrorWithComponentOrOwnerStack(message, componentStack)
dynamicValidation.dynamicErrors.push(error) dynamicValidation.dynamicErrors.push(error)
return return DynamicErrorKind.MissingSuspense
} }
} }
......
...@@ -36,6 +36,7 @@ export class StagedRenderingController { ...@@ -36,6 +36,7 @@ export class StagedRenderingController {
} }
advanceStage(stage: NonStaticRenderStage) { advanceStage(stage: NonStaticRenderStage) {
console.log('controller :: advancing stage', this.currentStage, '->', stage)
// If we're already at the target stage or beyond, do nothing. // If we're already at the target stage or beyond, do nothing.
// (this can happen e.g. if sync IO advanced us to the dynamic stage) // (this can happen e.g. if sync IO advanced us to the dynamic stage)
if (this.currentStage >= stage) { if (this.currentStage >= stage) {
...@@ -110,7 +111,11 @@ function makeDevtoolsIOPromiseFromIOTrigger<T>( ...@@ -110,7 +111,11 @@ function makeDevtoolsIOPromiseFromIOTrigger<T>(
// In particular, it should shadow any inner IO that resolved/rejected the promise // In particular, it should shadow any inner IO that resolved/rejected the promise
// (in case of staged rendering, this will be the `setTimeout` that triggers the relevant stage) // (in case of staged rendering, this will be the `setTimeout` that triggers the relevant stage)
const promise = new Promise<T>((resolve, reject) => { const promise = new Promise<T>((resolve, reject) => {
ioTrigger.then(resolve.bind(null, resolvedValue), reject) // ioTrigger.then(resolve.bind(null, resolvedValue), reject)
ioTrigger.then(() => {
console.log('resolving -', displayName)
resolve(resolvedValue)
}, reject)
}) })
if (displayName !== undefined) { if (displayName !== undefined) {
// @ts-expect-error // @ts-expect-error
......
...@@ -87,7 +87,7 @@ export function io(expression: string, type: ApiType) { ...@@ -87,7 +87,7 @@ export function io(expression: string, type: ApiType) {
} }
case 'request': case 'request':
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
trackSynchronousPlatformIOAccessInDev(workUnitStore) trackSynchronousPlatformIOAccessInDev(workUnitStore, expression, type)
} }
break break
case 'prerender-ppr': case 'prerender-ppr':
......
export default function Root({ children }: { children: React.ReactNode }) {
return (
<html>
<body /*style={{ backgroundColor: randomColor() }}*/>{children}</body>
</html>
)
}
// const randomColor = () => {
// const [r, g, b] = exitAls(() => [Math.random(), Math.random(), Math.random()])
// const color = (n: number) => 127 + Math.floor(64 * n)
// return `rgb(${color(r)}, ${color(g)}, ${color(b)})`
// }
// const exitAls = require('node:async_hooks').AsyncLocalStorage.snapshot()
import { cookies } from 'next/headers'
import { connection } from 'next/server'
import { Suspense } from 'react'
export default async function Page() {
console.log('Page')
return (
<main>
<h1>repro</h1>
{/* <Suspense fallback={<div>Loading...</div>}> */}
<Child />
{/* </Suspense> */}
{/* <Suspense fallback={<div>Loading...</div>}> */}
<Child2 />
{/* </Suspense> */}
</main>
)
}
async function Child() {
console.log('Child - before cookies')
await cookies()
console.log('Child - after cookies')
return <Nested />
}
async function Child2() {
console.log('Child2 - before connection')
await connection()
console.log('Child2 - after connection')
return <Nested />
}
function Nested() {
console.log('Nested')
return 'Content'
}
// async function cached() {
// "use cache"
// await new Promise((resolve) => setTimeout(resolve))
// return Date.now()
// }
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
cacheComponents: true,
experimental: {
// reactDebugChannel: true,
},
typescript: {
ignoreBuildErrors: true,
},
}
export default nextConfig
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