GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf(core): tree-shake TransferState from resources without hydration by nigrosimone · Pull Request #72241 · angular/angular

Conversation

@nigrosimone

@nigrosimone nigrosimone commented Nov 28, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Every resource() and httpResource() calls injector.get(TransferState), also in apps without SSR. So TransferState and the read of the ng-state script are in the bundle, and the instance is created at runtime. On the client the state is read only with provideClientHydration() (CACHE_ACTIVE) or the HTTP transfer cache (CACHE_OPTIONS).

Now these providers give the TransferState lookup, and the resources use it on the client. On the server resource() keeps the direct lookup, which is removed from browser builds. Same pattern as 8993029. Both commits are needed: HttpResourceImpl extends ResourceImpl.

main.js without hydration, Angular 22.3.0: app with one resource() 149.19 kB -> 148.13 kB (43.53 -> 43.21 kB transferred), app like the http bundling test 134.10 kB -> 133.04 kB (38.94 -> 38.66 kB). The http golden drops TransferState, retrieveTransferredState and createDictionary.

Tests: new spec for the client without hydration (fails without the change), and a hydration spec that reads a resource from TransferState with provideClientHydration().

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@nigrosimone
perf(core): tree-shake TransferState from resource without hydration
9f65b73
On the client a resource reads TransferState only when hydration is enabled, so provideClientHydration now provides the lookup. Apps that use resource() without hydration no longer retain TransferState.
@angular-robot angular-robot Bot added area: performance Issues related to performance area: core Issues related to the framework runtime labels Nov 28, 2026
@ngbot ngbot Bot added this to the Backlog milestone Nov 28, 2026
@nigrosimone
nigrosimone marked this pull request as ready for review November 28, 2026 16:16
@pullapprove
pullapprove Bot requested a review from JeanMeche November 28, 2026 16:16
@nigrosimone
perf(http): tree-shake TransferState from httpResource without transf…
19ce7a1
…er cache

On the client httpResource() reads TransferState only when the HTTP transfer cache is enabled, so its provider now provides the lookup. With the resource() change, apps that use httpResource() without it no longer retain TransferState.
@nigrosimone nigrosimone changed the title perf(core): tree-shake TransferState from resource without hydration perf(core): tree-shake TransferState from resources without hydration Nov 28, 2026
@angular-robot angular-robot Bot added the area: common/http Issues related to HTTP and HTTP Client label Nov 28, 2026
SkyZeroZx
SkyZeroZx reviewed Nov 28, 2026
View reviewed changes
Comment thread packages/platform-browser/test/hydration_spec.ts
});

it(`should read resources from TransferState on the client`, () => {
globalThis['ngServerMode'] = undefined;

@SkyZeroZx SkyZeroZx Nov 28, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I'm unsure about this , Could we remove it ?
If we override globalThis here ( without restore it ) while running the test suite, it could fail or cause unexpected behavior in other tests.
Also I think the rest of test are enough

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

nigrosimone reacted with eyes emoji
All reactions
  • 👀 1 reaction

@nigrosimone nigrosimone Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks. The outer describe already resets it: beforeEach sets ngServerMode to true and afterEach sets it back to undefined, so nothing leaks to other tests. I would keep the test because it is the only one that covers the lookup provided by provideClientHydration(). Without it, a change in hydration.ts could stop resource from reading the SSR cache and no test would fail. I can move it into its own describe with an explicit save and restore if you prefer.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

SkyZeroZx reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@JeanMeche JeanMeche Awaiting requested review from JeanMeche
1 more reviewer
@SkyZeroZx SkyZeroZx SkyZeroZx left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

area: common/http Issues related to HTTP and HTTP Client area: core Issues related to the framework runtime area: performance Issues related to performance

Projects

None yet

Milestone

Backlog

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@nigrosimone @SkyZeroZx
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.