Commit aef7c344 authored by Jiachi Liu's avatar Jiachi Liu

prototyping

parent 17257e64
...@@ -49,6 +49,7 @@ import { ...@@ -49,6 +49,7 @@ import {
import { scheduleOnNextTick } from '../../lib/scheduler' import { scheduleOnNextTick } from '../../lib/scheduler'
import { BailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr' import { BailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr'
import { InvariantError } from '../../shared/lib/invariant-error' import { InvariantError } from '../../shared/lib/invariant-error'
import { trackDynamicAPIAccess } from './suspense-boundary-collector'
const hasPostpone = typeof React.unstable_postpone === 'function' const hasPostpone = typeof React.unstable_postpone === 'function'
...@@ -224,7 +225,10 @@ export function throwToInterruptStaticGeneration( ...@@ -224,7 +225,10 @@ export function throwToInterruptStaticGeneration(
* *
* @internal * @internal
*/ */
export function trackDynamicDataInDynamicRender(workUnitStore: WorkUnitStore) { export function trackDynamicDataInDynamicRender(
workUnitStore: WorkUnitStore,
expression?: string
) {
switch (workUnitStore.type) { switch (workUnitStore.type) {
case 'cache': case 'cache':
case 'unstable-cache': case 'unstable-cache':
...@@ -246,6 +250,14 @@ export function trackDynamicDataInDynamicRender(workUnitStore: WorkUnitStore) { ...@@ -246,6 +250,14 @@ export function trackDynamicDataInDynamicRender(workUnitStore: WorkUnitStore) {
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
workUnitStore.usedDynamic = true workUnitStore.usedDynamic = true
} }
// Track for suspense profiling
if (expression) {
const ownerStack =
process.env.NODE_ENV !== 'production' && React.captureOwnerStack
? React.captureOwnerStack()
: null
trackDynamicAPIAccess(expression, ownerStack)
}
break break
default: default:
workUnitStore satisfies never workUnitStore satisfies never
...@@ -368,6 +380,13 @@ export function postponeWithTracking( ...@@ -368,6 +380,13 @@ export function postponeWithTracking(
}) })
} }
// Track for suspense profiling
const ownerStack =
process.env.NODE_ENV !== 'production' && React.captureOwnerStack
? React.captureOwnerStack()
: null
trackDynamicAPIAccess(expression, ownerStack)
React.unstable_postpone(createPostponeReason(route, expression)) React.unstable_postpone(createPostponeReason(route, expression))
} }
......
import type { ComponentProps, ReactNode, ComponentType } from 'react' import type { ComponentProps, ReactNode, ComponentType } from 'react'
import { import { registerSuspenseBoundary } from './suspense-boundary-collector'
registerSuspenseBoundary,
pushSuspenseBoundary,
popSuspenseBoundary,
type SuspenseBoundarySource,
} from './suspense-boundary-collector'
type SuspenseProps = ComponentProps<typeof import('react').Suspense> type SuspenseProps = ComponentProps<typeof import('react').Suspense>
interface ProfilingSuspenseProps extends SuspenseProps { interface ReactWithOwnerStack {
__source?: SuspenseBoundarySource captureOwnerStack?: () => string | null
}
// Wrapper component to track boundary nesting
function SuspenseBoundaryTracker({
boundaryId,
children,
}: {
boundaryId: string
children: ReactNode
}) {
// Push this boundary onto the stack when rendering children
// This allows us to track parent-child relationships
pushSuspenseBoundary(boundaryId)
// The pop happens after children render due to React's depth-first rendering
// We use a trick: wrap children in a component that pops on render
return (
<>
{children}
<SuspenseBoundaryTrackerEnd boundaryId={boundaryId} />
</>
)
}
// This component renders at the end of the boundary's children
// and pops the boundary from the stack
function SuspenseBoundaryTrackerEnd({
boundaryId: _boundaryId,
}: {
boundaryId: string
}) {
popSuspenseBoundary()
return null
} }
export function createProfilingSuspense( export function createProfilingSuspense(
OriginalSuspense: ComponentType<SuspenseProps> OriginalSuspense: ComponentType<SuspenseProps>,
): ComponentType<ProfilingSuspenseProps> { React: ReactWithOwnerStack
function ProfilingSuspense(props: ProfilingSuspenseProps): ReactNode { ): ComponentType<SuspenseProps> {
const { children, fallback, __source, ...rest } = props function ProfilingSuspense(props: SuspenseProps): ReactNode {
const { children, fallback, ...rest } = props
// Capture owner stack in dev mode
const ownerStack =
process.env.NODE_ENV !== 'production' &&
typeof React?.captureOwnerStack === 'function'
? React.captureOwnerStack()
: null
// Register this boundary and get its unique ID // Register this boundary and get its unique ID
const boundaryId = registerSuspenseBoundary(__source || null) const boundaryId = registerSuspenseBoundary(ownerStack)
// If no boundary ID (collector not active), render original // If no boundary ID (collector not active), render original
if (!boundaryId) { if (!boundaryId) {
...@@ -63,13 +33,6 @@ export function createProfilingSuspense( ...@@ -63,13 +33,6 @@ export function createProfilingSuspense(
) )
} }
// Wrap children to track nesting
const trackedChildren = (
<SuspenseBoundaryTracker boundaryId={boundaryId}>
{children}
</SuspenseBoundaryTracker>
)
return ( return (
<OriginalSuspense <OriginalSuspense
fallback={ fallback={
...@@ -91,7 +54,7 @@ export function createProfilingSuspense( ...@@ -91,7 +54,7 @@ export function createProfilingSuspense(
data-suspense-state="content" data-suspense-state="content"
hidden hidden
/> />
{trackedChildren} {children}
</OriginalSuspense> </OriginalSuspense>
) )
} }
...@@ -99,5 +62,5 @@ export function createProfilingSuspense( ...@@ -99,5 +62,5 @@ export function createProfilingSuspense(
// Preserve display name for debugging // Preserve display name for debugging
ProfilingSuspense.displayName = 'Suspense' ProfilingSuspense.displayName = 'Suspense'
return ProfilingSuspense as ComponentType<ProfilingSuspenseProps> return ProfilingSuspense
} }
import type { AsyncLocalStorage } from 'async_hooks'
import { createAsyncLocalStorage } from './async-local-storage' import { createAsyncLocalStorage } from './async-local-storage'
export interface SuspenseBoundarySource { export interface StackFrame {
fileName: string componentName: string
lineNumber: number fileName: string | null
columnNumber: number lineNumber: number | null
columnNumber: number | null
}
export interface DynamicAPIAccess {
expression: string // e.g., "cookies", "headers", "connection"
frames: StackFrame[] // owner stack at the point of call
} }
export interface SuspenseBoundaryInfo { export interface SuspenseBoundaryInfo {
id: string id: string
source: SuspenseBoundarySource | null frames: StackFrame[]
parentId: string | null
children: string[]
} }
export interface SuspenseBoundaryCollectorStore { export interface SuspenseBoundaryCollectorStore {
boundaries: Map<string, SuspenseBoundaryInfo> boundaries: Map<string, SuspenseBoundaryInfo>
idCounter: number idCounter: number
parentStack: string[] // Track dynamic API accesses that occurred during the render
dynamicAccesses: DynamicAPIAccess[]
}
// Use globalThis to ensure singleton across module duplications (vendored React bundles separately)
const globalKey = '__NEXT_SUSPENSE_BOUNDARY_COLLECTOR_STORAGE__'
function getOrCreateStorage(): AsyncLocalStorage<SuspenseBoundaryCollectorStore> {
const g = globalThis as any
if (!g[globalKey]) {
g[globalKey] = createAsyncLocalStorage<SuspenseBoundaryCollectorStore>()
}
return g[globalKey]
} }
export const suspenseBoundaryCollectorStorage = export const suspenseBoundaryCollectorStorage = getOrCreateStorage()
createAsyncLocalStorage<SuspenseBoundaryCollectorStore>()
export function createSuspenseBoundaryCollector(): SuspenseBoundaryCollectorStore { export function createSuspenseBoundaryCollector(): SuspenseBoundaryCollectorStore {
return { return {
boundaries: new Map(), boundaries: new Map(),
idCounter: 0, idCounter: 0,
parentStack: [], dynamicAccesses: [],
} }
} }
export function registerSuspenseBoundary( /**
source: SuspenseBoundarySource | null * Track a dynamic API access (e.g., cookies(), headers(), connection())
): string { * This is called from dynamic-rendering.ts when a dynamic API is used
*/
export function trackDynamicAPIAccess(
expression: string,
ownerStack: string | null
): void {
const store = suspenseBoundaryCollectorStorage.getStore() const store = suspenseBoundaryCollectorStorage.getStore()
if (!store) { if (!store) {
return '' return
} }
const id = `suspense-${store.idCounter++}` store.dynamicAccesses.push({
const parentId = store.parentStack[store.parentStack.length - 1] || null expression,
frames: parseOwnerStack(ownerStack),
// Register this boundary
store.boundaries.set(id, {
id,
source,
parentId,
children: [],
}) })
}
/**
* Parse owner stack string into structured stack frames
* Format: " at ComponentName (file:line:col)\n at Parent..."
* Or: " at ComponentName (file:line:col)"
* Or: " at file:line:col" (anonymous)
*/
function parseOwnerStack(ownerStack: string | null): StackFrame[] {
if (!ownerStack) return []
const frames: StackFrame[] = []
const lines = ownerStack.split('\n')
for (const line of lines) {
const trimmed = line.trim()
if (!trimmed.startsWith('at ')) continue
// Add to parent's children list // Try to match "at ComponentName (file:line:col)"
if (parentId) { const namedMatch = trimmed.match(
const parent = store.boundaries.get(parentId) /^at\s+([^\s(]+)\s+\((.+):(\d+):(\d+)\)$/
if (parent) { )
parent.children.push(id) if (namedMatch) {
frames.push({
componentName: namedMatch[1],
fileName: namedMatch[2],
lineNumber: parseInt(namedMatch[3], 10),
columnNumber: parseInt(namedMatch[4], 10),
})
continue
} }
}
return id // Try to match "at ComponentName (file:line)"
} const namedNoColMatch = trimmed.match(
/^at\s+([^\s(]+)\s+\((.+):(\d+)\)$/
)
if (namedNoColMatch) {
frames.push({
componentName: namedNoColMatch[1],
fileName: namedNoColMatch[2],
lineNumber: parseInt(namedNoColMatch[3], 10),
columnNumber: null,
})
continue
}
export function pushSuspenseBoundary(id: string): void { // Try to match "at file:line:col" (anonymous)
const store = suspenseBoundaryCollectorStorage.getStore() const anonMatch = trimmed.match(/^at\s+(.+):(\d+):(\d+)$/)
if (store && id) { if (anonMatch) {
store.parentStack.push(id) frames.push({
componentName: '<anonymous>',
fileName: anonMatch[1],
lineNumber: parseInt(anonMatch[2], 10),
columnNumber: parseInt(anonMatch[3], 10),
})
continue
}
// Try to match "at ComponentName" (no file info)
const nameOnlyMatch = trimmed.match(/^at\s+([^\s(]+)$/)
if (nameOnlyMatch) {
frames.push({
componentName: nameOnlyMatch[1],
fileName: null,
lineNumber: null,
columnNumber: null,
})
continue
}
} }
return frames
} }
export function popSuspenseBoundary(): void { export function registerSuspenseBoundary(ownerStack: string | null): string {
const store = suspenseBoundaryCollectorStorage.getStore() const store = suspenseBoundaryCollectorStorage.getStore()
if (store) { if (!store) {
store.parentStack.pop() return ''
} }
const id = `suspense-${store.idCounter++}`
const frames = parseOwnerStack(ownerStack)
store.boundaries.set(id, {
id,
frames,
})
return id
} }
export function getSuspenseBoundaries(): SuspenseBoundaryInfo[] { export function getSuspenseBoundaries(): SuspenseBoundaryInfo[] {
...@@ -82,10 +162,10 @@ export function getSuspenseBoundaries(): SuspenseBoundaryInfo[] { ...@@ -82,10 +162,10 @@ export function getSuspenseBoundaries(): SuspenseBoundaryInfo[] {
return Array.from(store.boundaries.values()) return Array.from(store.boundaries.values())
} }
export function serializeSuspenseBoundaries(): string { export function getDynamicAccesses(): DynamicAPIAccess[] {
const boundaries = getSuspenseBoundaries() const store = suspenseBoundaryCollectorStorage.getStore()
return JSON.stringify({ if (!store) {
boundaries, return []
timestamp: Date.now(), }
}) return store.dynamicAccesses
} }
import React from 'react' import React from 'react'
import { import {
getSuspenseBoundaries, getSuspenseBoundaries,
getDynamicAccesses,
type SuspenseBoundaryInfo, type SuspenseBoundaryInfo,
type DynamicAPIAccess,
} from './suspense-boundary-collector' } from './suspense-boundary-collector'
export interface SuspenseBoundaryData { export interface SuspenseBoundaryData {
boundaries: SuspenseBoundaryInfo[] boundaries: SuspenseBoundaryInfo[]
dynamicAccesses: DynamicAPIAccess[]
timestamp: number timestamp: number
} }
export function getSuspenseBoundaryData(): SuspenseBoundaryData { export function getSuspenseBoundaryData(): SuspenseBoundaryData {
return { return {
boundaries: getSuspenseBoundaries(), boundaries: getSuspenseBoundaries(),
dynamicAccesses: getDynamicAccesses(),
timestamp: Date.now(), timestamp: Date.now(),
} }
} }
export function SuspenseBoundaryScript(): React.ReactNode { const panelScript = `
const data = getSuspenseBoundaryData() (function() {
if (typeof window === 'undefined') return;
// Only inject if there are boundaries to report function createPanel() {
// (boundaries are only collected when suspense profiling is enabled) const script = document.getElementById('__NEXT_SUSPENSE_BOUNDARIES__');
if (data.boundaries.length === 0) { if (!script) return;
return null
}
return ( let data;
<script try {
id="__NEXT_SUSPENSE_BOUNDARIES__" data = JSON.parse(script.textContent || '{}');
type="application/json" } catch (e) {
dangerouslySetInnerHTML={{ return;
__html: JSON.stringify(data), }
}}
/>
)
}
export function serializeSuspenseBoundaryScript(): string { const container = document.createElement('div');
const data = getSuspenseBoundaryData() container.id = '__next_suspense_profiler__';
document.body.appendChild(container);
// Track expanded nodes by path
window.__sp = {
isOpen: false,
expanded: {},
toggle: function(path) {
window.__sp.expanded[path] = !window.__sp.expanded[path];
render();
},
open: function() {
window.__sp.isOpen = true;
render();
},
close: function() {
window.__sp.isOpen = false;
render();
}
};
// Build tree from boundaries and dynamic accesses
function buildTree(boundaries, dynamicAccesses) {
var root = { name: 'Root', children: {}, boundaries: [], apis: [] };
// Add boundaries to tree
boundaries.forEach(function(b) {
if (!b.frames.length) return;
// Reverse frames: from root to leaf
var path = b.frames.slice().reverse();
var node = root;
path.forEach(function(frame) {
var name = frame.componentName;
if (!node.children[name]) {
node.children[name] = { name: name, children: {}, boundaries: [], apis: [], frame: frame };
}
node = node.children[name];
});
node.boundaries.push(b);
});
// Add dynamic APIs to tree
dynamicAccesses.forEach(function(api) {
if (!api.frames.length) return;
var path = api.frames.slice().reverse();
var node = root;
path.forEach(function(frame) {
var name = frame.componentName;
if (!node.children[name]) {
node.children[name] = { name: name, children: {}, boundaries: [], apis: [], frame: frame };
}
node = node.children[name];
});
node.apis.push(api);
});
return root;
}
function renderNode(node, depth, path) {
var sp = window.__sp;
var childKeys = Object.keys(node.children);
var hasChildren = childKeys.length > 0;
var isExpanded = sp.expanded[path] !== false; // Default expanded
var indent = depth * 16;
var html = '';
if (depth > 0) {
var hasSuspense = node.boundaries.length > 0;
var hasApis = node.apis.length > 0;
html += '<div style="border-bottom:1px solid #f5f5f5;">';
html += '<div onclick="window.__sp.toggle(\\'' + path + '\\')" style="padding:8px 12px 8px ' + (12 + indent) + 'px;cursor:pointer;display:flex;align-items:center;gap:6px;">';
if (data.boundaries.length === 0) { if (hasChildren) {
return '' html += '<span style="color:#999;font-size:9px;width:10px;">' + (isExpanded ? '▼' : '▶') + '</span>';
} else {
html += '<span style="width:10px;"></span>';
}
html += '<span style="color:#1a1a1a;">' + node.name + '</span>';
if (hasSuspense) {
html += '<span style="background:#e8e8e8;color:#666;padding:1px 6px;border-radius:3px;font-size:10px;">suspense</span>';
}
if (hasApis) {
var apiNames = [];
node.apis.forEach(function(a) { if (apiNames.indexOf(a.expression) === -1) apiNames.push(a.expression); });
html += '<span style="color:#888;font-size:11px;margin-left:auto;">' + apiNames.join(', ') + '</span>';
}
html += '</div></div>';
}
if (isExpanded && hasChildren) {
childKeys.forEach(function(key) {
html += renderNode(node.children[key], depth + 1, path + '/' + key);
});
}
return html;
}
function render() {
var boundaries = data.boundaries || [];
var dynamicAccesses = data.dynamicAccesses || [];
var sp = window.__sp;
if (sp.isOpen) {
var tree = buildTree(boundaries, dynamicAccesses);
var treeHtml = '';
Object.keys(tree.children).forEach(function(key) {
treeHtml += renderNode(tree.children[key], 1, key);
});
container.innerHTML = '<div style="position:fixed;bottom:20px;right:20px;z-index:99999;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;font-size:13px;">' +
'<div style="background:#fff;color:#1a1a1a;border:1px solid #e0e0e0;border-radius:8px;width:360px;max-height:450px;overflow:hidden;display:flex;flex-direction:column;box-shadow:0 4px 12px rgba(0,0,0,0.1);">' +
'<div style="padding:12px 16px;border-bottom:1px solid #e0e0e0;display:flex;justify-content:space-between;align-items:center;">' +
'<span style="font-weight:600;color:#1a1a1a;">Component Tree</span>' +
'<button onclick="window.__sp.close()" style="background:none;border:none;color:#666;cursor:pointer;font-size:18px;line-height:1;padding:0 4px;">×</button>' +
'</div>' +
'<div style="overflow:auto;flex:1;">' +
(treeHtml || '<div style="padding:16px;color:#888;">No boundaries detected</div>') +
'</div>' +
'</div>' +
'</div>';
} else {
var hasDynamic = dynamicAccesses.length > 0;
container.innerHTML = '<div style="position:fixed;bottom:20px;right:20px;z-index:99999;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;font-size:13px;">' +
'<button onclick="window.__sp.open()" style="background:#fff;color:#1a1a1a;border:1px solid #e0e0e0;border-radius:6px;padding:8px 14px;cursor:pointer;display:flex;align-items:center;gap:8px;box-shadow:0 2px 8px rgba(0,0,0,0.08);">' +
'<span>⏳ ' + boundaries.length + '</span>' +
(hasDynamic ? '<span style="color:#666;">' + dynamicAccesses.length + ' dynamic</span>' : '') +
'</button>' +
'</div>';
}
}
render();
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', createPanel);
} else {
createPanel();
} }
})();
`
export function SuspenseBoundaryScript(): React.ReactNode {
const data = getSuspenseBoundaryData()
return `<script id="__NEXT_SUSPENSE_BOUNDARIES__" type="application/json">${JSON.stringify(data)}</script>` return (
<>
<script
id="__NEXT_SUSPENSE_BOUNDARIES__"
type="application/json"
dangerouslySetInnerHTML={{
__html: JSON.stringify(data),
}}
/>
<script
dangerouslySetInnerHTML={{
__html: panelScript,
}}
/>
</>
)
} }
...@@ -101,7 +101,7 @@ export function connection(): Promise<void> { ...@@ -101,7 +101,7 @@ export function connection(): Promise<void> {
workUnitStore workUnitStore
) )
case 'request': case 'request':
trackDynamicDataInDynamicRender(workUnitStore) trackDynamicDataInDynamicRender(workUnitStore, callingExpression)
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
// Semantically we only need the dev tracking when running in `next dev` // Semantically we only need the dev tracking when running in `next dev`
// but since you would never use next dev with production NODE_ENV we use this // but since you would never use next dev with production NODE_ENV we use this
......
...@@ -106,7 +106,7 @@ export function cookies(): Promise<ReadonlyRequestCookies> { ...@@ -106,7 +106,7 @@ export function cookies(): Promise<ReadonlyRequestCookies> {
// so we don't need an additional delay here. // so we don't need an additional delay here.
return makeUntrackedCookies(workUnitStore.cookies) return makeUntrackedCookies(workUnitStore.cookies)
case 'request': case 'request':
trackDynamicDataInDynamicRender(workUnitStore) trackDynamicDataInDynamicRender(workUnitStore, callingExpression)
let underlyingCookies: ReadonlyRequestCookies let underlyingCookies: ReadonlyRequestCookies
......
...@@ -238,7 +238,7 @@ function trackDynamicDraftMode(expression: string, constructorOpt: Function) { ...@@ -238,7 +238,7 @@ function trackDynamicDraftMode(expression: string, constructorOpt: Function) {
throw err throw err
case 'request': case 'request':
trackDynamicDataInDynamicRender(workUnitStore) trackDynamicDataInDynamicRender(workUnitStore, expression)
break break
default: default:
workUnitStore satisfies never workUnitStore satisfies never
......
...@@ -132,7 +132,7 @@ export function headers(): Promise<ReadonlyHeaders> { ...@@ -132,7 +132,7 @@ export function headers(): Promise<ReadonlyHeaders> {
// so we don't need an additional delay here. // so we don't need an additional delay here.
return makeUntrackedHeaders(workUnitStore.headers) return makeUntrackedHeaders(workUnitStore.headers)
case 'request': case 'request':
trackDynamicDataInDynamicRender(workUnitStore) trackDynamicDataInDynamicRender(workUnitStore, callingExpression)
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
// Semantically we only need the dev tracking when running in `next dev` // Semantically we only need the dev tracking when running in `next dev`
......
...@@ -8,5 +8,5 @@ const ReactRSC = ( ...@@ -8,5 +8,5 @@ const ReactRSC = (
// The wrapper checks at render time if the collector is active. // The wrapper checks at render time if the collector is active.
// If not, it renders the original Suspense without markers. // If not, it renders the original Suspense without markers.
module.exports = Object.assign({}, ReactRSC, { module.exports = Object.assign({}, ReactRSC, {
Suspense: createProfilingSuspense(ReactRSC.Suspense), Suspense: createProfilingSuspense(ReactRSC.Suspense, ReactRSC),
}) })
...@@ -8,5 +8,5 @@ const ReactSSR = ( ...@@ -8,5 +8,5 @@ const ReactSSR = (
// The wrapper checks at render time if the collector is active. // The wrapper checks at render time if the collector is active.
// If not, it renders the original Suspense without markers. // If not, it renders the original Suspense without markers.
module.exports = Object.assign({}, ReactSSR, { module.exports = Object.assign({}, ReactSSR, {
Suspense: createProfilingSuspense(ReactSSR.Suspense), Suspense: createProfilingSuspense(ReactSSR.Suspense, ReactSSR),
}) })
import { Suspense } from 'react'
import { cookies, headers } from 'next/headers'
// Component that uses cookies - triggers dynamic API
async function CookieCounter() {
const cookieStore = await cookies()
const allCookies = cookieStore.getAll()
return (
<div data-testid="cookie-counter">
Cookie count: {allCookies.length}
</div>
)
}
// Component that uses headers - triggers dynamic API
async function HeaderInfo() {
const headersList = await headers()
const userAgent = headersList.get('user-agent') || 'Unknown'
return (
<div data-testid="header-info">
User Agent: {userAgent.slice(0, 50)}...
</div>
)
}
// Regular async component (no dynamic API)
async function SlowComponent({ id, delay }: { id: string; delay: number }) {
await new Promise((resolve) => setTimeout(resolve, delay))
return <div data-testid={`content-${id}`}>Content {id} loaded</div>
}
// Wrapper components to make boundaries identifiable
function CookieSection() {
return (
<Suspense fallback={<div data-testid="cookies-loading">Loading cookies...</div>}>
<CookieCounter />
</Suspense>
)
}
function HeaderSection() {
return (
<Suspense fallback={<div data-testid="headers-loading">Loading headers...</div>}>
<HeaderInfo />
</Suspense>
)
}
function RegularSection() {
return (
<Suspense fallback={<div data-testid="regular-loading">Loading regular...</div>}>
<SlowComponent id="regular" delay={100} />
</Suspense>
)
}
export default function DynamicPage() {
return (
<div data-testid="dynamic-page-root">
<h1>Dynamic API Test</h1>
<section>
<h2>Dynamic APIs (will opt out of static rendering)</h2>
<CookieSection />
<HeaderSection />
</section>
<section>
<h2>Regular Async (no dynamic API)</h2>
<RegularSection />
</section>
</div>
)
}
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