summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortaichan <40626578+tai-cha@users.noreply.github.com>2025-03-10 07:45:17 +0900
committerGitHub <noreply@github.com>2025-03-09 22:45:17 +0000
commit88efc0a3be239432fa3693f182064567fed5a7f3 (patch)
tree8d01ba5f5400e750286bc7075623ce84297ad078
parentBump version to 2025.3.2-alpha.3 (diff)
downloadmisskey-88efc0a3be239432fa3693f182064567fed5a7f3.tar.gz
misskey-88efc0a3be239432fa3693f182064567fed5a7f3.tar.bz2
misskey-88efc0a3be239432fa3693f182064567fed5a7f3.zip
fix(dev): 検索インデックス対象ファイルでHMRが効かない問題を修正 (#15638)
-rw-r--r--packages/frontend/lib/vite-plugin-create-search-index.ts36
1 files changed, 28 insertions, 8 deletions
diff --git a/packages/frontend/lib/vite-plugin-create-search-index.ts b/packages/frontend/lib/vite-plugin-create-search-index.ts
index 509eb804cb..e194872640 100644
--- a/packages/frontend/lib/vite-plugin-create-search-index.ts
+++ b/packages/frontend/lib/vite-plugin-create-search-index.ts
@@ -1213,22 +1213,37 @@ async function processVueFile(
transformedCodeCache: Record<string, string>
}> {
const normalizedId = id.replace(/\\/g, '/'); // ファイルパスを正規化
- // すでにキャッシュに存在する場合は、そのまま返す
- if (transformedCodeCache[normalizedId] && transformedCodeCache[normalizedId].includes('markerId=')) {
+
+ // 開発モード時はコード内容に変更があれば常に再処理する
+ // コード内容が同じ場合のみキャッシュを使用
+ const isDevMode = process.env.NODE_ENV === 'development';
+
+ const s = new MagicString(code); // magic-string のインスタンスを作成
+
+ if (!isDevMode && transformedCodeCache[normalizedId] && transformedCodeCache[normalizedId].includes('markerId=')) {
logger.info(`Using cached version for ${id}`);
return {
code: transformedCodeCache[normalizedId],
- map: null,
+ map: s.generateMap({ source: id, includeContent: true }),
+ transformedCodeCache
+ };
+ }
+
+ // すでに処理済みのファイルでコードに変更がない場合はキャッシュを返す
+ if (transformedCodeCache[normalizedId] === code) {
+ logger.info(`Code unchanged for ${id}, using cached version`);
+ return {
+ code: transformedCodeCache[normalizedId],
+ map: s.generateMap({ source: id, includeContent: true }),
transformedCodeCache
};
}
- const s = new MagicString(code); // magic-string のインスタンスを作成
const parsed = vueSfcParse(code, { filename: id });
if (!parsed.descriptor.template) {
return {
code,
- map: null,
+ map: s.generateMap({ source: id, includeContent: true }),
transformedCodeCache
};
}
@@ -1466,16 +1481,21 @@ export default function pluginCreateSearchIndex(options: Options): Plugin {
if (isMatch) break; // いずれかのパターンでマッチしたら、outer loop も抜ける
}
-
if (!isMatch) {
return;
}
+ // ファイルの内容が変更された場合は再処理を行う
+ const normalizedId = id.replace(/\\/g, '/');
+ const hasContentChanged = !transformedCodeCache[normalizedId] || transformedCodeCache[normalizedId] !== code;
+
const transformed = await processVueFile(code, id, options, transformedCodeCache);
transformedCodeCache = transformed.transformedCodeCache; // キャッシュを更新
- if (isDevServer) {
- await analyzeVueProps({ ...options, transformedCodeCache }); // analyzeVueProps を呼び出す
+
+ if (isDevServer && hasContentChanged) {
+ await analyzeVueProps({ ...options, transformedCodeCache }); // ファイルが変更されたときのみ分析を実行
}
+
return transformed;
},