Skip to content

Conversation

rainerhahnekamp
Copy link
Contributor

withState, signalState, and withLinkedState now pass a Signal instead of the original WritableSignal to the DeepSignal.

This prevents accidental misuse where consumers (e.g. ngModel or other APIs with incompatible types) could assert WritableSignal and write directly into the state.

Closes #4958

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

const person = signalState({ title: 'Title'});
(person.title as WritableSignal<string>).set('Hallo'); <-- direct access to state

Closes #4958

What is the new behavior?

Will throw an error if set is called because the Signal is readonly.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

`withState`, `signalState`, and `withLinkedState` now pass a `Signal`
instead of the original `WritableSignal` to the DeepSignal.

This prevents accidental misuse where consumers (e.g. `ngModel` or other
APIs with incompatible types) could assert `WritableSignal` and write
directly into the state.

Closes ngrx#4958
Copy link

netlify bot commented Sep 19, 2025

Deploy Preview for ngrx-site-v19 ready!

Name Link
🔨 Latest commit 2cf0c83
🔍 Latest deploy log https://app.netlify.com/projects/ngrx-site-v19/deploys/68cde2c0d443900008327242
😎 Deploy Preview https://deploy-preview-4959--ngrx-site-v19.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

netlify bot commented Sep 19, 2025

Deploy Preview for ngrx-io canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit 2cf0c83
🔍 Latest deploy log https://app.netlify.com/projects/ngrx-io/deploys/68cde2c0d84ac200089d9ab7

@markostanimirovic
Copy link
Member

Let's merge this in v21 to prevent unintentional breaking changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Signal Store Allows Writing to Read-Only Signals
2 participants