mirror of
https://github.com/logseq/logseq.git
synced 2026-05-28 14:39:48 +00:00
fix(property/value): icon-row hook crash when picker opens
icon-row was modified earlier in this branch (c85e8e5588) to add
< rum/reactive db-mixins/query mixins so a model/sub-block call could
refresh the entity reactively. Those mixins turn rum/defc into a class
component, but the component still called hooks/use-effect! — which
internally calls React.useEffect and is only valid inside a function
component's body. The result: an Invalid-hook-call exception every time
icon-row rendered, surfacing as a "Something wrong, please try again"
toast when the user clicked to add a page icon.
Convert rum/defc → rum/defcs (class component, takes state as first
arg) and replace the hooks/use-effect! cleanup with a :will-unmount
lifecycle. The original effect returned a cleanup that restored the
cursor when `editing?` was true on unmount; lifecycle-based unmount is
the natural equivalent.
Verified live: page reloads, picker can render icon-row without
throwing — zero hook errors in console.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -96,13 +96,16 @@
|
||||
(or (> (count selected-blocks) 1)
|
||||
(seq view-selected-blocks))))
|
||||
|
||||
(rum/defc icon-row < rum/reactive db-mixins/query
|
||||
[block editing?]
|
||||
(hooks/use-effect!
|
||||
(fn []
|
||||
(fn []
|
||||
(when editing?
|
||||
(editor-handler/restore-last-saved-cursor!)))))
|
||||
(rum/defcs icon-row < rum/reactive db-mixins/query
|
||||
{:will-unmount (fn [state]
|
||||
;; The class mixins (rum/reactive + db-mixins/query) make
|
||||
;; this a class component, so hooks/use-effect! is invalid
|
||||
;; here. Restore the cursor on unmount via lifecycle instead.
|
||||
(let [[_ editing?] (:rum/args state)]
|
||||
(when editing?
|
||||
(editor-handler/restore-last-saved-cursor!)))
|
||||
state)}
|
||||
[_state block editing?]
|
||||
;; Subscribe to a fresh entity reference. Without `model/sub-block`, the
|
||||
;; `block` prop is a stale snapshot — in-picker writes (e.g. shape changes
|
||||
;; from the customize band) update the entity but the snapshot held by this
|
||||
|
||||
Reference in New Issue
Block a user