Skip to content

fix(core): suppress hydration warnings in test environments - #71978

Open
JeanMeche wants to merge 1 commit into
angular:mainfrom
JeanMeche:fix/hydration-test-warning
Open

JeanMeche wants to merge 1 commit into
angular:mainfrom
JeanMeche:fix/hydration-test-warning

Conversation

@JeanMeche

Copy link
Copy Markdown
Member

When running component tests in TestBed, an application configuration may include provideClientHydration() (e.g. from appConfig.providers) or use @defer blocks with hydrate triggers without hydration providers configured.

In these testing scenarios, there is no serialized server state in TransferState because the tests run purely in the test runner. As a result, Angular emitted spurious warnings:

  • NG0505: warning that client hydration was requested on the client, but no serialized information was present in the server response.
  • NG0508: warning that incremental hydration is not enabled when @defer (hydrate ...) triggers are used.

This commit introduces an internal IS_TESTING token (defaulting to false), which is provided as true by TestBedCompiler and BrowserTestingModule. It suppresses both warnings when running inside a testing environment.

Fixes #62053

@angular-robot angular-robot Bot added the area: core Issues related to the framework runtime label Nov 11, 2026
@ngbot ngbot Bot added this to the Backlog milestone Nov 11, 2026
When running component tests in TestBed, an application may include
provideClientHydration() (e.g. from appConfig.providers) or use
defer blocks with hydrate triggers without hydration providers configured.

In these testing scenarios, there is no serialized server state in
TransferState. As a result, Angular emitted spurious warnings:
- NG0505: warning that client hydration was requested but no serialized info was found.
- NG0508: warning that incremental hydration is not enabled for @defer hydrate triggers.

This commit introduces an internal IS_TESTING token, provided by TestBedCompiler
and BrowserTestingModule, which suppresses these warnings in test environments.

Fixes angular#62053
@JeanMeche
JeanMeche force-pushed the fix/hydration-test-warning branch from 66908e0 to d42979a Compare November 11, 2026 22:39
@JeanMeche
JeanMeche marked this pull request as ready for review November 11, 2026 23:32

@thePunderWoman thePunderWoman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JeanMeche JeanMeche added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NG0505 warning on tests when client hydration enabled

2 participants