mirror of
https://github.com/zadam/trilium.git
synced 2026-01-04 05:34:30 +01:00
fix(widget): prevent unnecessary refresh by checking note context change
This commit is contained in:
parent
267a37d3bd
commit
b936a35b63
@ -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 ]);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user