-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Labels
Description
Intended outcome:
Render a component wrapped in observer
once.
Actual outcome:
Component wrapped in observer
made two renders.
How to reproduce the issue:
Repro:
- Next.js v14 with bug (mobx-react-lite@4.0.5): https://codesandbox.io/p/devbox/mobx-react-lite-render-twice-q2qpk5
- Next.js v14 without bug (mobx-react-lite@3.4.3): https://codesandbox.io/p/devbox/mobx-react-lite-render-once-vjzpw9
- Create next application
- Install latest
mobx
andmobx-react-lite
- Set
reactStrictMode: false
in next.config.js - Add Child component to Index page
import { enableStaticRendering, observer } from "mobx-react-lite";
enableStaticRendering(typeof window === "undefined");
const ChildObserver = observer(function Child() {
console.log("Hello world");
return <div>Test</div>;
});
export default function Index() {
return <ChildObserver />;
}
Result:
If downgrade mobx-react-lite
to 3.4.3
:
I also tried to reproduce this bug with a pure react application, but everything works fine there (with 4.0.5 and 3.4.3 versions).
If build and run the application, the bug remains.
Versions
next@14.1.0
mobx-react-lite@4.0.5