I observed that above error is thrown by 2nd widget and 1st widget on the page renders properly. For example lets say I developed SampleWidgetOne and SampleWidgetTwo and I don’t see this error if I use anyone of the widget multiple times. But if I use both widgets on same page then this error comes.
I debugged the issue and observed that this error is coming from wherever go.Diagram is used in 2nd widget. Not sure why this problem is coming from 2nd widget and this works fine from widget one that is on the same page. Any help is appreciated.
Note: This error thrown during runtime and not on compile time
So for one type of widget you say you can have multiple instances on a page, but when you try to use a second type of widget it causes that error which is not very helpful because it is missing the error message. I don’t suppose you could find out what the error message actually is? Maybe set a breakpoint somewhere in mxui.js?
My guess is that the second widget is loading the GoJS library a second time. Doing so can cause subtle problems. See if the second widget is trying to load the library even though it doesn’t need to.
I also guessed second widget is trying to reload the gojs one more time. Is there a way to avoid this programmatically or using gojs. I won’t be able to debug the mxui.js because its Mendix framework script and don’t have access to it
On further debugging, I am able to see below warning. Looks like the problem is related to creating the same object in the global scope multiple times. do you have any recommendation to fix this issue?
WARNING: a `go` object on the root object is already defined. version: 2.2.14, replaced with version: 2.2.14 Error: WARNING: a `go` object on the root object is already defined. version: 2.2.14, replaced with version: 2.2.14
Don’t load the GoJS library multiple times. Not only is that wasteful in terms of bandwidth and processing time and memory usage, but it may also result in some obscure errors when any objects created before the second load interact with any objects created after the second load.
I understand but these are two separate widgets and they are built and packaged separately. I think the Mendix widget framework automatically loads all the npm packages that are part of the widget when each widget is loaded on a page. I don’t have a control over it. This issue is not coming with any other npm packages that are used in the widget. Do you have any recommendations or workarounds on how to avoid this multiple load issues?
If you comment out the first kind of widget using a diagram, does the second kind of widget work by itself, even if there are multiple copies of it? I would want to confirm that it’s the presence of both kinds of widgets together at the same time that causes the error.
Ah, it turns out that when we detect the repeated load, we do throw an Error. If the loading system doesn’t handle that well, I can see how that would cause a problem. We’ll consider changing it to just call console.log with that warning message in the next release.