Skip to content

Build your personal knowledge base with Trilium Notes

fix(widget): prevent unnecessary refresh by checking note context change

lzingab936a35b63a7
diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx
index d04fbe60b8..f0019ac467 100644
--- a/apps/client/src/widgets/react/hooks.tsx
+++ b/apps/client/src/widgets/react/hooks.tsx
@@ -669,10 +669,17 @@ export function useLegacyWidget<T extends BasicWidget>(widgetFactory: () => T, {
}, [ renderedWidget ]);
// Inject the note context - this updates the existing widget without recreating it.
+ // We check if the context actually changed to avoid double refresh when the event system
+ // also delivers activeContextChanged to the widget through component tree propagation.
useEffect(() => {
if (noteContext && widget instanceof NoteContextAwareWidget) {
- widget.setNoteContextEvent({ noteContext });
- widget.activeContextChangedEvent({ noteContext });
+ // Only trigger refresh if the context actually changed.
+ // The event system may have already updated the widget, in which case
+ // widget.noteContext will already equal noteContext.
+ if (widget.noteContext !== noteContext) {
+ widget.setNoteContextEvent({ noteContext });
+ widget.activeContextChangedEvent({ noteContext });
+ }
}
}, [ noteContext, widget ]);