Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat(core): Add incremental hydration public api
This exposes the public api to utilize incremental hydration.
  • Loading branch information
thePunderWoman committed Oct 21, 2024
commit 138c53bd15f7832b4cd1a1d74260d5c8a580ed8c
3 changes: 3 additions & 0 deletions goldens/public-api/platform-browser/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ export function withHttpTransferCacheOptions(options: HttpTransferCacheOptions):
// @public
export function withI18nSupport(): HydrationFeature<HydrationFeatureKind.I18nSupport>;

// @public
export function withIncrementalHydration(): HydrationFeature<HydrationFeatureKind.IncrementalHydration>;

// @public
export function withNoHttpTransferCache(): HydrationFeature<HydrationFeatureKind.NoHttpTransferCache>;

Expand Down
21 changes: 21 additions & 0 deletions packages/platform-browser/src/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
ɵwithEventReplay,
ɵwithI18nSupport,
ɵZONELESS_ENABLED as ZONELESS_ENABLED,
ɵwithIncrementalHydration,
} from '@angular/core';

import {RuntimeErrorCode} from './errors';
Expand Down Expand Up @@ -120,6 +121,26 @@ export function withEventReplay(): HydrationFeature<HydrationFeatureKind.EventRe
return hydrationFeature(HydrationFeatureKind.EventReplay, ɵwithEventReplay());
}

/**
* Enables support for incremental hydration using the `hydrate` trigger syntax.
*
* @usageNotes
*
* Basic example of how you can enable event replay in your application when
* `bootstrapApplication` function is used:
* ```
* bootstrapApplication(AppComponent, {
* providers: [provideClientHydration(withIncrementalHydration())]
* });
* ```
* @experimental
* @publicApi
* @see {@link provideClientHydration}
*/
export function withIncrementalHydration(): HydrationFeature<HydrationFeatureKind.IncrementalHydration> {
return hydrationFeature(HydrationFeatureKind.IncrementalHydration, ɵwithIncrementalHydration());
}

/**
* Returns an `ENVIRONMENT_INITIALIZER` token setup with a function
* that verifies whether compatible ZoneJS was used in an application
Expand Down
1 change: 1 addition & 0 deletions packages/platform-browser/src/platform-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export {
withHttpTransferCacheOptions,
withI18nSupport,
withNoHttpTransferCache,
withIncrementalHydration,
} from './hydration';

export * from './private_export';
Expand Down
22 changes: 0 additions & 22 deletions packages/platform-server/test/hydration_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
Injectable,
Provider,
Type,
ɵwithIncrementalHydration,
} from '@angular/core';
import {Console} from '@angular/core/src/console';
import {
Expand Down Expand Up @@ -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<FeatureKind extends HydrationFeatureKind>(
ɵkind: FeatureKind,
ɵproviders: Provider[] = [],
ɵoptions: unknown = {},
): HydrationFeature<FeatureKind> {
return {ɵkind, ɵproviders};
}

// TODO(incremental-hydration): remove this once the public api lands
export function withIncrementalHydration(): HydrationFeature<HydrationFeatureKind.IncrementalHydration> {
return hydrationFeature(HydrationFeatureKind.IncrementalHydration, ɵwithIncrementalHydration());
}
4 changes: 2 additions & 2 deletions packages/platform-server/test/incremental_hydration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down