( injector: Injector, blockName: string, replayQueuedEventsFn?: Function, )
| 372 | * events. |
| 373 | */ |
| 374 | export async function triggerHydrationFromBlockName( |
| 375 | injector: Injector, |
| 376 | blockName: string, |
| 377 | replayQueuedEventsFn?: Function, |
| 378 | ) { |
| 379 | const dehydratedBlockRegistry = injector.get(DEHYDRATED_BLOCK_REGISTRY); |
| 380 | const blocksBeingHydrated = dehydratedBlockRegistry.hydrating; |
| 381 | |
| 382 | // Make sure we don't hydrate/trigger the same thing multiple times |
| 383 | if (blocksBeingHydrated.has(blockName)) { |
| 384 | return; |
| 385 | } |
| 386 | |
| 387 | // Trigger resource loading and hydration for the blocks in the queue in the order of highest block |
| 388 | // to lowest block. Once a block has finished resource loading, after next render fires after hydration |
| 389 | // finishes. The new block will have its defer instruction called and will be in the registry. |
| 390 | // Due to timing related to potential nested control flow, this has to be scheduled after the next render. |
| 391 | const {parentBlockPromise, hydrationQueue} = getParentBlockHydrationQueue(blockName, injector); |
| 392 | if (hydrationQueue.length === 0) return; |
| 393 | |
| 394 | // The hydrating map in the registry prevents re-triggering hydration for a block that's already in |
| 395 | // the hydration queue. Here we generate promises for each of the blocks about to be hydrated |
| 396 | populateHydratingStateForQueue(dehydratedBlockRegistry, hydrationQueue); |
| 397 | |
| 398 | // We await this after populating the hydration state so we can prevent re-triggering hydration for |
| 399 | // the same blocks while this promise is being awaited. |
| 400 | if (parentBlockPromise !== null) { |
| 401 | await parentBlockPromise; |
| 402 | } |
| 403 | |
| 404 | const topmostParentBlock = hydrationQueue[0]; |
| 405 | if (dehydratedBlockRegistry.has(topmostParentBlock)) { |
| 406 | // the topmost parent block is already in the registry and we can proceed |
| 407 | // with hydration. |
| 408 | await triggerHydrationForBlockQueue(injector, hydrationQueue, replayQueuedEventsFn); |
| 409 | } else { |
| 410 | // the topmost parent block is not yet in the registry, which may mean |
| 411 | // a lazy loaded route, a control flow branch was taken, a route has |
| 412 | // been navigated, etc. So we need to queue up the hydration process |
| 413 | // so that it can be finished after the top block has had its defer |
| 414 | // instruction executed. |
| 415 | dehydratedBlockRegistry.awaitParentBlock( |
| 416 | topmostParentBlock, |
| 417 | async () => |
| 418 | await triggerHydrationForBlockQueue(injector, hydrationQueue, replayQueuedEventsFn), |
| 419 | ); |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | /** |
| 424 | * The core mechanism for incremental hydration. This triggers |
no test coverage detected