Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(react): use different injection mechanism
Elian Doran4bd25a0d4ab2
diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsxindex dfaa029d09..82fe5545e5 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 | unexport function useLegacyWidget(widgetFactory: () => BasicWidget, { noteContext }: {noteContext?: NoteContext;} = {}) {+ const ref = useRef<HTMLDivElement>(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 <RawHtml html={widget.render()} />+ return <div ref={ref} />}\ No newline at end of file