From 1534a67d866e4922a7eab1a1c166db7f11855c59 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Wed, 29 Jul 2026 18:25:47 +0530 Subject: [PATCH] fix(search): serve a fresh search index after dev updates Re-indexing only invalidated the bare @localSearchIndex module; the per-locale modules that carry the data were still served from the transform cache, and the browser module cache pinned them too. Version the locale import in dev so every index update loads fresh data. Co-Authored-By: Claude Fable 5 --- src/node/plugins/localSearchPlugin.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/node/plugins/localSearchPlugin.ts b/src/node/plugins/localSearchPlugin.ts index a9b053d1..2a01af56 100644 --- a/src/node/plugins/localSearchPlugin.ts +++ b/src/node/plugins/localSearchPlugin.ts @@ -82,8 +82,13 @@ export async function localSearchPlugin( let server: ViteDevServer | undefined let pending: Promise + let indexVersion = 0 + function onIndexUpdated() { if (!server) return + // bust the per-locale import urls emitted below — the browser module + // cache and the transform cache would otherwise serve the old index + indexVersion++ server.moduleGraph.onFileChange(LOCAL_SEARCH_INDEX_REQUEST_PATH) // HMR const mod = server.moduleGraph.getModuleById( @@ -199,7 +204,9 @@ export async function localSearchPlugin( records.push( `${JSON.stringify( locale - )}: () => import('${LOCAL_SEARCH_INDEX_ID}${locale}')` + )}: () => import('${LOCAL_SEARCH_INDEX_ID}${locale}${ + server ? `?v=${indexVersion}` : '' + }')` ) } return `export default {${records.join(',')}}` @@ -208,7 +215,9 @@ export async function localSearchPlugin( return `export default ${JSON.stringify( JSON.stringify( indexByLocales.get( - id.replace(LOCAL_SEARCH_INDEX_REQUEST_PATH, '') + id + .replace(LOCAL_SEARCH_INDEX_REQUEST_PATH, '') + .replace(/\?.*$/, '') ) ?? {} ) )}`