Skip to content

Commit

Permalink
feat: invalidate modules and trigger full reload on file change
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathanaël Labreuil authored and IonianPlayboy committed Nov 4, 2024
1 parent f0269a2 commit 9b9889d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions code/frameworks/vue3-vite/src/plugins/vue-component-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { dirname, join, parse, relative, resolve } from 'node:path';

import findPackageJson from 'find-package-json';
import MagicString from 'magic-string';
import type { PluginOption } from 'vite';
import type { ModuleNode, PluginOption } from 'vite';
import {
type ComponentMeta,
type MetaCheckerOptions,
Expand Down Expand Up @@ -147,9 +147,18 @@ export async function vueComponentMeta(tsconfigPath = 'tsconfig.json'): Promise<
}
},
// handle hot updates to update the component meta on file changes
async handleHotUpdate({ file, read }) {
async handleHotUpdate({ file, read, server, modules, timestamp }) {
const content = await read();
checker.updateFile(file, content);
// Invalidate modules manually
const invalidatedModules = new Set<ModuleNode>();

for (const mod of modules) {
server.moduleGraph.invalidateModule(mod, invalidatedModules, timestamp, true);
}

server.ws.send({ type: 'full-reload' });
return [];
},
};
}
Expand Down

0 comments on commit 9b9889d

Please sign in to comment.