Skip to content

Commit e0b29c7

Browse files
authored
fix(plugin-vue-jsx): fix vue jsx hmr (#1495)
1 parent c7d1658 commit e0b29c7

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

Diff for: packages/plugin-vue-jsx/index.js

+9-20
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,14 @@ function vueJsxPlugin(options = {}) {
6262

6363
// check for hmr injection
6464
/**
65-
* @type {{ name: string, hash: string }[]}
65+
* @type {{ name: string }[]}
6666
*/
6767
const declaredComponents = []
6868
/**
6969
* @type {{
7070
* local: string,
7171
* exported: string,
7272
* id: string,
73-
* hash: string
7473
* }[]}
7574
*/
7675
const hotComponents = []
@@ -91,11 +90,10 @@ function vueJsxPlugin(options = {}) {
9190
) {
9291
hotComponents.push(
9392
...parseComponentDecls(node.declaration, code).map(
94-
({ name, hash: _hash }) => ({
93+
({ name }) => ({
9594
local: name,
9695
exported: name,
97-
id: hash(id + name),
98-
hash: _hash
96+
id: hash(id + name)
9997
})
10098
)
10199
)
@@ -112,8 +110,7 @@ function vueJsxPlugin(options = {}) {
112110
hotComponents.push({
113111
local: spec.local.name,
114112
exported: spec.exported.name,
115-
id: hash(id + spec.exported.name),
116-
hash: matched.hash
113+
id: hash(id + spec.exported.name)
117114
})
118115
}
119116
}
@@ -131,19 +128,15 @@ function vueJsxPlugin(options = {}) {
131128
hotComponents.push({
132129
local: node.declaration.name,
133130
exported: 'default',
134-
id: hash(id + 'default'),
135-
hash: matched.hash
131+
id: hash(id + 'default')
136132
})
137133
}
138134
} else if (isDefineComponentCall(node.declaration)) {
139135
hasDefault = true
140136
hotComponents.push({
141137
local: '__default__',
142138
exported: 'default',
143-
id: hash(id + 'default'),
144-
hash: hash(
145-
code.slice(node.declaration.start, node.declaration.end)
146-
)
139+
id: hash(id + 'default')
147140
})
148141
}
149142
}
@@ -160,14 +153,11 @@ function vueJsxPlugin(options = {}) {
160153
}
161154

162155
let callbackCode = ``
163-
for (const { local, exported, id, hash } of hotComponents) {
156+
for (const { local, exported, id } of hotComponents) {
164157
code +=
165158
`\n${local}.__hmrId = "${id}"` +
166-
`\n${local}.__hmrHash = "${hash}"` +
167159
`\n__VUE_HMR_RUNTIME__.createRecord("${id}", ${local})`
168-
callbackCode +=
169-
`\n if (__${exported}.__hmrHash !== ${local}.__hmrHash) ` +
170-
`__VUE_HMR_RUNTIME__.reload("${id}", __${exported})`
160+
callbackCode += `\n__VUE_HMR_RUNTIME__.reload("${id}", __${exported})`
171161
}
172162

173163
code += `\nimport.meta.hot.accept(({${hotComponents
@@ -195,8 +185,7 @@ function parseComponentDecls(node, source) {
195185
for (const decl of node.declarations) {
196186
if (decl.id.type === 'Identifier' && isDefineComponentCall(decl.init)) {
197187
names.push({
198-
name: decl.id.name,
199-
hash: hash(source.slice(decl.init.start, decl.init.end))
188+
name: decl.id.name
200189
})
201190
}
202191
}

0 commit comments

Comments
 (0)