Skip to content

Commit 635f53f

Browse files
committed
chore: skip rolldown hmr for outside module graph
1 parent 27ad840 commit 635f53f

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

packages/vite/src/node/build.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,11 @@ async function buildEnvironment(
973973
}
974974

975975
server.watcher.on('change', async (file) => {
976+
// The playground/hmr test `plugin hmr remove custom events` need to skip the change of unused files.
977+
if (!bundle!.watchFiles.includes(file)) {
978+
return
979+
}
980+
976981
const startTime = Date.now()
977982
const hmrOutput = (await bundle!.generateHmrPatch([file]))!
978983
// TODO(underfin): rebuild at first could be work.

playground/hmr/__tests__/hmr.spec.ts

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ if (!isBuild) {
277277
await untilUpdated(() => el.textContent(), 'edited')
278278
})
279279

280+
// TODO(underfin): the customFile tests maybe make test hang.
281+
// The `customFile.js` is not inside module graph, it couldn't be seen also hasn't hmr.
282+
// Here only trigger hmr events.
280283
test('plugin hmr remove custom events', async () => {
281284
const el = await page.$('.toRemove')
282285
editFile('customFile.js', (code) => code.replace('custom', 'edited'))
@@ -342,6 +345,7 @@ if (!isBuild) {
342345
})
343346
}
344347

348+
// TODO(underfin): recheck it
345349
if (!process.env.VITE_TEST_FULL_BUNDLE_MODE) {
346350
test('not loaded dynamic import', async () => {
347351
await page.goto(viteTestUrl + '/counter/index.html', {
@@ -378,33 +382,35 @@ if (!isBuild) {
378382
btn = await page.$('button')
379383
expect(await btn.textContent()).toBe('Counter 1')
380384
})
385+
}
381386

382-
// #2255
383-
test('importing reloaded', async () => {
384-
await page.goto(viteTestUrl)
385-
const outputEle = await page.$('.importing-reloaded')
386-
const getOutput = () => {
387-
return outputEle.innerHTML()
388-
}
387+
// #2255
388+
test('importing reloaded', async () => {
389+
await page.goto(viteTestUrl)
390+
const outputEle = await page.$('.importing-reloaded')
391+
const getOutput = () => {
392+
return outputEle.innerHTML()
393+
}
389394

390-
await untilUpdated(getOutput, ['a.js: a0', 'b.js: b0,a0'].join('<br>'))
395+
await untilUpdated(getOutput, ['a.js: a0', 'b.js: b0,a0'].join('<br>'))
391396

392-
editFile('importing-updated/a.js', (code) => code.replace("'a0'", "'a1'"))
393-
await untilUpdated(
394-
getOutput,
395-
['a.js: a0', 'b.js: b0,a0', 'a.js: a1'].join('<br>'),
396-
)
397+
editFile('importing-updated/a.js', (code) => code.replace("'a0'", "'a1'"))
398+
await untilUpdated(
399+
getOutput,
400+
['a.js: a0', 'b.js: b0,a0', 'a.js: a1'].join('<br>'),
401+
)
397402

398-
editFile('importing-updated/b.js', (code) =>
399-
code.replace('`b0,${a}`', '`b1,${a}`'),
400-
)
401-
// note that "a.js: a1" should not happen twice after "b.js: b0,a0'"
402-
await untilUpdated(
403-
getOutput,
404-
['a.js: a0', 'b.js: b0,a0', 'a.js: a1', 'b.js: b1,a1'].join('<br>'),
405-
)
406-
})
403+
editFile('importing-updated/b.js', (code) =>
404+
code.replace('`b0,${a}`', '`b1,${a}`'),
405+
)
406+
// note that "a.js: a1" should not happen twice after "b.js: b0,a0'"
407+
await untilUpdated(
408+
getOutput,
409+
['a.js: a0', 'b.js: b0,a0', 'a.js: a1', 'b.js: b1,a1'].join('<br>'),
410+
)
411+
})
407412

413+
if (!process.env.VITE_TEST_FULL_BUNDLE_MODE) {
408414
describe('acceptExports', () => {
409415
const HOT_UPDATED = /hot updated/
410416
const CONNECTED = /connected/

0 commit comments

Comments
 (0)