Skip to content

Commit 7809d8f

Browse files
committed
Add test for Server Components HMR after navigating to page with Edge runtime
1 parent 2621746 commit 7809d8f

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

test/development/app-hmr/hmr.test.ts

+76
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { retry, waitFor } from 'next-test-utils'
33

44
const envFile = '.env.development.local'
55

6+
const isPPREnabledByDefault = process.env.__NEXT_EXPERIMENTAL_PPR === 'true'
7+
68
describe(`app-dir-hmr`, () => {
79
const { next } = nextTestSetup({
810
files: __dirname,
@@ -54,6 +56,80 @@ describe(`app-dir-hmr`, () => {
5456
}
5557
})
5658

59+
it('should update server components after navigating to a page with a different runtime', async () => {
60+
const envContent = await next.readFile(envFile)
61+
62+
const browser = await next.browser('/env/node')
63+
await browser.loadPage(`${next.url}/env/edge`)
64+
await browser.eval('window.__TEST_NO_RELOAD = true')
65+
66+
await next.patchFile(envFile, 'MY_DEVICE="ipad"')
67+
68+
try {
69+
const logs = await browser.log()
70+
71+
if (process.env.TURBOPACK) {
72+
await retry(async () => {
73+
const fastRefreshLogs = logs.filter((log) => {
74+
return log.message.startsWith('[Fast Refresh]')
75+
})
76+
// FIXME: 3+ "rebuilding" but single "done" is confusing.
77+
// There may actually be more "rebuilding" but not reliably.
78+
// To ignore this flakiness, we just assert on subset matches.
79+
// Once the bug is fixed, each "rebuilding" should be paired with a "done in" exactly.
80+
expect(fastRefreshLogs).toEqual(
81+
expect.arrayContaining([
82+
{ source: 'log', message: '[Fast Refresh] rebuilding' },
83+
{ source: 'log', message: '[Fast Refresh] rebuilding' },
84+
{
85+
source: 'log',
86+
message: expect.stringContaining('[Fast Refresh] done in '),
87+
},
88+
{ source: 'log', message: '[Fast Refresh] rebuilding' },
89+
])
90+
)
91+
})
92+
} else {
93+
await retry(
94+
async () => {
95+
const fastRefreshLogs = logs.filter((log) => {
96+
return log.message.startsWith('[Fast Refresh]')
97+
})
98+
// FIXME: Should be either a single "rebuilding"+"done" or the last "rebuilding" should be followed by "done"
99+
expect(fastRefreshLogs).toEqual([
100+
{ source: 'log', message: '[Fast Refresh] rebuilding' },
101+
{ source: 'log', message: '[Fast Refresh] rebuilding' },
102+
{
103+
source: 'log',
104+
message: expect.stringContaining('[Fast Refresh] done in '),
105+
},
106+
{ source: 'log', message: '[Fast Refresh] rebuilding' },
107+
])
108+
},
109+
// Very slow Hot Update for some reason.
110+
// May be related to receiving 3 rebuild events but only one finish event
111+
5000
112+
)
113+
}
114+
const envValue = await browser.elementByCss('p').text()
115+
const mpa = await browser.eval('window.__TEST_NO_RELOAD === undefined')
116+
// Flaky sometimes in Webpack:
117+
// A. misses update and just receives `{ envValue: 'mac', mpa: false }`
118+
// B. triggers error on server resulting in MPA: `{ envValue: 'ipad', mpa: true }` and server logs: ⨯ [TypeError: Cannot read properties of undefined (reading 'polyfillFiles')] ⨯ [TypeError: Cannot read properties of null (reading 'default')]
119+
// A is more common than B.
120+
expect({ envValue, mpa }).toEqual({
121+
envValue:
122+
isPPREnabledByDefault && !process.env.TURBOPACK
123+
? // FIXME: Should be 'ipad' but PPR+Webpack swallows the update reliably
124+
'mac'
125+
: 'ipad',
126+
mpa: false,
127+
})
128+
} finally {
129+
await next.patchFile(envFile, envContent)
130+
}
131+
})
132+
57133
it('should update server components pages when env files is changed (nodejs)', async () => {
58134
const envContent = await next.readFile(envFile)
59135
const browser = await next.browser('/env/node')

0 commit comments

Comments
 (0)