Skip to content

mobx-react-lite component wrapped in observer renders twice in latest Next.js #3826

@dmitrytavern

Description

@dmitrytavern

Intended outcome:

Render a component wrapped in observer once.

Actual outcome:

Component wrapped in observer made two renders.

How to reproduce the issue:
Repro:

  1. Create next application
  2. Install latest mobx and mobx-react-lite
  3. Set reactStrictMode: false in next.config.js
  4. 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:

image

If downgrade mobx-react-lite to 3.4.3:

image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions