Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mobx-react-lite@4.0.2 observer not triggering component re-renders #3671

Closed
johnsonsu opened this issue Mar 27, 2023 · 18 comments
Closed

mobx-react-lite@4.0.2 observer not triggering component re-renders #3671

johnsonsu opened this issue Mar 27, 2023 · 18 comments
Labels

Comments

@johnsonsu
Copy link

The observer of mobx-react-lite seems to not trigger the wrapped component to re-renders after upgrading from mobx-react-lite@3.4.3 to mobx-react-lite@4.0.2.

Intended outcome:

When an observable value changes in the store, the observer component should re-render with the new value.

Actual outcome:

The observer component does not re-render when the observable value is updated.

How to reproduce the issue:

Code Sandbox: https://codesandbox.io/s/new-dawn-b2shxq?file=/src/App.js

Clicking "Push new element to data" button will push a new element to the store.data array using a store action.

However, the component does not re-render even thought store.data has been updated (see console logs).

If you change the mobx-react-lite version from 4.0.2 to 3.4.3 in the sandbox, the component will re-render when you click the "Push new element to data" button.

Screenshot 2023-03-27 at 7 49 23 PM

Versions

mobx-react-lite@4.0.2

@imjordanxd
Copy link

imjordanxd commented Mar 28, 2023

I've started using observer from mobx-react as a workaround also exists in mobx-react 8

@kenbankspeng
Copy link

@imjordanxd What version of mobx-react works for you? Because I think I'm seeing this same issue with mobx-react 8.0.0.

@kenbankspeng
Copy link

The sandbox provided in the issue also fails using the observer from mobx-react 8.0.0 but works using mobx-react 7.6.0. No doubt same root cause as in mobx-react-lite@4.0.2.

@hheimerd
Copy link

hheimerd commented Mar 28, 2023

If you turn off StrictMode, then the update works.
I also found this bug on the 8th version of mobx-react

@hheimerd
Copy link

I noticed that the update is working with strict mode, but only in the Production build. Most likely the problem with compatibility with the DEV mode in React

Working configuration:

"mobx": "^6.7.0",
"mobx-react": "^7.6.0"

non -working configuration:

"mobx": "^6.7.0",
"mobx-react": "^8.0.0",

@urugator
Copy link
Collaborator

urugator commented Mar 28, 2023

I identified the cause, but the fix seems to be non-trivial atm. The problem can also appear outside StrictMode (probably only when using concurrent features or when FinalizationRegistry isn't available), WIP PR #3673

@mweststrate
Copy link
Member

@urugator should we unpublish this major mobx-react / mobx-react-lite to avoid people taking it in production unawares until fixed?

@urugator
Copy link
Collaborator

@mweststrate Yea, probably. Atm I can provide a "fix", where everything basically works, bot not as intended - it won't use a global state version - however it's actually NOT using global version even now, because there was a pretty stupid typo:
https://github.com/mobxjs/mobx/pull/3673/files#diff-6b93715e19eb9119588dbe2af609a132062e61484d0d3de41b9e32e2d4a4ad5cL30-R30
And turned out switching to global version for some reason breaks interoperability with mobx-react or class components in general, dunno, have to investigate further, probably not sooner than over the weekend.

@urugator
Copy link
Collaborator

urugator commented Mar 28, 2023

Found the problem - observable state/props/context setters increment global state version during render. Don't know about a solution yet.

@evoyy
Copy link

evoyy commented Mar 29, 2023

mobx-react v8.0.0 broke my apps. I wrap my app in StrictMode in development. If I remove StrictMode, it all works again. I already pushed another app to production but StrictMode is disabled in production so I dodged a bullet there.

@mweststrate
Copy link
Member

mweststrate commented Mar 29, 2023 via email

@mweststrate
Copy link
Member

Reverted latest tag back to mobx-react@7.6.0 / mobx-react-lite@3.4.3, and deprecated the newer majors.

@urugator urugator mentioned this issue Mar 31, 2023
@LoveMeWithoutAll
Copy link

Has this issue been resolved? I'm waiting so long.

@mweststrate
Copy link
Member

mweststrate commented Apr 26, 2023 via email

@mweststrate
Copy link
Member

Should be fixed by mobx-react@9. Thanks for the patience!

@DeepakM02
Copy link

is it fixed? @mweststrate in mobx-react-lite?

@wuzinong
Copy link

Is it fixed?

@kubk
Copy link
Collaborator

kubk commented Jun 20, 2024

@wuzinong Feel free to create a separate issue with a reproduction. No need to bump old issues

@mobxjs mobxjs locked as resolved and limited conversation to collaborators Jun 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests