🐛 Fix subscribe to undefined stream error in use-stream hook (#8633)

Add a nil guard before subscribing to the stream in the use-stream
hook. When a nil/undefined stream is passed (e.g., from a conditional
expression or timing edge case during React rendering), the subscribe
call on undefined causes a TypeError. The guard ensures we only
subscribe when the stream is defined.

Signed-off-by: Andrey Antukh <niwi@niwi.nz>
This commit is contained in:
Andrey Antukh
2026-03-17 10:06:16 +01:00
committed by GitHub
parent 0779c9ca61
commit e730e9ee64

View File

@@ -214,10 +214,11 @@
(mf/use-effect
deps
(fn []
(let [sub (->> stream (rx/subs! on-subscribe))]
#(do
(rx/dispose! sub)
(when on-dispose (on-dispose))))))))
(when stream
(let [sub (->> stream (rx/subs! on-subscribe))]
#(do
(rx/dispose! sub)
(when on-dispose (on-dispose)))))))))
;; https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state
;; FIXME: replace with rumext