Skip to content

Commit b124e50

Browse files
refactor(core): avoid producing zone-related warnings during hydration when in zoneless mode (angular#57911)
This commit updates hydration code to avoid logging "unsupported configuration" warnings when in zoneless mode. PR Close angular#57911
1 parent 030ffb2 commit b124e50

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

packages/platform-browser/src/hydration.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
ɵwithDomHydration as withDomHydration,
2020
ɵwithEventReplay,
2121
ɵwithI18nSupport,
22+
ɵZONELESS_ENABLED as ZONELESS_ENABLED,
2223
} from '@angular/core';
2324

2425
import {RuntimeErrorCode} from './errors';
@@ -129,9 +130,10 @@ function provideZoneJsCompatibilityDetector(): Provider[] {
129130
provide: ENVIRONMENT_INITIALIZER,
130131
useValue: () => {
131132
const ngZone = inject(NgZone);
133+
const isZoneless = inject(ZONELESS_ENABLED);
132134
// Checking `ngZone instanceof NgZone` would be insufficient here,
133135
// because custom implementations might use NgZone as a base class.
134-
if (ngZone.constructor !== NgZone) {
136+
if (!isZoneless && ngZone.constructor !== NgZone) {
135137
const console = inject(Console);
136138
const message = formatRuntimeError(
137139
RuntimeErrorCode.UNSUPPORTED_ZONEJS_INSTANCE,

packages/platform-server/test/hydration_spec.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
Pipe,
4242
PipeTransform,
4343
PLATFORM_ID,
44+
provideExperimentalZonelessChangeDetection,
4445
Provider,
4546
QueryList,
4647
TemplateRef,
@@ -7950,6 +7951,47 @@ describe('platform-server hydration integration', () => {
79507951
});
79517952
});
79527953

7954+
describe('zoneless', () => {
7955+
it('should not produce "unsupported configuration" warnings for zoneless mode', async () => {
7956+
@Component({
7957+
standalone: true,
7958+
selector: 'app',
7959+
template: `
7960+
<header>Header</header>
7961+
<footer>Footer</footer>
7962+
`,
7963+
})
7964+
class SimpleComponent {}
7965+
7966+
const html = await ssr(SimpleComponent);
7967+
const ssrContents = getAppContents(html);
7968+
7969+
expect(ssrContents).toContain(`<app ${NGH_ATTR_NAME}`);
7970+
7971+
resetTViewsFor(SimpleComponent);
7972+
7973+
const appRef = await renderAndHydrate(doc, html, SimpleComponent, {
7974+
envProviders: [
7975+
withDebugConsole(),
7976+
provideExperimentalZonelessChangeDetection() as unknown as Provider[],
7977+
],
7978+
});
7979+
const compRef = getComponentRef<SimpleComponent>(appRef);
7980+
appRef.tick();
7981+
7982+
// Make sure there are no extra logs in case zoneless mode is enabled.
7983+
verifyHasNoLog(
7984+
appRef,
7985+
'NG05000: Angular detected that hydration was enabled for an application ' +
7986+
'that uses a custom or a noop Zone.js implementation.',
7987+
);
7988+
7989+
const clientRootNode = compRef.location.nativeElement;
7990+
verifyAllNodesClaimedForHydration(clientRootNode);
7991+
verifyClientAndSSRContentsMatch(ssrContents, clientRootNode);
7992+
});
7993+
});
7994+
79537995
describe('Router', () => {
79547996
it('should wait for lazy routes before triggering post-hydration cleanup', async () => {
79557997
const ngZone = TestBed.inject(NgZone);

0 commit comments

Comments
 (0)