Skip to content

Commit 71a9d7f

Browse files
fix(signals): do not create nested signals for STATE_SIGNAL property (#4062)
1 parent 52e7dbd commit 71a9d7f

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

modules/signals/spec/signal-state.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ describe('signalState', () => {
5959
expect((state.user.firstName as any).y).toBe(undefined);
6060
});
6161

62+
it('does not modify STATE_SIGNAL', () => {
63+
const state = signalState(initialState);
64+
65+
expect((state[STATE_SIGNAL] as any).user).toBe(undefined);
66+
expect((state[STATE_SIGNAL] as any).foo).toBe(undefined);
67+
expect((state[STATE_SIGNAL] as any).numbers).toBe(undefined);
68+
expect((state[STATE_SIGNAL] as any).ngrx).toBe(undefined);
69+
});
70+
6271
it(
6372
'emits new values only for affected signals',
6473
testEffects((tick) => {

modules/signals/src/deep-signal.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isSignal, Signal, untracked } from '@angular/core';
1+
import { Signal, untracked } from '@angular/core';
22
import { selectSignal } from './select-signal';
33

44
export type DeepSignal<T> = Signal<T> &
@@ -14,11 +14,15 @@ export function toDeepSignal<T>(signal: Signal<T>): DeepSignal<T> {
1414

1515
return new Proxy(signal, {
1616
get(target: any, prop) {
17-
if (prop in value && !target[prop]) {
17+
if (!(prop in value)) {
18+
return target[prop];
19+
}
20+
21+
if (!target[prop]) {
1822
target[prop] = selectSignal(() => target()[prop]);
1923
}
2024

21-
return isSignal(target[prop]) ? toDeepSignal(target[prop]) : target[prop];
25+
return toDeepSignal(target[prop]);
2226
},
2327
});
2428
}

0 commit comments

Comments
 (0)