Commit 56f6145f authored by Luke Sandberg's avatar Luke Sandberg

Add JSON HMR regression test for #91768

Tests that Turbopack HMR correctly propagates consecutive JSON file edits
across three scenarios: server component with static import, client component
with static import, and server component with dynamic import() using template
literals. Each test patches the JSON file multiple times to catch the regression
where only the first edit triggers HMR.
Co-Authored-By: 's avatarClaude <noreply@anthropic.com>
parent eb44c314
import JsonClient from '../../components/json-client'
export default function ClientPage() {
return (
<div>
<JsonClient />
</div>
)
}
export default async function DynamicPage() {
const locale = 'messages'
const data = (await import(`../../data/${locale}.json`)).default
return (
<div>
<p id="dynamic-value">{data.hello}</p>
</div>
)
}
import { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
import config from '../data/config.json'
export default function Page() {
return (
<div>
<p id="server-value">{config.value}</p>
</div>
)
}
'use client'
import config from '../data/config.json'
export default function JsonClient() {
return <p id="client-value">{config.value}</p>
}
import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
describe('json-hmr', () => {
const { next, isTurbopack, isNextDev } = nextTestSetup({
files: __dirname,
})
// This regression only affects Turbopack dev mode (Server Fast Refresh)
const itTurbopackDev = isTurbopack && isNextDev ? it : it.skip
describe('server component with static JSON import', () => {
itTurbopackDev(
'reflects multiple consecutive JSON edits via HMR',
async () => {
const browser = await next.browser('/')
// Verify initial value
await retry(async () => {
const text = await browser.elementByCss('#server-value').text()
expect(text).toBe('initial')
})
const originalContent = await next.readFile('data/config.json')
try {
// First edit — should update
await next.patchFile(
'data/config.json',
JSON.stringify({ value: 'first-edit' })
)
await retry(async () => {
const text = await browser.elementByCss('#server-value').text()
expect(text).toBe('first-edit')
})
// Second edit — this is the regression: subsequent edits are ignored
await next.patchFile(
'data/config.json',
JSON.stringify({ value: 'second-edit' })
)
await retry(async () => {
const text = await browser.elementByCss('#server-value').text()
expect(text).toBe('second-edit')
})
// Third edit — ensure continued HMR functionality
await next.patchFile(
'data/config.json',
JSON.stringify({ value: 'third-edit' })
)
await retry(async () => {
const text = await browser.elementByCss('#server-value').text()
expect(text).toBe('third-edit')
})
} finally {
await next.patchFile('data/config.json', originalContent)
}
}
)
})
describe('client component with static JSON import', () => {
itTurbopackDev(
'reflects multiple consecutive JSON edits via HMR',
async () => {
const browser = await next.browser('/client')
// Verify initial value
await retry(async () => {
const text = await browser.elementByCss('#client-value').text()
expect(text).toBe('initial')
})
const originalContent = await next.readFile('data/config.json')
try {
// First edit
await next.patchFile(
'data/config.json',
JSON.stringify({ value: 'client-first' })
)
await retry(async () => {
const text = await browser.elementByCss('#client-value').text()
expect(text).toBe('client-first')
})
// Second edit — regression: subsequent edits ignored
await next.patchFile(
'data/config.json',
JSON.stringify({ value: 'client-second' })
)
await retry(async () => {
const text = await browser.elementByCss('#client-value').text()
expect(text).toBe('client-second')
})
} finally {
await next.patchFile('data/config.json', originalContent)
}
}
)
})
describe('server component with dynamic import()', () => {
itTurbopackDev(
'reflects multiple consecutive JSON edits via HMR for dynamically imported JSON',
async () => {
const browser = await next.browser('/dynamic')
// Verify initial value
await retry(async () => {
const text = await browser.elementByCss('#dynamic-value').text()
expect(text).toBe('world')
})
const originalContent = await next.readFile('data/messages.json')
try {
// First edit
await next.patchFile(
'data/messages.json',
JSON.stringify({ hello: 'dynamic-first' })
)
await retry(async () => {
const text = await browser.elementByCss('#dynamic-value').text()
expect(text).toBe('dynamic-first')
})
// Second edit — regression: subsequent edits ignored
await next.patchFile(
'data/messages.json',
JSON.stringify({ hello: 'dynamic-second' })
)
await retry(async () => {
const text = await browser.elementByCss('#dynamic-value').text()
expect(text).toBe('dynamic-second')
})
} finally {
await next.patchFile('data/messages.json', originalContent)
}
}
)
})
})
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}
module.exports = nextConfig
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment