From 4bd25a0d4ab24db0094a6ea7435ec6c9a83f411b Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 22 Aug 2025 23:24:00 +0300 Subject: [PATCH] chore(react): use different injection mechanism --- apps/client/src/widgets/react/hooks.tsx | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx index dfaa029d0..82fe5545e 100644 --- a/apps/client/src/widgets/react/hooks.tsx +++ b/apps/client/src/widgets/react/hooks.tsx @@ -417,17 +417,27 @@ export function useNoteBlob(note: FNote | null | undefined): [ FBlob | null | un export function useLegacyWidget(widgetFactory: () => BasicWidget, { noteContext }: { noteContext?: NoteContext; } = {}) { + const ref = useRef(null); const widget = useMemo(widgetFactory, []); const parentComponent = useContext(ParentComponent); + useEffect(() => { + if (!ref.current) return; + + const $container = $(ref.current); + $container.empty(); + widget.render().appendTo($container); + + if (noteContext && widget instanceof NoteContextAwareWidget) { + console.log("Injecting note context", noteContext); + widget.setNoteContextEvent({ noteContext }); + widget.activeContextChangedEvent({ noteContext }); + } + }, [ widget ]); + if (parentComponent) { parentComponent.child(widget); - } + } - if (noteContext && widget instanceof NoteContextAwareWidget) { - console.log("Inject!"); - widget.setNoteContextEvent({ noteContext }); - } - - return + return
} \ No newline at end of file