patternfly / react-topology

MIT License
9 stars 18 forks source link

Allow to isolate mobx global state #130

Closed jotak closed 5 months ago

jotak commented 6 months ago

Describe the problem As discussed on chat, there's a problem when two versions of react-topology / mobx are used from different components, which can be the case with the openshift console and some console plugins: when there's a version mismatch, mobx throws the following error:

Error:      Error: [mobx] There are multiple, different versions of MobX active. Make sure MobX is loaded only once or use `configure({ isolateGlobalState: true })`
    at s (mobx.module.js:16:15)
    at a (mobx.module.js:11:5)
    at mobx.module.js:1490:17
    at o (VM360 netflow-traffic:1:414)
    at VM360 netflow-traffic:1:787

Since it is not always an option to have the same versions, the solution would be to configure mobx as mentioned in the error, with configure({ isolateGlobalState: true })

The best two options I can see so far would be either to do this configuration directly in react-topology, or to provide a public function that does this configuration, to be called by the consumers, which avoids them to have to add an explicit dependency to mobx when they don't use it otherwise. I think the former option makes more sense as I don't see reasons to share react-topology internal mobx states across instances, but perhaps I'm missing use cases ; anyway, these two options are not mutually exclusive: state isolation could be enabled by default, with a public function available to turn it off.

How do you reproduce the problem?

If you're familiar with openshift development you can deploy an ocp 4.15 cluster + network observability operator 1.4 for instance: you will see the error in the JS console when opening the openshift console. Let me know if you need any help installing network observability operator. I'm also happy to test any build in my environment.

Expected behavior

No error thrown by mobx.

Is this issue blocking you?

It's possible to call this configure({ isolateGlobalState: true }) from the consumers side, however it is far from ideal because it forces us to add an explicit dependency to mobx that we wouldn't use otherwise, forcing us to know about the react-topology internals & implementation details.

What is your environment?

What is your product and what release date are you targeting?

Network Observability operator (and openshift console is also affected on its own when network observability plugin is installed) No strong opinion on the release date target since there is a temporary workaround

github-actions[bot] commented 5 months ago

:tada: This issue has been resolved in version 5.3.0-prerelease.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: