René's URL Explorer Experiment


Title: Signal for TransferState data · Issue #58128 · angular/angular · GitHub

Open Graph Title: Signal for TransferState data · Issue #58128 · angular/angular

X Title: Signal for TransferState data · Issue #58128 · angular/angular

Description: Which @angular/* package(s) are relevant/related to the feature request? core Description When creating an app that uses Signals and TransferState, it was found that we had to do a fair amount of boilerplate for this to work with persist...

Open Graph Description: Which @angular/* package(s) are relevant/related to the feature request? core Description When creating an app that uses Signals and TransferState, it was found that we had to do a fair amount of b...

X Description: Which @angular/* package(s) are relevant/related to the feature request? core Description When creating an app that uses Signals and TransferState, it was found that we had to do a fair amount of b...

Opengraph URL: https://github.com/angular/angular/issues/58128

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Signal for TransferState data","articleBody":"### Which @angular/* package(s) are relevant/related to the feature request?\n\ncore\n\n### Description\n\nWhen creating an app that uses Signals and TransferState, it was found that we had to do a fair amount of boilerplate for this to work with persisting the signal state to TransferState and then loading it again on the browser: \n\n- Create a state key with `makeStateKey` that requires a new constant with duplicated type and string key\n- Inject TransferState\n- Create a signal property\n- Set the signal on the server once data is loaded\n- Set the TransferState data keys for each signal\n- Set the signal on the browser from TransferState data\n\nIt would be handy if there is a signal that wraps TransferState and can remove some of this boilerplate to just:\n\n- Create a `transferStateSignal` property, giving it the key and initial value\n- Set the signal on the server once data is loaded\n- (Signal is automatically loaded on the browser from TransferState data)\n\nNo state key, TransferState injection, or setting/loading TransferState is needed.\n\n### Proposed solution\n\nHere is a quick example of a prototype of what this could look like:\n\n```ts\nimport { inject, makeStateKey, signal, TransferState, WritableSignal } from \"@angular/core\";\n\nexport function transferStateSignal\u003cT>(key: string, initialValue: T): WritableSignal\u003cT> {\n    const stateKey = makeStateKey\u003cT>(key);\n    const transferState = inject(TransferState);\n\n    const value = transferState.hasKey(stateKey)\n        ? transferState.get(stateKey, initialValue)\n        : initialValue;\n\n    const signalValue = signal(value);\n\n    const signalProxy = new Proxy(signalValue, {\n        // override `set` method of signalValue to set on TransferState\n        get: (target, prop, receiver) => {\n            if (prop === 'set') {\n                return (newValue: T) => {\n                    transferState.set(stateKey, newValue);\n                    target.set(newValue);\n                };\n            }\n            return Reflect.get(target, prop, receiver);\n        }\n    });\n\n    return signalProxy;\n}\n```\n\nExample usage:\n```ts\nimport { isPlatformBrowser, isPlatformServer } from '@angular/common';\nimport { ChangeDetectionStrategy, Component, computed, Inject, PLATFORM_ID } from '@angular/core';\nimport { transferStateSignal } from '../transferStateSignal';\n\n@Component({\n    selector: 'app-transfer-state-signal',\n    standalone: true,\n    imports: [],\n    template: `\n    \u003ch1>TransferStateSignal Example\u003c/h1>\n    \u003cp>String: {{dataString()}}\u003c/p>\n    \u003cp>Number: {{dataNumber()}}\u003c/p>\n    \u003cp>Boolean: {{dataBoolean()}}\u003c/p>\n    \u003cp>Object.key: {{dataObject().key}}\u003c/p>\n    \u003cp>Computed: {{computedNumber()}}\u003c/p>\n    `,\n    changeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class TransferStateSignalComponent {\n    readonly dataString = transferStateSignal\u003cstring>('dataString', 'Hello, World!');\n    readonly dataNumber = transferStateSignal\u003cnumber>('dataNumber', 42);\n    readonly dataBoolean = transferStateSignal\u003cboolean>('dataBoolean', true);\n    readonly dataObject = transferStateSignal\u003c{ key: string }>('dataObject', { key: 'value' });\n\n    readonly computedNumber = computed\u003cnumber>(() => this.dataNumber() * 100);\n\n    constructor(\n        @Inject(PLATFORM_ID) private readonly platformId: Object\n    ) { }\n\n    ngOnInit(): void {\n        if (isPlatformServer(this.platformId)) {\n            // pretend we load data on the server here, then set in signals for SSR,\n            // and no need to set on TransferState as it's done in transferStateSignal\n            this.dataString.set('Hello, Server!');\n            this.dataNumber.set(24);\n            this.dataBoolean.set(false);\n            this.dataObject.set({ key: 'server' });\n        } else if (isPlatformBrowser(this.platformId)) {\n            setInterval(() => {\n                this.dataNumber.set(this.dataNumber() + 1);\n            }, 1000);\n        }\n    }\n}\n```\n\nCompare this to what is required to do this without `transferStateSignal`:\n\n```ts\nimport { isPlatformBrowser, isPlatformServer } from '@angular/common';\nimport { ChangeDetectionStrategy, Component, computed, Inject, makeStateKey, PLATFORM_ID, signal, TransferState } from '@angular/core';\n\n// duplicated effort of having to make a state key for each and ensure data types match\nconst dataStringKey = makeStateKey\u003cstring>('dataStringCurrent');\nconst dataNumberKey = makeStateKey\u003cnumber>('dataNumberCurrent');\nconst dataBooleanKey = makeStateKey\u003cboolean>('dataBooleanCurrent');\nconst dataObjectKey = makeStateKey\u003c{ key: string }>('dataObjectCurrent');\n\n@Component({\n    selector: 'app-current',\n    standalone: true,\n    imports: [],\n    template: `\n    \u003ch1>Current Example\u003c/h1>\n    \u003cp>String: {{dataString()}}\u003c/p>\n    \u003cp>Number: {{dataNumber()}}\u003c/p>\n    \u003cp>Boolean: {{dataBoolean()}}\u003c/p>\n    \u003cp>Object.key: {{dataObject().key}}\u003c/p>\n    \u003cp>Computed: {{computedNumber()}}\u003c/p>\n    `,\n    changeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class CurrentComponent {\n    readonly dataString = signal\u003cstring>('Hello, World!');\n    readonly dataNumber = signal\u003cnumber>(42);\n    readonly dataBoolean = signal\u003cboolean>(true);\n    readonly dataObject = signal\u003c{ key: string }>({ key: 'value' });\n\n    readonly computedNumber = computed\u003cnumber>(() => this.dataNumber() * 100);\n\n    constructor(\n        @Inject(PLATFORM_ID) private readonly platformId: Object,\n        private readonly transferState: TransferState, // extra import\n    ) { }\n\n    ngOnInit(): void {\n        if (isPlatformServer(this.platformId)) {\n            // pretend we load data on the server here, then set in signals for SSR\n            this.dataString.set('Hello, Server!');\n            this.dataNumber.set(24);\n            this.dataBoolean.set(false);\n            this.dataObject.set({ key: 'server' });\n\n            // duplicated effort of setting on TransferState\n            this.transferState.set(dataStringKey, this.dataString());\n            this.transferState.set(dataNumberKey, this.dataNumber());\n            this.transferState.set(dataBooleanKey, this.dataBoolean());\n            this.transferState.set(dataObjectKey, this.dataObject());\n        } else if (isPlatformBrowser(this.platformId)) {\n            // duplicated effort of getting from TransferState\n            this.dataString.set(this.transferState.get(dataStringKey, this.dataString()));\n            this.dataNumber.set(this.transferState.get(dataNumberKey, this.dataNumber()));\n            this.dataBoolean.set(this.transferState.get(dataBooleanKey, this.dataBoolean()));\n            this.dataObject.set(this.transferState.get(dataObjectKey, this.dataObject()));\n\n            setInterval(() => {\n                this.dataNumber.set(this.dataNumber() + 1);\n            }, 1000);\n        }\n    }\n}\n```\n\n### Alternatives considered\n\nWill consider creating this as a third-party OSS library if the Angular team is not interested in adding something like this to the framework.","author":{"url":"https://github.com/paulirwin","@type":"Person","name":"paulirwin"},"datePublished":"2024-10-08T22:43:30Z","url":"https://github.com/angular/angular/issues/58128"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:463e5c87-c7d4-644a-3e06-7f0217fa0fe8
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9A76:1CCECA:FC118B:1506C85:6B01E8C6
html-safe-nonce9029246b55082b3aeec9179d473ec3a7e6dced787760a502c7a31638a8dca91f
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QTc2OjFDQ0VDQTpGQzExOEI6MTUwNkM4NTo2QjAxRThDNiIsInZpc2l0b3JfaWQiOiIxMTY1NDg0NTkwNjg1NjEyMjMwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac360cb62f1d877703d7f86b26f2fed95048ed8eeab9fa27d66ab6f49a5d98e8e6
hovercard-subject-tagissue:2574354063
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/58128/issue_layout
twitter:imagehttps://opengraph.githubassets.com/25bac6f8197d6959c4a461891e15146cc491825b3eca0dc261ceec56296808e4/angular/angular/issues/58128
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/25bac6f8197d6959c4a461891e15146cc491825b3eca0dc261ceec56296808e4/angular/angular/issues/58128
og:image:altWhich @angular/* package(s) are relevant/related to the feature request? core Description When creating an app that uses Signals and TransferState, it was found that we had to do a fair amount of b...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamepaulirwin
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/angular/angular git https://github.com/angular/angular.git
octolytics-dimension-user_id139426
octolytics-dimension-user_loginangular
octolytics-dimension-repository_id24195339
octolytics-dimension-repository_nwoangular/angular
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id24195339
octolytics-dimension-repository_network_root_nwoangular/angular
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/angular/angular/issues/58128#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F58128
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F58128
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=angular%2Fangular
Reloadhttps://github.com/angular/angular/issues/58128
Reloadhttps://github.com/angular/angular/issues/58128
Reloadhttps://github.com/angular/angular/issues/58128
angularhttps://github.com/angular
angularhttps://github.com/angular/angular
Codehttps://github.com/angular/angular
Issues835 (835)https://github.com/angular/angular/issues
Pull requests143 (143)https://github.com/angular/angular/pulls
Discussionshttps://github.com/angular/angular/discussions
Actionshttps://github.com/angular/angular/actions
Projectshttps://github.com/angular/angular/projects
Security and quality40 (40)https://github.com/angular/angular/security
Insightshttps://github.com/angular/angular/insights
https://github.com/angular/angular
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/58128
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/58128
Enhancementhttps://github.com/angular/angular/issues?q=type:"Enhancement"
Signal for TransferState datahttps://github.com/angular/angular/issues/58128#top
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
area: serverIssues related to server-side renderinghttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20server%22
core: reactivityWork related to fine-grained reactivity in the core frameworkhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20reactivity%22
cross-cutting: signalshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22cross-cutting%3A%20signals%22
featureLabel used to distinguish feature request from other issueshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22feature%22
Backloghttps://github.com/angular/angular/milestone/82
https://github.com/paulirwin
paulirwinhttps://github.com/paulirwin
on Oct 8, 2024https://github.com/angular/angular/issues/58128#issue-2574354063
https://github.com/JeanMeche
JeanMechehttps://github.com/JeanMeche
on Oct 8, 2024https://github.com/angular/angular/issues/58128#issuecomment-2400993258
https://github.com/paulirwin
paulirwinhttps://github.com/paulirwin
on Oct 9, 2024https://github.com/angular/angular/issues/58128#issuecomment-2401042992
JeanMechehttps://github.com/JeanMeche
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
area: serverIssues related to server-side renderinghttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20server%22
cross-cutting: signalshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22cross-cutting%3A%20signals%22
on Oct 9, 2024https://github.com/angular/angular/issues/58128#event-14566937420
ngbothttps://github.com/apps/ngbot
needsTriagehttps://github.com/angular/angular/milestone/83
on Oct 9, 2024https://github.com/angular/angular/issues/58128#event-14566938557
JeanMechehttps://github.com/JeanMeche
core: reactivityWork related to fine-grained reactivity in the core frameworkhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20reactivity%22
on Oct 9, 2024https://github.com/angular/angular/issues/58128#event-14566939053
https://github.com/alan-agius4
alan-agius4https://github.com/alan-agius4
on Oct 9, 2024https://github.com/angular/angular/issues/58128#issuecomment-2402191348
alxhubhttps://github.com/alxhub
featureLabel used to distinguish feature request from other issueshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22feature%22
on Oct 9, 2024https://github.com/angular/angular/issues/58128#event-14573251764
ngbothttps://github.com/apps/ngbot
needsTriagehttps://github.com/angular/angular/milestone/83
Backloghttps://github.com/angular/angular/milestone/82
on Oct 9, 2024https://github.com/angular/angular/issues/58128#event-14573252312
https://github.com/paulirwin
paulirwinhttps://github.com/paulirwin
on Oct 9, 2024https://github.com/angular/angular/issues/58128#issuecomment-2402605982
https://github.com/paulirwin
paulirwinhttps://github.com/paulirwin
on Oct 9, 2024https://github.com/angular/angular/issues/58128#issuecomment-2402657782
https://github.com/eneajaho
eneajahohttps://github.com/eneajaho
on Oct 14, 2024https://github.com/angular/angular/issues/58128#issuecomment-2411134411
#58189https://github.com/angular/angular/pull/58189
https://github.com/JeanMeche
JeanMechehttps://github.com/JeanMeche
on Jun 19, 2026https://github.com/angular/angular/issues/58128#issuecomment-4755431672
JeanMechehttps://github.com/JeanMeche
not plannedhttps://github.com/angular/angular/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Anot-planned
on Jun 19, 2026https://github.com/angular/angular/issues/58128#event-26975547536
https://github.com/apps/angular-automatic-lock-bot
angular-automatic-lock-bothttps://github.com/apps/angular-automatic-lock-bot
on Jul 21, 2026https://github.com/angular/angular/issues/58128#issuecomment-5028780910
automatic conversation locking policyhttps://github.com/angular/angular/blob/f0fbced1c55bc8b8ed9df01cea99df42f3e7eae3/contributing-docs/auto-issue-locking.md
angular-automatic-lock-bothttps://github.com/apps/angular-automatic-lock-bot
on Jul 21, 2026https://github.com/angular/angular/issues/58128#event-28241649581
Sign up for freehttps://github.com/signup?return_to=https://github.com/angular/angular/issues/58128
Sign in to commenthttps://github.com/login?return_to=https://github.com/angular/angular/issues/58128
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
area: serverIssues related to server-side renderinghttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20server%22
core: reactivityWork related to fine-grained reactivity in the core frameworkhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20reactivity%22
cross-cutting: signalshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22cross-cutting%3A%20signals%22
featureLabel used to distinguish feature request from other issueshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22feature%22
Enhancementhttps://github.com/angular/angular/issues?q=type:"Enhancement"
BacklogNo due datehttps://github.com/angular/angular/milestone/82
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.