Skip to content

Commit 92cc143

Browse files
committed
fix: restore import.meta.hot.accept() for Vite HMR boundary detection
Commit ad30cba accidentally removed the direct import.meta.hot.accept() call from the normal refresh path when refactoring the reload pragma. Vite's importAnalysis statically lexes for this pattern to mark modules as self-accepting; without it, Vite sends full-reload instead of hot-update. Made-with: Cursor
1 parent 0b566a7 commit 92cc143

5 files changed

Lines changed: 203 additions & 12 deletions

File tree

src/babel/core/create-registry.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,32 @@ export function createRegistry(
3333
)[0],
3434
);
3535
const pathToHot = getHotIdentifier(state);
36+
const statements: t.Statement[] = [
37+
t.expressionStatement(
38+
t.callExpression(getImportIdentifier(state, path, IMPORT_REFRESH), [
39+
t.stringLiteral(state.bundler),
40+
pathToHot,
41+
identifier,
42+
]),
43+
),
44+
];
45+
// Vite's importAnalysis statically lexes for `import.meta.hot.accept` to
46+
// mark modules as self-accepting. The actual accept logic is in $$refreshESM,
47+
// but Vite needs this direct call for server-side HMR boundary detection.
48+
if (state.bundler === 'vite') {
49+
statements.unshift(
50+
t.expressionStatement(
51+
t.callExpression(
52+
t.memberExpression(pathToHot, t.identifier('accept')),
53+
[],
54+
),
55+
),
56+
);
57+
}
3658
(
3759
path.scope.getProgramParent().path as babel.NodePath<t.Program>
3860
).pushContainer('body', [
39-
t.ifStatement(
40-
pathToHot,
41-
t.blockStatement([
42-
t.expressionStatement(
43-
t.callExpression(getImportIdentifier(state, path, IMPORT_REFRESH), [
44-
t.stringLiteral(state.bundler),
45-
pathToHot,
46-
identifier,
47-
]),
48-
),
49-
]),
50-
),
61+
t.ifStatement(pathToHot, t.blockStatement(statements)),
5162
]);
5263
state.imports.set(REGISTRY, identifier);
5364
return identifier;

0 commit comments

Comments
 (0)