@@ -317,7 +317,7 @@ function defineTest(f: Fixture) {
317317 await expect ( locator ) . toContainText ( '[dep: 1]' )
318318 } )
319319
320- test ( 'shared hmr' , async ( { page } ) => {
320+ test ( 'shared hmr basic ' , async ( { page } ) => {
321321 await page . goto ( f . url ( ) )
322322 await waitForHydration ( page )
323323 await using _ = await expectNoReload ( page )
@@ -329,9 +329,6 @@ function defineTest(f: Fixture) {
329329 await expect ( page . getByTestId ( 'test-hmr-shared-client' ) ) . toContainText (
330330 '(shared1, shared2)' ,
331331 )
332- await expect ( page . getByTestId ( 'test-hmr-shared-atomic' ) ) . toContainText (
333- 'ok (test-shared)' ,
334- )
335332
336333 // Test 1: Component HMR (shared1.tsx)
337334 const editor1 = f . createEditor ( 'src/routes/hmr-shared/shared1.tsx' )
@@ -372,28 +369,35 @@ function defineTest(f: Fixture) {
372369 await expect ( page . getByTestId ( 'test-hmr-shared-client' ) ) . toContainText (
373370 '(shared1, shared2)' ,
374371 )
372+ } )
375373
376- // Test 3: Atomic updates (atomic/shared.tsx)
377- // This tests if server/client updates are atomic or if there can be temporary mismatches
378- const editor3 = f . createEditor ( 'src/routes/hmr-shared/atomic/shared.tsx' )
379- editor3 . edit ( ( s ) => s . replace ( 'test-shared' , 'test-shared-edit' ) )
374+ // for this use case to work, server refetch/render and client hmr needs to applied atomically
375+ // at the same time. Next.js doesn't seem to support this either.
376+ // https://github.com/hi-ogawa/reproductions/tree/main/next-rsc-hmr-shared-module
377+ test ( 'shared hmr not atomic' , async ( { page } ) => {
378+ await page . goto ( f . url ( ) )
379+ await waitForHydration ( page )
380+ await expect ( page . getByTestId ( 'test-hmr-shared-atomic' ) ) . toContainText (
381+ 'ok (test-shared)' ,
382+ )
380383
381- // The atomic test should either:
382- // 1. Update atomically and show "ok (test-shared-edit)" immediately
383- // 2. Show a temporary error if updates are not atomic, then recover
384- await expect ( async ( ) => {
385- const text = await page
386- . getByTestId ( 'test-hmr-shared-atomic' )
387- . textContent ( )
388- // Should eventually show either the updated value or recover from error
389- expect ( text ) . toMatch ( / o k \( t e s t - s h a r e d - e d i t \) | E r r o r B o u n d a r y c a u g h t / )
390- } ) . toPass ( { timeout : 5000 } )
391-
392- // Wait a bit longer to see if it recovers to the correct state
393- await page . waitForTimeout ( 1000 )
384+ // non-atomic update causes an error
385+ const editor = f . createEditor ( 'src/routes/hmr-shared/atomic/shared.tsx' )
386+ editor . edit ( ( s ) => s . replace ( 'test-shared' , 'test-shared-edit' ) )
387+ await expect ( page . getByTestId ( 'test-hmr-shared-atomic' ) ) . toContainText (
388+ 'ErrorBoundary' ,
389+ )
390+
391+ await page . reload ( )
394392 await expect ( page . getByText ( 'ok (test-shared-edit)' ) ) . toBeVisible ( )
395393
396- editor3 . reset ( )
394+ // non-atomic update causes an error
395+ editor . reset ( )
396+ await expect ( page . getByTestId ( 'test-hmr-shared-atomic' ) ) . toContainText (
397+ 'ErrorBoundary' ,
398+ )
399+
400+ await page . reload ( )
397401 await expect ( page . getByText ( 'ok (test-shared)' ) ) . toBeVisible ( )
398402 } )
399403 } )
0 commit comments