From 138c53bd15f7832b4cd1a1d74260d5c8a580ed8c Mon Sep 17 00:00:00 2001 From: Jessica Janiuk Date: Thu, 17 Oct 2024 14:16:44 -0400 Subject: [PATCH] feat(core): Add incremental hydration public api This exposes the public api to utilize incremental hydration. --- .../public-api/platform-browser/index.api.md | 3 +++ packages/platform-browser/src/hydration.ts | 21 ++++++++++++++++++ .../platform-browser/src/platform-browser.ts | 1 + .../platform-server/test/hydration_utils.ts | 22 ------------------- .../test/incremental_hydration_spec.ts | 4 ++-- 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/goldens/public-api/platform-browser/index.api.md b/goldens/public-api/platform-browser/index.api.md index 8d5edafbbdd0..51fb029be841 100644 --- a/goldens/public-api/platform-browser/index.api.md +++ b/goldens/public-api/platform-browser/index.api.md @@ -248,6 +248,9 @@ export function withHttpTransferCacheOptions(options: HttpTransferCacheOptions): // @public export function withI18nSupport(): HydrationFeature; +// @public +export function withIncrementalHydration(): HydrationFeature; + // @public export function withNoHttpTransferCache(): HydrationFeature; diff --git a/packages/platform-browser/src/hydration.ts b/packages/platform-browser/src/hydration.ts index 3866b4c34ec1..2f2340b2ab20 100644 --- a/packages/platform-browser/src/hydration.ts +++ b/packages/platform-browser/src/hydration.ts @@ -20,6 +20,7 @@ import { ɵwithEventReplay, ɵwithI18nSupport, ɵZONELESS_ENABLED as ZONELESS_ENABLED, + ɵwithIncrementalHydration, } from '@angular/core'; import {RuntimeErrorCode} from './errors'; @@ -120,6 +121,26 @@ export function withEventReplay(): HydrationFeature { + return hydrationFeature(HydrationFeatureKind.IncrementalHydration, ɵwithIncrementalHydration()); +} + /** * Returns an `ENVIRONMENT_INITIALIZER` token setup with a function * that verifies whether compatible ZoneJS was used in an application diff --git a/packages/platform-browser/src/platform-browser.ts b/packages/platform-browser/src/platform-browser.ts index a8f5b7c88a9b..34cef910a004 100644 --- a/packages/platform-browser/src/platform-browser.ts +++ b/packages/platform-browser/src/platform-browser.ts @@ -44,6 +44,7 @@ export { withHttpTransferCacheOptions, withI18nSupport, withNoHttpTransferCache, + withIncrementalHydration, } from './hydration'; export * from './private_export'; diff --git a/packages/platform-server/test/hydration_utils.ts b/packages/platform-server/test/hydration_utils.ts index 840ff1b491f0..705340e3456b 100644 --- a/packages/platform-server/test/hydration_utils.ts +++ b/packages/platform-server/test/hydration_utils.ts @@ -13,7 +13,6 @@ import { Injectable, Provider, Type, - ɵwithIncrementalHydration, } from '@angular/core'; import {Console} from '@angular/core/src/console'; import { @@ -277,24 +276,3 @@ export function clearConsole(appRef: ApplicationRef) { const console = appRef.injector.get(Console) as DebugConsole; console.logs = []; } - -// The following 2 functions are temporary for landing incremental hydration code -// before the feature commit that adds the public api. These will be removed -// in favor of the real API. - -// TODO(incremental-hydration): remove this once the public api lands -/** - * Helper function to create an object that represents a Hydration feature. - */ -function hydrationFeature( - ɵkind: FeatureKind, - ɵproviders: Provider[] = [], - ɵoptions: unknown = {}, -): HydrationFeature { - return {ɵkind, ɵproviders}; -} - -// TODO(incremental-hydration): remove this once the public api lands -export function withIncrementalHydration(): HydrationFeature { - return hydrationFeature(HydrationFeatureKind.IncrementalHydration, ɵwithIncrementalHydration()); -} diff --git a/packages/platform-server/test/incremental_hydration_spec.ts b/packages/platform-server/test/incremental_hydration_spec.ts index d68441b5440a..e0c609a74107 100644 --- a/packages/platform-server/test/incremental_hydration_spec.ts +++ b/packages/platform-server/test/incremental_hydration_spec.ts @@ -19,10 +19,10 @@ import { } from '@angular/core'; import {getAppContents, prepareEnvironmentAndHydrate, resetTViewsFor} from './dom_utils'; -import {getComponentRef, ssr, timeout, withIncrementalHydration} from './hydration_utils'; +import {getComponentRef, ssr, timeout} from './hydration_utils'; import {getDocument} from '@angular/core/src/render3/interfaces/document'; import {isPlatformServer} from '@angular/common'; -import {withEventReplay} from '@angular/platform-browser'; +import {withEventReplay, withIncrementalHydration} from '@angular/platform-browser'; describe('platform-server partial hydration integration', () => { const originalWindow = globalThis.window;