Unverified Commit 04e9933b authored by Sam Poder's avatar Sam Poder Committed by GitHub

[turbopack] Fix HMR for dynamic imports evaluated from layouts (#97213)

Tbh, I don't really understand this code path but this appears to fix
the bug. This includes `referenced_output_assets` in `async_chunks`. The
bug report went away when `experimental.turbopackServerFastRefresh` was
disabled.

The agent's explanation (more for entertainment):

<img width="967" height="290" alt="Screenshot 2026-08-11 at 5 07 46 pm"
src="https://github.com/user-attachments/assets/e57425be-e4e9-44b8-a6eb-8e93d04b37f0"
/>

Closes https://github.com/vercel/next.js/issues/97206
parent 10725074
import { ReactNode } from 'react'
export default async function LocaleLayout({
children,
params,
}: {
children: ReactNode
params: Promise<{ locale: string }>
}) {
const { locale } = await params
const messages = (await import(`../../messages/${locale}.json`)).default
return (
<>
<p id="subtitle">{messages.subtitle}</p>
{children}
</>
)
}
export default function Page() {
return <main id="page">page</main>
}
import { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
describe('layout-dynamic-import-hmr', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should pick up edits to a file that is dynamically imported from a layout', async () => {
const $ = await next.render$('/en')
expect($('#subtitle').text()).toBe('original')
await next.patchFile(
'messages/en.json',
JSON.stringify({ subtitle: 'updated' }, null, 2),
async () => {
await retry(async () => {
const $updated = await next.render$('/en')
expect($updated('#subtitle').text()).toBe('updated')
})
}
)
})
})
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}
module.exports = nextConfig
......@@ -237,6 +237,7 @@ impl EcmascriptBuildNodeEntryChunk {
EcmascriptBuildNodeChunkListContent::new(
*self.chunking_context,
*self.other_chunks,
*self.referenced_output_assets,
*self.references,
)
}
......
......@@ -58,6 +58,7 @@ impl EcmascriptBuildNodeChunkListContent {
pub async fn new(
chunking_context: ResolvedVc<NodeJsChunkingContext>,
chunks: ResolvedVc<OutputAssets>,
referenced_assets: ResolvedVc<OutputAssets>,
references: ResolvedVc<OutputAssetsReferences>,
) -> Result<Vc<Self>> {
let output_root = chunking_context.output_root().owned().await?;
......@@ -66,12 +67,24 @@ impl EcmascriptBuildNodeChunkListContent {
// imported chunks. `inner=false`: only follow Reference edges (async
// loaders), not Asset-adjacent files like source maps that aren't part
// of the module graph and can't be hot-reloaded.
//
// `referenced_assets` covers async chunks that were already expanded by
// the caller (e.g. chunks reachable from concatenated chunk groups).
// They must be tracked here too, otherwise an edit inside one of them
// produces no chunk list update at all.
let async_chunks = expand_output_assets(
references
referenced_assets
.await?
.iter()
.copied()
.map(ExpandOutputAssetsInput::Reference),
.map(ExpandOutputAssetsInput::Asset)
.chain(
references
.await?
.iter()
.copied()
.map(ExpandOutputAssetsInput::Reference),
),
false,
)
.await?;
......
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