mirror of
https://github.com/penpot/penpot.git
synced 2026-08-01 19:06:18 +00:00
🐛 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:
parent
0779c9ca61
commit
e730e9ee64
@ -214,10 +214,11 @@
|
|||||||
(mf/use-effect
|
(mf/use-effect
|
||||||
deps
|
deps
|
||||||
(fn []
|
(fn []
|
||||||
(let [sub (->> stream (rx/subs! on-subscribe))]
|
(when stream
|
||||||
#(do
|
(let [sub (->> stream (rx/subs! on-subscribe))]
|
||||||
(rx/dispose! sub)
|
#(do
|
||||||
(when on-dispose (on-dispose))))))))
|
(rx/dispose! sub)
|
||||||
|
(when on-dispose (on-dispose)))))))))
|
||||||
|
|
||||||
;; https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state
|
;; https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state
|
||||||
;; FIXME: replace with rumext
|
;; FIXME: replace with rumext
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user