You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed an issue with my Breadcrumbs widget breaking on any tab/split. It seemed to only update the most recently opened pane. So I did some digging... It seems because SplitNoteContainer uses a widgetFactory (https://github.com/zadam/trilium/blob/master/src/public/app/layouts/desktop_layout.js#L120) all the widgets inside that function have separate instantiations per split/tab except for the note-detail-pane custom widgets since they are expected to export an instance of the widget. This would mean that these widgets are "attached" to the latest split/tab only and previous ones are left behind which matches what I was experiencing with my widget.
So basically checking if the exported widget was actually the full class with prototype as opposed to an instance and instantiating it if needed that way each call of the widget factory got a new instance.
Then in my widget I just made the parentWidget getter be static so it would pass the bundler's check. Then only exported the class itself instead of an instance.
const position = api.startNote.getLabelValue("breadcrumbsPosition") ?? "";
class BreadcrumbWidget extends api.NoteContextAwareWidget {
get position() {return position === "bottom" ? 100 : position === "top" ? 1 : 50;}
- get parentWidget() {return (this.position === 100 || this.position === 1) ? "center-pane" : "note-detail-pane";}+ static get parentWidget() {return (position === "bottom" || position === "top") ? "center-pane" : "note-detail-pane";}
... // rest of the widget
}
-module.exports = new BreadcrumbWidget();+module.exports = BreadcrumbWidget;
And this worked out perfectly and allowed the separate instances of the widget to function independently and correctly on each note/split/tab.
I'm sure there are better ways of fixing this, but this was the first that came to mind as proof-of-concept that was still backward-compatible.
Error logs
No response
The text was updated successfully, but these errors were encountered:
Hmm, yeah ... this was designed before there were splits and thus before the possibility of having two note contexts visible at the same time.
I applied your patch and updated the wiki. The changes are backwards compatible, just the recommended style for new widgets changes so that they work better with splits.
Trilium Version
0.60.4
What operating system are you using?
Windows
What is your setup?
Local + server sync
Operating System Version
Windows 10 v1909
Description
I noticed an issue with my Breadcrumbs widget breaking on any tab/split. It seemed to only update the most recently opened pane. So I did some digging... It seems because
SplitNoteContainer
uses awidgetFactory
(https://github.com/zadam/trilium/blob/master/src/public/app/layouts/desktop_layout.js#L120) all the widgets inside that function have separate instantiations per split/tab except for thenote-detail-pane
custom widgets since they are expected to export an instance of the widget. This would mean that these widgets are "attached" to the latest split/tab only and previous ones are left behind which matches what I was experiencing with my widget.To test this out locally I modified the
get
ofWidgetsByParent
(https://github.com/zadam/trilium/blob/master/src/public/app/services/bundle.js#L55) to look more like this:So basically checking if the exported widget was actually the full class with
prototype
as opposed to an instance and instantiating it if needed that way each call of the widget factory got a new instance.Then in my widget I just made the
parentWidget
getter bestatic
so it would pass the bundler's check. Then only exported the class itself instead of an instance.And this worked out perfectly and allowed the separate instances of the widget to function independently and correctly on each note/split/tab.
I'm sure there are better ways of fixing this, but this was the first that came to mind as proof-of-concept that was still backward-compatible.
Error logs
No response
The text was updated successfully, but these errors were encountered: