Skip to content

Commit fadd92f

Browse files
committed
fix: invalidate in circular dep
1 parent f71db56 commit fadd92f

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
@@ -934,10 +934,17 @@ async function buildEnvironment(
934934
server!.ws.send({
935935
type: 'full-reload',
936936
})
937-
logger.info(colors.green(`page reload `) + colors.dim(file), {
938-
clear: !hmrOutput.firstInvalidatedBy,
939-
timestamp: true,
940-
})
937+
const reason = hmrOutput.fullReloadReason
938+
? colors.dim(` (${hmrOutput.fullReloadReason})`)
939+
: ''
940+
logger.info(
941+
colors.green(`page reload `) + colors.dim(file) + reason,
942+
{
943+
clear: !hmrOutput.firstInvalidatedBy,
944+
timestamp: true,
945+
},
946+
)
947+
return
941948
}
942949

943950
if (hmrOutput.patch) {
@@ -949,6 +956,7 @@ async function buildEnvironment(
949956
url,
950957
path: boundary.boundary,
951958
acceptedPath: boundary.acceptedVia,
959+
firstInvalidatedBy: hmrOutput.firstInvalidatedBy,
952960
timestamp: 0,
953961
}
954962
}) as Update[]
@@ -981,9 +989,8 @@ async function buildEnvironment(
981989
server.hot.on(
982990
'vite:invalidate',
983991
async ({ path: file, message, firstInvalidatedBy }) => {
984-
file = path.join(root, file)
985992
const hmrOutput = (await bundle!.hmrInvalidate(
986-
file,
993+
path.join(root, file),
987994
firstInvalidatedBy,
988995
))!
989996
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)