[BUG] React component doesn't connect to Overmind
SergeiKalachev opened this issue · 1 comments
Hello @christianalfoni
There is a bug that happens in specific conditions, component does not connect to overmind and does not react on state changes.
Background and problem
I updated overmind packages to the latest versions:
"overmind": "28.0.1",
"overmind-react": "29.0.1",
Migrated codebase according to the migration guide.
While testing I noticed that <Header />
component does not render icons after logging-in:
In the devtools I see that <Header />
isn't connected even though I have useOvermindState
and some state used inside render function:
The only functionality-relevant change is removing onInitialize
and creating new action called onInitializeOvermind
. After some digging I discovered conditions in which bug appear:
- Setting boolean flag to
false
insideonInitializeOvermind
- Accessing boolean flag in component via
useOvermindState
hook.
const Component1 = () => {
const { someBooleanValue } = useOvermindState();
return (<div>{String(someBooleanValue)}</div>)
}
- Running action that updates boolean to
true
inside function component's body, e.g
const Component2 = () => {
const { setToTrue } = useOvermindActions();
setToTrue();
return (<div>Some text</div>)
}
In such case Component1
won't connect to overmind and will ignore any changes to someBooleanValue
.
Reproducible examples
CodeSandbox number one has an old version of overmind with onInitialize
where everything is working as expected (Press Toggle
to see changes): https://codesandbox.io/s/overmind-connect-issue-old-working-0jm9w?file=/src/FinishLoginOnMount.tsx
Codesandbox is the same code migrated according to the guide. Component does not connect to overmind (Toggle
changes value in state but component doesn't care): https://codesandbox.io/s/overmind-connect-issue-60u5w
Expected behavior
I would expect the same behavior as in older version of overmind 27.0.0
. Component should connect anyway, doesn't matter how I call actions (inside useEffect or in function component's body) and whether I change flag inside initializeOvermind.
I hope it helps. @christianalfoni Will you have a chance to look at it?
Hi @SergeiKalachev and thanks so much for diving into it! I will take another round of Overmind related fixes and will check this one first! 😄