@@ -104,31 +104,20 @@ export function useObservable<T = unknown>(observableId: string, source: Observa
104104 return observable . immutableStatus ;
105105 } , [ observable ] ) ;
106106
107- // `useSyncExternalStore` requires a third argument when the tree is rendered on a
108- // server or hydrated; without it React throws "Missing getServerSnapshot, which is
109- // required for server-rendered content" and the surrounding subtree falls back to
110- // client rendering.
107+ // The third argument is required for server-rendered and hydrating trees; without it
108+ // React throws "Missing getServerSnapshot" and the subtree falls back to client rendering.
111109 //
112- // This applies on React 18 and up. Below that, `use-sync-external-store/shim` ignores the
113- // third argument on the server as well as the client, so both shapes render identically
114- // and nothing here regresses. It also does nothing for it.
110+ // It deliberately does not return `observable.immutableStatus` the way `getSnapshot` does:
111+ // `preloadedObservables` is a `globalThis` cache keyed only by `observableId`, so a server
112+ // shares it across concurrent requests, and seeding from it would render one request's data
113+ // into another's HTML. Every field below comes from `config`, the caller's input on this
114+ // render. `firstValuePromise` is the one exception, and it resolves without a value.
115115 //
116- // This deliberately does NOT return `observable.immutableStatus` the way `getSnapshot`
117- // does. `preloadedObservables` is a `globalThis` cache keyed only by `observableId`, so
118- // on a server it is shared by every concurrent request. Seeding the server snapshot from
119- // it would let one request render data another request fetched for the same path.
116+ // Note the `as ObservableStatus<T>` cast hides a missing `firstValuePromise` from both
117+ // `tsc` and the tests; a server-side `.then(...)` would throw.
120118 //
121- // So no field below carries data across requests: `status`, `hasEmitted` and `data` come
122- // from `config`, which is the caller's own input on this render. `firstValuePromise` does
123- // read the shared `observable`, but it is a `Promise<void>` that resolves without a value,
124- // so it discloses nothing. It is not optional on `ObservableStatus`, and the
125- // `as ObservableStatus<T>` cast below means neither `tsc` nor the tests would notice if it
126- // were dropped: a caller doing `status.firstValuePromise.then(...)` on the server would
127- // just throw.
128- //
129- // The result is memoized per component instance because React compares the value it
130- // returns across renders, and a fresh object each time is what triggers the
131- // "The result of getServerSnapshot should be cached" error.
119+ // Memoized per instance because React compares the returned value across renders, and a
120+ // fresh object each time triggers "The result of getServerSnapshot should be cached".
132121 const serverSnapshotRef = React . useRef < ObservableStatus < T > | undefined > ( undefined ) ;
133122 const getServerSnapshot = React . useCallback < ( ) => ObservableStatus < T > > ( ( ) => {
134123 if ( serverSnapshotRef . current === undefined ) {
@@ -145,10 +134,8 @@ export function useObservable<T = unknown>(observableId: string, source: Observa
145134 }
146135
147136 return serverSnapshotRef . current ;
148- // `config.initialData` and `config.startWithValue` are read above but deliberately left
149- // out of the dependency array. Callers routinely pass a fresh `config` literal on every
150- // render, so including them would rebuild this callback constantly, and the ref means
151- // the value is computed once per component instance regardless.
137+ // `config` fields are read above but kept out of the deps: callers routinely pass a
138+ // fresh literal each render, and the ref computes the value once per instance anyway.
152139 // eslint-disable-next-line react-hooks/exhaustive-deps
153140 } , [ observable , hasInitialData ] ) ;
154141
0 commit comments