I used a Vite plugin (which automatically restarts the server after modifying the MD file), but when the search was set to local search, the plugin failed to restart, perhaps because the search cache was not cleared
Reproduction
import { defineConfig } from "vitepress";
import fs from "fs";
function autoRestart() {
let restartPromise;
return {
name: "auto-restart",
configureServer(server) {
server.watcher.on("all", (event, path) => {
if (path.endsWith(".md")) {
if (!restartPromise) {
restartPromise = (async () => {
console.log("Restarting server...");
// TODO: clearCache()?
// [vitepress] MiniSearch: duplicate ID
// [vitepress] server restart failed
await server.restart();
// await fs.promises.utimes(server.config.vitepress.configPath, new Date(), new Date());
})().finally(() => {
restartPromise = undefined;
});
}
}
});
},
}
}
export default defineConfig({
vite: {
plugins: [
autoRestart(),
],
},
themeConfig: {
search: {
provider: "local",
}
},
});
When modifying the MD file did not restart successfully, but after turning off local search, the code can restart successfully
Restarting server...
[vitepress] MiniSearch: duplicate ID
[vitepress] server restart failed
Expected behavior
Perhaps a method is needed to clearCache() to restart, or the contents of the sidebar can be modified at any time during runtime to take effect in real-time
Describe the bug
I used a Vite plugin (which automatically restarts the server after modifying the MD file), but when the search was set to local search, the plugin failed to restart, perhaps because the search cache was not cleared
Reproduction
When modifying the MD file did not restart successfully, but after turning off local search, the code can restart successfully
Expected behavior
Perhaps a method is needed to
clearCache()
to restart, or the contents of the sidebar can be modified at any time during runtime to take effect in real-timelike this: https://github.com/vuejs/vitepress/blob/2ac64b8d4180f2a7c54fda57df7f3a0a52488d62/src/node/shortcuts.ts#L76-L88 https://github.com/vuejs/vitepress/blob/2ac64b8d4180f2a7c54fda57df7f3a0a52488d62/src/node/plugin.ts#L371-L394
System Info
Additional context
No response
Validations