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

React 18: observer not working with <React.StrictMode> #3395

Closed
urugator opened this issue May 13, 2022 Discussed in #3393 · 3 comments · Fixed by #3434 or #3428
Closed

React 18: observer not working with <React.StrictMode> #3395

urugator opened this issue May 13, 2022 Discussed in #3393 · 3 comments · Fixed by #3434 or #3428
Labels

Comments

@urugator
Copy link
Collaborator

See #3393 (reply in thread) for explanation and fix proposal.

Discussed in #3393

Originally posted by acataluddi May 11, 2022
Hi guys,

I was wondering whether any of you experienced any issue with class-based React components and MobX when the <React.StrictMode> is enabled. I've created a quick CodeSandbox Example to explain the issue.

There is a very basic MobX observable store and the following function which triggers the enableService() action:

window.setTimeout(() => {
  store.enableService().then();
}, 1500);

The strange thing is that while functional components get updated as expected (the first "service is enabled string) the class-based one is not (the green one):

immagine

However, by removing the <React.StrictMode> wrapper, everything works as expected:

// Doesn't work
root.render(
  <StrictMode>
    <App />
  </StrictMode>
);

// Works
root.render(
    <App />
);

The same code was working without problems in older version of React even with the <React.StrictMode> enabled.

Is it possible there is any bug or it's just me missing something obvious?

Thanks,
Adriano

@urugator
Copy link
Collaborator Author

Should be fixed in mobx-react@7.5.1

@fltonii
Copy link

fltonii commented Jun 30, 2022

Hey @urugator, can this be downported to v6 as well? I'm having this issue in my codebase and don't want to bump the version from 6 to 7 for compatibility issues.

@mweststrate
Copy link
Member

mweststrate commented Jun 30, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants