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
fix(right_pane): custom widgets not rendering after being expanded
Elian Dorane1df65adce14
diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsxindex d6b0db34c6..898e425ade 100644--- a/apps/client/src/widgets/react/hooks.tsx+++ b/apps/client/src/widgets/react/hooks.tsx@@ -605,11 +605,10 @@ export function useNoteBlob(note: FNote | null | undefined, componentId?: stringreturn blob;}-export function useLegacyWidget<T extends BasicWidget>(widgetFactory: () => T, { noteContext, containerClassName, containerStyle, noAttach }: {+export function useLegacyWidget<T extends BasicWidget>(widgetFactory: () => T, { noteContext, containerClassName, containerStyle }: {noteContext?: NoteContext;containerClassName?: string;containerStyle?: CSSProperties;- noAttach?: boolean;} = {}): [VNode, T] {const ref = useRef<HTMLDivElement>(null);const parentComponent = useContext(ParentComponent);@@ -632,13 +631,12 @@ export function useLegacyWidget<T extends BasicWidget>(widgetFactory: () => T, {// Attach the widget to the parent.useEffect(() => {- if (noAttach) return;const parentContainer = ref.current;if (parentContainer) {parentContainer.replaceChildren();renderedWidget.appendTo(parentContainer);}- }, [ renderedWidget, noAttach ]);+ });// Inject the note context.useEffect(() => {diff --git a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx b/apps/client/src/widgets/sidebar/RightPanelContainer.tsxindex fd339563ae..21d10cd993 100644--- a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx+++ b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx@@ -71,15 +71,26 @@ function useSplit(visible: boolean) {function CustomWidget({ originalWidget }: { originalWidget: LegacyRightPanelWidget }) {const containerRef = useRef<HTMLDivElement>(null);++ return (+ <RightPanelWidget+ id={originalWidget._noteId}+ title={originalWidget.widgetTitle}+ containerRef={containerRef}+ >+ <CustomWidgetContent originalWidget={originalWidget} />+ </RightPanelWidget>+ );+}++function CustomWidgetContent({ originalWidget }: { originalWidget: LegacyRightPanelWidget }) {const [ el ] = useLegacyWidget(() => {+ originalWidget.contentSized();+// Monkey-patch the original widget by replacing the default initialization logic.originalWidget.doRender = function doRender(this: LegacyRightPanelWidget) {- if (!containerRef.current) {- this.$widget = $("<div>");- return;- };- this.$widget = $(containerRef.current);- this.$body = this.$widget.find(".card-body");+ this.$widget = $("<div>");+ this.$body = this.$widget;const renderResult = this.doRenderBody();if (typeof renderResult === "object" && "catch" in renderResult) {this.initialized = renderResult.catch((e) => {@@ -91,14 +102,7 @@ function CustomWidget({ originalWidget }: { originalWidget: LegacyRightPanelWidg};return originalWidget;- }, {- noAttach: true});- return (- <RightPanelWidget- id={originalWidget._noteId}- title={originalWidget.widgetTitle}- containerRef={containerRef}- >{el}</RightPanelWidget>- );++ return el;}