Skip to content

Commit

Permalink
fix: unsynchronized useSyncExternalStore snapshots with server
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrytavern committed Feb 13, 2024
1 parent 58d4328 commit 98c5b77
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/thirty-beans-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"mobx-react-lite": patch
---

fix #3826: components make two renders because of the different state of the snapshots
5 changes: 1 addition & 4 deletions packages/mobx-react-lite/src/useObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -98,7 +95,7 @@ export function useObserver<T>(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
Expand Down

0 comments on commit 98c5b77

Please sign in to comment.