diff --git a/packages/core/src/hydration/annotate.ts b/packages/core/src/hydration/annotate.ts index 64c75efe4c4e99..1402e8db8c1e64 100644 --- a/packages/core/src/hydration/annotate.ts +++ b/packages/core/src/hydration/annotate.ts @@ -405,12 +405,16 @@ function serializeLContainer( // Add defer block into info context.deferBlocks const deferBlockInfo: SerializedDeferBlock = { - [DEFER_PARENT_BLOCK_ID]: parentDeferBlockId, [NUM_ROOT_NODES]: rootNodes.length, [DEFER_BLOCK_STATE]: lDetails[CURRENT_DEFER_BLOCK_STATE], [DEFER_HYDRATE_TRIGGERS]: serializeHydrateTriggers(tDetails.hydrateTriggers), }; + if (parentDeferBlockId !== null) { + // Serialize parent id only when it's present. + deferBlockInfo[DEFER_PARENT_BLOCK_ID] = parentDeferBlockId; + } + context.deferBlocks.set(deferBlockId, deferBlockInfo); const node = unwrapRNode(lContainer); diff --git a/packages/core/src/hydration/interfaces.ts b/packages/core/src/hydration/interfaces.ts index 929cdc3e3df6cd..7ac11311df3393 100644 --- a/packages/core/src/hydration/interfaces.ts +++ b/packages/core/src/hydration/interfaces.ts @@ -158,7 +158,7 @@ export interface SerializedDeferBlock { /** * This contains the unique id of this defer block's parent, if it exists. */ - [DEFER_PARENT_BLOCK_ID]: string | null; + [DEFER_PARENT_BLOCK_ID]?: string; /** * This field represents a status, based on the `DeferBlockState` enum. diff --git a/packages/core/src/hydration/utils.ts b/packages/core/src/hydration/utils.ts index 14692c41c2f856..31c036a0cd7577 100644 --- a/packages/core/src/hydration/utils.ts +++ b/packages/core/src/hydration/utils.ts @@ -566,7 +566,7 @@ export function getParentBlockHydrationQueue( const deferBlockParents = transferState.get(NGH_DEFER_BLOCKS_KEY, {}); let isTopMostDeferBlock = false; - let currentBlockId: string | null = deferBlockId; + let currentBlockId: string | undefined = deferBlockId; let parentBlockPromise: Promise | null = null; const hydrationQueue: string[] = []; diff --git a/packages/platform-server/test/incremental_hydration_spec.ts b/packages/platform-server/test/incremental_hydration_spec.ts index e46dd96902e589..c706fd48e2a2fa 100644 --- a/packages/platform-server/test/incremental_hydration_spec.ts +++ b/packages/platform-server/test/incremental_hydration_spec.ts @@ -206,7 +206,7 @@ describe('platform-server partial hydration integration', () => { expect(ssrContents).toContain('

{ expect(ssrContents).toContain('

{ // expect(ssrContents).toContain('