diff --git a/.changeset/thirty-beans-dress.md b/.changeset/thirty-beans-dress.md new file mode 100644 index 000000000..89f09d2d5 --- /dev/null +++ b/.changeset/thirty-beans-dress.md @@ -0,0 +1,5 @@ +--- +"mobx-react-lite": patch +--- + +fix #3826: components make two renders because of the different state of the snapshots diff --git a/packages/mobx-react-lite/src/useObserver.ts b/packages/mobx-react-lite/src/useObserver.ts index bacc48a10..886073467 100644 --- a/packages/mobx-react-lite/src/useObserver.ts +++ b/packages/mobx-react-lite/src/useObserver.ts @@ -5,9 +5,6 @@ import { isUsingStaticRendering } from "./staticRendering" import { observerFinalizationRegistry } from "./utils/observerFinalizationRegistry" import { useSyncExternalStore } from "use-sync-external-store/shim" -// Required by SSR when hydrating #3669 -const getServerSnapshot = () => {} - // Do not store `admRef` (even as part of a closure!) on this object, // otherwise it will prevent GC and therefore reaction disposal via FinalizationRegistry. type ObserverAdministration = { @@ -98,7 +95,7 @@ export function useObserver(render: () => T, baseComponentName: string = "obs // Both of these must be stable, otherwise it would keep resubscribing every render. adm.subscribe, adm.getSnapshot, - getServerSnapshot + adm.getSnapshot ) // render the original component, but have the