( instrumentationHooks: ClientInstrumentationHooks | null, assetPrefix: string )
| 347 | } |
| 348 | |
| 349 | export async function hydrate( |
| 350 | instrumentationHooks: ClientInstrumentationHooks | null, |
| 351 | assetPrefix: string |
| 352 | ) { |
| 353 | let staticIndicatorState: StaticIndicatorState | undefined |
| 354 | let webSocket: WebSocket | undefined |
| 355 | |
| 356 | if (process.env.__NEXT_DEV_SERVER) { |
| 357 | const { createWebSocket } = |
| 358 | require('./dev/hot-reloader/app/web-socket') as typeof import('./dev/hot-reloader/app/web-socket') |
| 359 | |
| 360 | staticIndicatorState = { pathname: null, appIsrManifest: null } |
| 361 | webSocket = createWebSocket(assetPrefix, staticIndicatorState) |
| 362 | } |
| 363 | const initialRSCPayload = await initialServerResponse |
| 364 | |
| 365 | // setNavigationBuildId should be called only once, during JS initialization |
| 366 | // and before any components have hydrated. |
| 367 | if (initialRSCPayload.b) { |
| 368 | setNavigationBuildId(initialRSCPayload.b!) |
| 369 | } else { |
| 370 | setNavigationBuildId(getDeploymentId()!) |
| 371 | } |
| 372 | |
| 373 | const initialTimestamp = Date.now() |
| 374 | const actionQueue: AppRouterActionQueue = createMutableActionQueue( |
| 375 | createInitialRouterState({ |
| 376 | navigatedAt: initialTimestamp, |
| 377 | initialRSCPayload, |
| 378 | initialFlightStreamForCache, |
| 379 | location: window.location, |
| 380 | }), |
| 381 | instrumentationHooks |
| 382 | ) |
| 383 | |
| 384 | const reactEl = ( |
| 385 | <StrictModeIfEnabled> |
| 386 | <HeadManagerContext.Provider value={{ appDir: true }}> |
| 387 | <Root> |
| 388 | <ServerRoot |
| 389 | initialRSCPayload={initialRSCPayload} |
| 390 | actionQueue={actionQueue} |
| 391 | webSocket={webSocket} |
| 392 | staticIndicatorState={staticIndicatorState} |
| 393 | /> |
| 394 | </Root> |
| 395 | </HeadManagerContext.Provider> |
| 396 | </StrictModeIfEnabled> |
| 397 | ) |
| 398 | |
| 399 | if (document.documentElement.id === '__next_error__') { |
| 400 | let element = reactEl |
| 401 | // Server rendering failed, fall back to client-side rendering |
| 402 | if (process.env.NODE_ENV !== 'production') { |
| 403 | const { RootLevelDevOverlayElement } = |
| 404 | require('../next-devtools/userspace/app/client-entry') as typeof import('../next-devtools/userspace/app/client-entry') |
| 405 | |
| 406 | // Note this won't cause hydration mismatch because we are doing CSR w/o hydration |
nothing calls this directly
no test coverage detected