Skip to content

Commit

Permalink
fix: unsynchronized useSyncExternalStore snapshots with server (#3830)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrytavern committed Feb 14, 2024
1 parent 58d4328 commit b970cbb
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
@@ -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
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 b970cbb

Please sign in to comment.