Draft
Conversation
In order for resources to allow caching in SSR context (eg in the TransferState), resource need to be able to set their value synchronously. If the resource value is not set synchronously, the resource will be in in a "loading" state which is responsible for destroying the server-hydrated resolved DOM.
cd92c68 to
39f6641
Compare
Contributor
This commit adds a `transferCacheKey` option to enable easy caching for `resource`/ `rxResource`. By caching resource data we make sure that resources are not in a loading state during hydration on the client side and responsible for destroying server hydrated DOM. fixes angular#62897
39f6641 to
6af5943
Compare
alan-agius4
reviewed
Mar 3, 2026
| equal?: ValueEqualityFn<T>; | ||
| injector?: Injector; | ||
| params?: (ctx: ResourceParamsContext) => R; | ||
| transferCacheKey?: (params: R) => StateKey<T>; |
Contributor
There was a problem hiding this comment.
- Does this implementation result in duplicate transfer state entries (HTTP Client andResource)?
- Consider
idmaybe instead oftransferCacheKey? - Manual key management places a heavy burden on the developer to ensure global uniqueness. To improve the DX, we should explore internal ID generation instead of it being part of the API or something similar to React’s
useIdor Vue’s composition helpers. Relying on users to manual create unique cache-key feels like a "foot-gun" especially in big organizations; we should ideally handle key construction internally to prevent collisions, this was one of the reasons that we always avoided providing such option in the HTTP transfer cache.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

On top of #67382
feat(core): add ability to cache resources for SSR
This commit adds a
transferCacheKeyoption to enable easy caching forresource/rxResource.By caching resource data we make sure that resources are not in a loading state during hydration on the client side and responsible for destroying server hydrated DOM.
fixes #62897