Skip to content

Commit e6c7898

Browse files
committed
fix(core): fixes issue with factory bind lazily referencing its enhanced self
1 parent a180a81 commit e6c7898

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/core/src/bind/connectFactoryObservable.test.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
merge,
1010
EMPTY,
1111
NEVER,
12+
noop,
1213
} from "rxjs"
1314
import { renderHook, act as actHook } from "@testing-library/react-hooks"
1415
import {
@@ -830,6 +831,22 @@ describe("connectFactoryObservable", () => {
830831

831832
subscription.unsubscribe()
832833
})
834+
835+
it("does not crash when the observable lazily references its enhanced self", () => {
836+
const [, obs$] = bind(
837+
(key: number) => defer(() => obs$(key)).pipe(take(1)),
838+
(key) => key,
839+
)
840+
841+
let error = null
842+
obs$(1)
843+
.subscribe(noop, (e: any) => {
844+
error = e
845+
})
846+
.unsubscribe()
847+
848+
expect(error).toBeNull()
849+
})
833850
})
834851
})
835852
})

packages/core/src/internal/share-latest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const shareLatest = <T>(
5050
},
5151
)
5252
emitIfEmpty()
53-
if (subscription.closed) subscription = null
53+
if (subscription && subscription.closed) subscription = null
5454
} else {
5555
innerSub = subject.subscribe(subscriber)
5656
if (currentValue !== EMPTY_VALUE) {

0 commit comments

Comments
 (0)