mirror of
https://github.com/penpot/penpot.git
synced 2026-03-20 09:23:47 +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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user