Skip to content

Fix optional react-dom loading in mobx-react-lite#4670

Closed
cyphercodes wants to merge 1 commit into
mobxjs:mainfrom
cyphercodes:fix-mobx-react-lite-optional-react-dom
Closed

Fix optional react-dom loading in mobx-react-lite#4670
cyphercodes wants to merge 1 commit into
mobxjs:mainfrom
cyphercodes:fix-mobx-react-lite-optional-react-dom

Conversation

@cyphercodes

Copy link
Copy Markdown

Fixes #4663

Summary

  • Replace the static react-dom re-export in mobx-react-lite with a guarded optional load.
  • Fall back to the existing no-op batch scheduler when react-dom is unavailable.
  • Add a regression test that verifies mobx-react-lite can load when react-dom cannot be resolved.

Code change checklist

  • Added/updated unit tests
  • Updated /docs (not applicable: bug fix, no docs/API change)
  • Verified that there is no significant performance drop (not applicable to core MobX performance; ran targeted package checks and size test)

Verification

  • npm ci --ignore-scripts
  • npm -w mobx run build:test
  • npm -w mobx-react run build:test
  • npm -w mobx-react-lite run lint
  • npm -w mobx-react-lite run test:types
  • npm -w mobx-react-lite run build:test
  • npm -w mobx-react-lite test -- --runInBand
  • npm -w mobx-react-lite run test:size
  • npx prettier --check packages/mobx-react-lite/src/utils/reactBatchedUpdates.ts packages/mobx-react-lite/__tests__/optionalReactDom.test.ts
  • git diff --check
  • Built CJS smoke test with react-dom module loading blocked

@changeset-bot

changeset-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 76ad2c7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
mobx-react-lite Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cyphercodes cyphercodes force-pushed the fix-mobx-react-lite-optional-react-dom branch from feab5e9 to 76ad2c7 Compare June 9, 2026 16:15
@kubk

kubk commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Thank you for the PR. As described in the issue comments - the problem shouldn't be solved at all as React 18+ provides its own batching. Mobx v7 will drop React <=17 support: #4671

@kubk kubk closed this Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mobx-react-lite unconditionally imports react-dom even though it is optional in package.json

2 participants