Skip to content

Commit 5700a7b

Browse files
committed
fix: make sure internal subscriptions are leaned up when converting writable signals to an observable
1 parent 5c77644 commit 5700a7b

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

npm/angular-zoneless/src/mount.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,14 @@ function detectAndRegisterOutputSpyToSignal<T> (config: MountConfig<T>, componen
337337
// we will create a subscriber that will emit an event every time the value inside the signal changes. We only do this
338338
// if the signal is writable and not an input signal.
339339
if (isWritableSignal(componentValue) && !isInputSignal(componentValue)) {
340-
toObservable(componentValue, {
341-
// @ts-expect-error - monorepo clashing types between Angular 18 and Angular 21
342-
injector,
343-
}).subscribe((value) => {
344-
component[expectedChangeKey]?.emit(value)
345-
})
340+
activeInternalSubscriptions.push(
341+
toObservable(componentValue, {
342+
// @ts-expect-error - monorepo clashing types between Angular 18 and Angular 21
343+
injector,
344+
}).subscribe((value) => {
345+
component[expectedChangeKey]?.emit(value)
346+
}),
347+
)
346348
}
347349
}
348350
}

npm/angular/src/mount.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,13 @@ function detectAndRegisterOutputSpyToSignal<T> (config: MountConfig<T>, componen
369369
// we will create a subscriber that will emit an event every time the value inside the signal changes. We only do this
370370
// if the signal is writable and not an input signal.
371371
if (isWritableSignal(componentValue) && !isInputSignal(componentValue)) {
372-
toObservable(componentValue, {
373-
injector,
374-
}).subscribe((value) => {
375-
component[expectedChangeKey]?.emit(value)
376-
})
372+
activeInternalSubscriptions.push(
373+
toObservable(componentValue, {
374+
injector,
375+
}).subscribe((value) => {
376+
component[expectedChangeKey]?.emit(value)
377+
}),
378+
)
377379
}
378380
}
379381
}

0 commit comments

Comments
 (0)