File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -131,21 +131,25 @@ export function useSnapshot<T extends object>(
131131 [ proxyObject ] ,
132132 )
133133 const lastSnapshot = useRef < Snapshot < T > > ( undefined )
134- let inRender = true
134+ const subscribed = useRef ( false )
135135 const currSnapshot = useSyncExternalStore (
136136 useCallback (
137137 ( callback ) => {
138+ subscribed . current = true
138139 const unsub = subscribe ( proxyObject , callback , notifyInSync )
139140 callback ( ) // Note: do we really need this?
140- return unsub
141+ return ( ) => {
142+ unsub ( )
143+ subscribed . current = false
144+ }
141145 } ,
142146 [ proxyObject , notifyInSync ] ,
143147 ) ,
144148 ( ) => {
145149 const nextSnapshot = snapshot ( proxyObject )
146150 try {
147151 if (
148- ! inRender &&
152+ subscribed . current &&
149153 lastSnapshot . current &&
150154 ! isChanged (
151155 lastSnapshot . current ,
@@ -164,9 +168,6 @@ export function useSnapshot<T extends object>(
164168 } ,
165169 ( ) => snapshot ( proxyObject ) ,
166170 )
167- // TODO how could we bypass this?
168- // eslint-disable-next-line react-hooks/immutability
169- inRender = false
170171 useLayoutEffect ( ( ) => {
171172 lastSnapshot . current = currSnapshot
172173 } )
You can’t perform that action at this time.
0 commit comments