Skip to content

Commit 6822af0

Browse files
committed
Current behavior of HMR to page with new bundler runtime
1 parent eeff555 commit 6822af0

File tree

5 files changed

+114
-0
lines changed

5 files changed

+114
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use client'
2+
// requires
3+
import * as React from 'react'
4+
5+
export default function RuntimeChangesNewRuntimeFunctionalityPage() {
6+
React.useEffect(() => {}, [])
7+
return <div data-testid="new-runtime-functionality-page" />
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Link from 'next/link'
2+
3+
export default function RuntimeChangesPage() {
4+
return (
5+
<Link href="/bundler-runtime-changes/new-runtime-functionality">
6+
Click me
7+
</Link>
8+
)
9+
}

Diff for: test/development/app-hmr/app/favicon.ico

14.7 KB
Binary file not shown.

Diff for: test/development/app-hmr/hmr.test.ts

+73
Original file line numberDiff line numberDiff line change
@@ -214,5 +214,78 @@ describe(`app-dir-hmr`, () => {
214214
it('should have no unexpected action error for hmr', async () => {
215215
expect(next.cliOutput).not.toContain('Unexpected action')
216216
})
217+
218+
it('can navigate cleanly to a page that requires a change in the Webpack runtime', async () => {
219+
// This isn't a very accurate test since the Webpack runtime is somewhat an implementation detail.
220+
// To ensure this is still valid, check the `*/webpack.*.hot-update.js` network response content when the navigation is triggered.
221+
// If there is new functionality added, the test is still valid.
222+
// If not, the test doesn't cover anything new.
223+
// TODO: Enforce console.error assertions or MPA navigation assertions in all tests instead.
224+
const browser = await next.browser('/bundler-runtime-changes')
225+
await browser.eval('window.__TEST_NO_RELOAD = true')
226+
227+
await browser
228+
.elementByCss('a')
229+
.click()
230+
.waitForElementByCss('[data-testid="new-runtime-functionality-page"]')
231+
232+
const logs = await browser.log()
233+
if (process.env.TURBOPACK) {
234+
// FIXME: logging "rebuilding" multiple times instead of closing it of with "done in"
235+
// Should just not branch here and have the same logs as Webpack.
236+
expect(logs).toEqual(
237+
expect.arrayContaining([
238+
{
239+
message: '[Fast Refresh] rebuilding',
240+
source: 'log',
241+
},
242+
{
243+
message: '[Fast Refresh] rebuilding',
244+
source: 'log',
245+
},
246+
{
247+
message: '[Fast Refresh] rebuilding',
248+
source: 'log',
249+
},
250+
])
251+
)
252+
expect(logs).not.toEqual(
253+
expect.arrayContaining([
254+
{
255+
message: expect.stringContaining('[Fast Refresh] done in'),
256+
source: 'log',
257+
},
258+
])
259+
)
260+
} else {
261+
// TODO: Should assert on all logs but these are cluttered with logs from our test utils (e.g. playwright tracing or webdriver)
262+
expect(logs).toEqual(
263+
expect.arrayContaining([
264+
{
265+
message: '[Fast Refresh] rebuilding',
266+
source: 'log',
267+
},
268+
{
269+
message: expect.stringContaining('[Fast Refresh] done in'),
270+
source: 'log',
271+
},
272+
])
273+
)
274+
expect(logs).toEqual(
275+
expect.arrayContaining([
276+
expect.objectContaining({
277+
source: 'error',
278+
}),
279+
])
280+
)
281+
}
282+
if (process.env.TURBOPACK) {
283+
// No MPA navigation triggered
284+
expect(await browser.eval('window.__TEST_NO_RELOAD')).toEqual(true)
285+
} else {
286+
// MPA navigation triggered
287+
expect(await browser.eval('window.__TEST_NO_RELOAD')).toEqual(undefined)
288+
}
289+
})
217290
})
218291
})

Diff for: test/development/app-hmr/tsconfig.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2017",
4+
"lib": ["dom", "dom.iterable", "esnext"],
5+
"allowJs": true,
6+
"skipLibCheck": true,
7+
"strict": false,
8+
"noEmit": true,
9+
"incremental": true,
10+
"module": "esnext",
11+
"esModuleInterop": true,
12+
"moduleResolution": "node",
13+
"resolveJsonModule": true,
14+
"isolatedModules": true,
15+
"jsx": "preserve",
16+
"plugins": [
17+
{
18+
"name": "next"
19+
}
20+
]
21+
},
22+
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
23+
"exclude": ["node_modules"]
24+
}

0 commit comments

Comments
 (0)