Skip to content

Commit 138c53b

Browse files
feat(core): Add incremental hydration public api
This exposes the public api to utilize incremental hydration.
1 parent 9544930 commit 138c53b

5 files changed

Lines changed: 27 additions & 24 deletions

File tree

goldens/public-api/platform-browser/index.api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ export function withHttpTransferCacheOptions(options: HttpTransferCacheOptions):
248248
// @public
249249
export function withI18nSupport(): HydrationFeature<HydrationFeatureKind.I18nSupport>;
250250

251+
// @public
252+
export function withIncrementalHydration(): HydrationFeature<HydrationFeatureKind.IncrementalHydration>;
253+
251254
// @public
252255
export function withNoHttpTransferCache(): HydrationFeature<HydrationFeatureKind.NoHttpTransferCache>;
253256

packages/platform-browser/src/hydration.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
ɵwithEventReplay,
2121
ɵwithI18nSupport,
2222
ɵZONELESS_ENABLED as ZONELESS_ENABLED,
23+
ɵwithIncrementalHydration,
2324
} from '@angular/core';
2425

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

124+
/**
125+
* Enables support for incremental hydration using the `hydrate` trigger syntax.
126+
*
127+
* @usageNotes
128+
*
129+
* Basic example of how you can enable event replay in your application when
130+
* `bootstrapApplication` function is used:
131+
* ```
132+
* bootstrapApplication(AppComponent, {
133+
* providers: [provideClientHydration(withIncrementalHydration())]
134+
* });
135+
* ```
136+
* @experimental
137+
* @publicApi
138+
* @see {@link provideClientHydration}
139+
*/
140+
export function withIncrementalHydration(): HydrationFeature<HydrationFeatureKind.IncrementalHydration> {
141+
return hydrationFeature(HydrationFeatureKind.IncrementalHydration, ɵwithIncrementalHydration());
142+
}
143+
123144
/**
124145
* Returns an `ENVIRONMENT_INITIALIZER` token setup with a function
125146
* that verifies whether compatible ZoneJS was used in an application

packages/platform-browser/src/platform-browser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export {
4444
withHttpTransferCacheOptions,
4545
withI18nSupport,
4646
withNoHttpTransferCache,
47+
withIncrementalHydration,
4748
} from './hydration';
4849

4950
export * from './private_export';

packages/platform-server/test/hydration_utils.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
Injectable,
1414
Provider,
1515
Type,
16-
ɵwithIncrementalHydration,
1716
} from '@angular/core';
1817
import {Console} from '@angular/core/src/console';
1918
import {
@@ -277,24 +276,3 @@ export function clearConsole(appRef: ApplicationRef) {
277276
const console = appRef.injector.get(Console) as DebugConsole;
278277
console.logs = [];
279278
}
280-
281-
// The following 2 functions are temporary for landing incremental hydration code
282-
// before the feature commit that adds the public api. These will be removed
283-
// in favor of the real API.
284-
285-
// TODO(incremental-hydration): remove this once the public api lands
286-
/**
287-
* Helper function to create an object that represents a Hydration feature.
288-
*/
289-
function hydrationFeature<FeatureKind extends HydrationFeatureKind>(
290-
ɵkind: FeatureKind,
291-
ɵproviders: Provider[] = [],
292-
ɵoptions: unknown = {},
293-
): HydrationFeature<FeatureKind> {
294-
return {ɵkind, ɵproviders};
295-
}
296-
297-
// TODO(incremental-hydration): remove this once the public api lands
298-
export function withIncrementalHydration(): HydrationFeature<HydrationFeatureKind.IncrementalHydration> {
299-
return hydrationFeature(HydrationFeatureKind.IncrementalHydration, ɵwithIncrementalHydration());
300-
}

packages/platform-server/test/incremental_hydration_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import {
1919
} from '@angular/core';
2020

2121
import {getAppContents, prepareEnvironmentAndHydrate, resetTViewsFor} from './dom_utils';
22-
import {getComponentRef, ssr, timeout, withIncrementalHydration} from './hydration_utils';
22+
import {getComponentRef, ssr, timeout} from './hydration_utils';
2323
import {getDocument} from '@angular/core/src/render3/interfaces/document';
2424
import {isPlatformServer} from '@angular/common';
25-
import {withEventReplay} from '@angular/platform-browser';
25+
import {withEventReplay, withIncrementalHydration} from '@angular/platform-browser';
2626

2727
describe('platform-server partial hydration integration', () => {
2828
const originalWindow = globalThis.window;

0 commit comments

Comments
 (0)