From 7d59bdb2c3702c9ac42d4e63ed3154fbc47235f6 Mon Sep 17 00:00:00 2001 From: Patrick Pircher Date: Tue, 1 Oct 2024 23:38:53 +0200 Subject: [PATCH 1/2] fix --- packages/vite/src/hbs.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/vite/src/hbs.ts b/packages/vite/src/hbs.ts index 2b3acf784..f0a8e768c 100644 --- a/packages/vite/src/hbs.ts +++ b/packages/vite/src/hbs.ts @@ -72,6 +72,32 @@ export function hbs(): Plugin { } }, + handleHotUpdate(ctx) { + let id = ctx.file; + let modules = ctx.modules.slice(); + if (isInComponents(id, resolverLoader.resolver.packageCache)) { + let jsFilename = id.slice(0, -1 * extname(id).length) + '.js'; + if (jsFilename !== id) { + // we don't actually do any transformation of these files here, but + // Babel is going to run the colocation plugin to wire js and hbs + // together, and it doesn't know about the extra dependency between + // them. We can invalidate the whole transform step from here. + modules.push((this as any).getModuleInfo(jsFilename)); + } + } + return modules; + }, + + transform(code: string, id: string) { + if (!hbsFilter(id)) { + return null; + } + if (getMeta(this, id)?.type === 'template-only-component-js') { + + this.addWatchFile(id); + } + return hbsToJS(code); + }, + load(id: string) { if (getMeta(this, id)?.type === 'template-only-component-js') { return { From da8391188940d45656929e7db0fcbf292b91c794 Mon Sep 17 00:00:00 2001 From: Patrick Pircher Date: Tue, 1 Oct 2024 23:46:17 +0200 Subject: [PATCH 2/2] fix --- packages/vite/src/hbs.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/packages/vite/src/hbs.ts b/packages/vite/src/hbs.ts index f0a8e768c..80ff0a541 100644 --- a/packages/vite/src/hbs.ts +++ b/packages/vite/src/hbs.ts @@ -9,6 +9,7 @@ import { templateOnlyComponentSource, syntheticJStoHBS, } from '@embroider/core'; +import { extname } from 'path'; const resolverLoader = new ResolverLoader(process.cwd()); const hbsFilter = createFilter('**/*.hbs?([?]*)'); @@ -88,16 +89,6 @@ export function hbs(): Plugin { return modules; }, - transform(code: string, id: string) { - if (!hbsFilter(id)) { - return null; - } - if (getMeta(this, id)?.type === 'template-only-component-js') { - + this.addWatchFile(id); - } - return hbsToJS(code); - }, - load(id: string) { if (getMeta(this, id)?.type === 'template-only-component-js') { return {