Skip to content

Commit 17aea88

Browse files
committed
fix: invalidate in circular dep
1 parent cf1102b commit 17aea88

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

packages/vite/src/node/build.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -938,10 +938,17 @@ async function buildEnvironment(
938938
server!.ws.send({
939939
type: 'full-reload',
940940
})
941-
logger.info(colors.green(`page reload `) + colors.dim(file), {
942-
clear: !hmrOutput.firstInvalidatedBy,
943-
timestamp: true,
944-
})
941+
const reason = hmrOutput.fullReloadReason
942+
? colors.dim(` (${hmrOutput.fullReloadReason})`)
943+
: ''
944+
logger.info(
945+
colors.green(`page reload `) + colors.dim(file) + reason,
946+
{
947+
clear: !hmrOutput.firstInvalidatedBy,
948+
timestamp: true,
949+
},
950+
)
951+
return
945952
}
946953

947954
if (hmrOutput.patch) {
@@ -953,6 +960,7 @@ async function buildEnvironment(
953960
url,
954961
path: boundary.boundary,
955962
acceptedPath: boundary.acceptedVia,
963+
firstInvalidatedBy: hmrOutput.firstInvalidatedBy,
956964
timestamp: 0,
957965
}
958966
}) as Update[]
@@ -985,9 +993,8 @@ async function buildEnvironment(
985993
server.hot.on(
986994
'vite:invalidate',
987995
async ({ path: file, message, firstInvalidatedBy }) => {
988-
file = path.join(root, file)
989996
const hmrOutput = (await bundle!.hmrInvalidate(
990-
file,
997+
path.join(root, file),
991998
firstInvalidatedBy,
992999
))!
9931000
if (hmrOutput) {

playground/hmr/__tests__/hmr.spec.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -247,31 +247,31 @@ if (!isBuild) {
247247
})
248248
}
249249

250-
if (!process.env.VITE_TEST_FULL_BUNDLE_MODE) {
251-
test('invalidate in circular dep should not trigger infinite HMR', async () => {
252-
const el = await page.$('.invalidation-circular-deps')
253-
await untilUpdated(() => el.textContent(), 'child')
254-
editFile(
255-
'invalidation-circular-deps/circular-invalidate/child.js',
256-
(code) => code.replace('child', 'child updated'),
257-
)
258-
await page.waitForEvent('load')
259-
await untilUpdated(
260-
() => page.textContent('.invalidation-circular-deps'),
261-
'child updated',
262-
)
263-
})
250+
test('invalidate in circular dep should not trigger infinite HMR', async () => {
251+
const el = await page.$('.invalidation-circular-deps')
252+
await untilUpdated(() => el.textContent(), 'child')
253+
editFile(
254+
'invalidation-circular-deps/circular-invalidate/child.js',
255+
(code) => code.replace('child', 'child updated'),
256+
)
257+
await page.waitForEvent('load')
258+
await untilUpdated(
259+
() => page.textContent('.invalidation-circular-deps'),
260+
'child updated',
261+
)
262+
})
264263

265-
test('invalidate in circular dep should be hot updated if possible', async () => {
266-
const el = await page.$('.invalidation-circular-deps-handled')
267-
await untilUpdated(() => el.textContent(), 'child')
268-
editFile(
269-
'invalidation-circular-deps/invalidate-handled-in-circle/child.js',
270-
(code) => code.replace('child', 'child updated'),
271-
)
272-
await untilUpdated(() => el.textContent(), 'child updated')
273-
})
264+
test('invalidate in circular dep should be hot updated if possible', async () => {
265+
const el = await page.$('.invalidation-circular-deps-handled')
266+
await untilUpdated(() => el.textContent(), 'child')
267+
editFile(
268+
'invalidation-circular-deps/invalidate-handled-in-circle/child.js',
269+
(code) => code.replace('child', 'child updated'),
270+
)
271+
await untilUpdated(() => el.textContent(), 'child updated')
272+
})
274273

274+
if (!process.env.VITE_TEST_FULL_BUNDLE_MODE) {
275275
test('plugin hmr handler + custom event', async () => {
276276
const el = await page.$('.custom')
277277
editFile('customFile.js', (code) => code.replace('custom', 'edited'))

0 commit comments

Comments
 (0)