@@ -128,6 +128,49 @@ describe("atom-react", () => {
128128
129129 expect ( screen . getByTestId ( "loading" ) ) . toBeInTheDocument ( )
130130 } )
131+
132+ test ( "suspense subscriptions are isolated per registry" , async ( ) => {
133+ const atom = Atom . make < Result . Result < string > > ( Result . initial ( ) )
134+ const firstRegistry = Registry . make ( )
135+ const secondRegistry = Registry . make ( )
136+
137+ function TestComponent ( { id } : { readonly id : string } ) {
138+ const value = useAtomSuspense ( atom ) . value
139+ return < div data-testid = { `${ id } -value` } > { value } </ div >
140+ }
141+
142+ render (
143+ < RegistryContext . Provider value = { firstRegistry } >
144+ < Suspense fallback = { < div data-testid = "first-loading" > Loading...</ div > } >
145+ < TestComponent id = "first" />
146+ </ Suspense >
147+ </ RegistryContext . Provider >
148+ )
149+ render (
150+ < RegistryContext . Provider value = { secondRegistry } >
151+ < Suspense fallback = { < div data-testid = "second-loading" > Loading...</ div > } >
152+ < TestComponent id = "second" />
153+ </ Suspense >
154+ </ RegistryContext . Provider >
155+ )
156+
157+ act ( ( ) => {
158+ secondRegistry . set ( atom , Result . success ( "second" ) )
159+ } )
160+
161+ await waitFor ( ( ) => {
162+ expect ( screen . getByTestId ( "second-value" ) ) . toHaveTextContent ( "second" )
163+ } )
164+ expect ( screen . getByTestId ( "first-loading" ) ) . toBeInTheDocument ( )
165+
166+ act ( ( ) => {
167+ firstRegistry . set ( atom , Result . success ( "first" ) )
168+ } )
169+
170+ await waitFor ( ( ) => {
171+ expect ( screen . getByTestId ( "first-value" ) ) . toHaveTextContent ( "first" )
172+ } )
173+ } )
131174 } )
132175
133176 test ( "suspense error" , ( ) => {
0 commit comments