[Regression] Initializing an Angular form in a signalStore via a state factory no longer works in @ngrx/signals 19
Closed this issue · 1 comments
g-drouard commented
Which @ngrx/* package(s) are the source of the bug?
signals
Minimal reproduction of the bug/regression with instructions
- Create a new Angular 19 app with
ng new xxx
for example - Install
ngrx/signals
19.0.0
withng add @ngrx/signals@latest
for example - Add a new signal store with a
FormControl
in thewithState
via a state factory() => state
instead of a standard state - Run app with
npm start
and go tohttp://localhost:4200/
with a browser (Chrome for example)
app.component.ts
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrl: './app.component.scss',
providers: [TestStore]
})
export class AppComponent {
store = inject(TestStore);
}
test.store.ts
Works with @ngrx/signals
18.1.1
and 19.0.0
:
import { signalStore, withState } from '@ngrx/signals';
import { FormControl } from '@angular/forms';
export const TestStore = signalStore(withState({ formControl: new FormControl('test') }))
Works with @ngrx/signals
18.1.1
but does not work with 19.0.0
:
import { signalStore, withState } from '@ngrx/signals';
import { FormControl } from '@angular/forms';
export const TestStore = signalStore(withState(() => ({ formControl: new FormControl('test') })))
Runtime error call stack :
TypeError: Cannot assign to read only property 'microTask' of object '[object Object]'
at _ZoneDelegate._updateTaskCount (C:\Sites\ng-19-sandbox\node_modules\zone.js\fesm2015\zone-node.js:432:38)
at ZoneImpl._updateTaskCount (C:\Sites\ng-19-sandbox\node_modules\zone.js\fesm2015\zone-node.js:264:34)
at ZoneImpl.runTask (C:\Sites\ng-19-sandbox\node_modules\zone.js\fesm2015\zone-node.js:177:30)
at drainMicroTaskQueue (C:\Sites\ng-19-sandbox\node_modules\zone.js\fesm2015\zone-node.js:581:35)
TypeError: Cannot assign to read only property 'microTask' of object '[object Object]'
at _ZoneDelegate._updateTaskCount (C:\Sites\ng-19-sandbox\node_modules\zone.js\fesm2015\zone-node.js:432:38)
at ZoneImpl._updateTaskCount (C:\Sites\ng-19-sandbox\node_modules\zone.js\fesm2015\zone-node.js:264:34)
at ZoneImpl.runTask (C:\Sites\ng-19-sandbox\node_modules\zone.js\fesm2015\zone-node.js:177:30)
at drainMicroTaskQueue (C:\Sites\ng-19-sandbox\node_modules\zone.js\fesm2015\zone-node.js:581:35)
Error: microTask 'Promise.then': can not transition to 'running', expecting state 'scheduled', was 'scheduling'.
at ZoneTask._transitionTo (C:\Sites\ng-19-sandbox\node_modules\zone.js\fesm2015\zone-node.js:510:23)
at ZoneImpl.runTask (C:\Sites\ng-19-sandbox\node_modules\zone.js\fesm2015\zone-node.js:150:38)
at drainMicroTaskQueue (C:\Sites\ng-19-sandbox\node_modules\zone.js\fesm2015\zone-node.js:581:35)
C:\Sites\ng-19-sandbox\node_modules\zone.js\fesm2015\zone-node.js:432
const next = (counts[type] = prev + count);
^
TypeError: Cannot assign to read only property 'microTask' of object '[object Object]'
at _ZoneDelegate._updateTaskCount (C:\Sites\ng-19-sandbox\node_modules\zone.js\fesm2015\zone-node.js:432:38)
at ZoneImpl._updateTaskCount (C:\Sites\ng-19-sandbox\node_modules\zone.js\fesm2015\zone-node.js:264:34)
at ZoneImpl.scheduleTask (C:\Sites\ng-19-sandbox\node_modules\zone.js\fesm2015\zone-node.js:217:22)
at ZoneImpl.scheduleMicroTask (C:\Sites\ng-19-sandbox\node_modules\zone.js\fesm2015\zone-node.js:225:25)
at eval (C:\Sites\ng-19-sandbox\node_modules\zone.js\fesm2015\zone-node.js:958:33)
at process.proto.<computed> (C:\Sites\ng-19-sandbox\node_modules\zone.js\fesm2015\zone-node.js:913:24)
at maybeReadMore (node:internal/streams/readable:860:13)
at addChunk (node:internal/streams/readable:578:3)
at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
at Readable.push (node:internal/streams/readable:392:5)
Node.js v22.11.0
Expected behavior
Same behavior as version 18.1.1
Versions of NgRx, Angular, Node, affected browser(s) and operating system(s)
Angular : 19.0.x
@ngrx/signals : 19.0.0
Node : 22.11.0
Other information
No response
I would be willing to submit a PR to fix this issue
- Yes
- No
rainerhahnekamp commented
@g-drouard that looks very similar to #4650
You should not put objects in the state that are getting mutated by the framework.
That being said, we're looking into options to allow you disable the freezing: #4645
I'm closing this one because it already handled in #4645, okay?