diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx index d6b0db34c..898e425ad 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?: string return blob; } -export function useLegacyWidget(widgetFactory: () => T, { noteContext, containerClassName, containerStyle, noAttach }: { +export function useLegacyWidget(widgetFactory: () => T, { noteContext, containerClassName, containerStyle }: { noteContext?: NoteContext; containerClassName?: string; containerStyle?: CSSProperties; - noAttach?: boolean; } = {}): [VNode, T] { const ref = useRef(null); const parentComponent = useContext(ParentComponent); @@ -632,13 +631,12 @@ export function useLegacyWidget(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.tsx index fd339563a..21d10cd99 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(null); + + return ( + + + + ); +} + +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 = $("
"); - return; - }; - this.$widget = $(containerRef.current); - this.$body = this.$widget.find(".card-body"); + this.$widget = $("
"); + 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 ( - {el} - ); + + return el; }