Skip to content

Commit

Permalink
fix: hmr doesn't work when modifying the code of jsx in sfc (#4563)
Browse files Browse the repository at this point in the history
  • Loading branch information
y1d7ng authored Sep 1, 2021
1 parent af437aa commit 551eaea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-vue-jsx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function vueJsxPlugin(options = {}) {
) + `\nexport default __default__`
}

if (needHmr && !ssr) {
if (needHmr && !ssr && !/\?vue&type=script/.test(id)) {
let code = result.code
let callbackCode = ``
for (const { local, exported, id } of hotComponents) {
Expand Down
9 changes: 8 additions & 1 deletion packages/plugin-vue/src/handleHotUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ export async function handleHotUpdate({
!isEqualBlock(descriptor.script, prevDescriptor.script) ||
!isEqualBlock(descriptor.scriptSetup, prevDescriptor.scriptSetup)
) {
affectedModules.add(mainModule)
let scriptModule: ModuleNode | undefined
if (descriptor.script?.lang && !descriptor.script.src) {
const scriptModuleRE = new RegExp(
`type=script.*&lang\.${descriptor.script.lang}$`
)
scriptModule = modules.find((m) => scriptModuleRE.test(m.url))
}
affectedModules.add(scriptModule || mainModule)
}

if (!isEqualBlock(descriptor.template, prevDescriptor.template)) {
Expand Down

0 comments on commit 551eaea

Please sign in to comment.