Skip to content

Commit

Permalink
fix: run transform hooks of all earlier plugins on handleHotUpdate vi…
Browse files Browse the repository at this point in the history
  • Loading branch information
rashfael committed Jul 27, 2023
1 parent ec58d00 commit 5953267
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions packages/plugin-vue/src/handleHotUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _debug from 'debug'
import type { SourceDescription } from 'rollup'
import type { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc'
import type { HmrContext, ModuleNode } from 'vite'
import { isCSSRequest } from 'vite'
Expand All @@ -23,7 +24,7 @@ const directRequestRE = /(?:\?|&)direct\b/
* Vite-specific HMR handling
*/
export async function handleHotUpdate(
{ file, modules, read }: HmrContext,
{ file, modules, read, server }: HmrContext,
options: ResolvedOptions,
): Promise<ModuleNode[] | void> {
const prevDescriptor = getDescriptor(file, options, false)
Expand All @@ -34,7 +35,24 @@ export async function handleHotUpdate(

setPrevDescriptor(file, prevDescriptor)

const content = await read()
let content = await read()

const vuePlugin = server.config.plugins.find((p) => p.name === 'vite:vue')
if (vuePlugin) {
for (const hook of server.config.getSortedPluginHooks('transform')) {
if (hook === vuePlugin.transform) break
const transformResult = await hook(content, file)
if (transformResult) {
if ((transformResult as Partial<SourceDescription>).code) {
content = (transformResult as Partial<SourceDescription>)
.code as string
} else {
content = transformResult as string
}
}
}
}

const { descriptor } = createDescriptor(file, content, options)

let needRerender = false
Expand Down

0 comments on commit 5953267

Please sign in to comment.