Skip to content

Commit 1dd7f8a

Browse files
committed
test: tweak
1 parent d51ab93 commit 1dd7f8a

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

packages/plugin-rsc/e2e/basic.test.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/ok \(test-shared-edit\)|ErrorBoundary caught/)
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
})

packages/plugin-rsc/examples/basic/src/routes/hmr-shared/atomic/error-boundary.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default class ErrorBoundary extends React.Component<Props, State> {
2424
if (this.state.error) {
2525
return (
2626
<span>
27-
ERROR
27+
ErrorBoundary: {this.state.error.message}
2828
<button
2929
onClick={() => {
3030
this.setState({ error: null })

0 commit comments

Comments
 (0)