Describe the bug
Opening / switching stories with the Source panel active repeatedly creates new Shiki highlighter instances. After enough navigations the browser console warns:
[Shiki] 10 instances have been created. Shiki is supposed to be used as a singleton, consider refactoring your code to cache your highlighter instance; Or call `highlighter.dispose()` to release unused instances.
This is more noticeable in projects with many stories (e.g. browsing a large story tree), but it is not project-specific.
Root cause: @histoire/app StorySourceCode.vue calls createHighlighter() inside onMounted and neither reuses a shared instance nor calls dispose() on unmount:
https://github.com/histoire-dev/histoire/blob/main/packages/histoire-app/src/app/components/panel/StorySourceCode.vue#L89-L100
Shiki documents that highlighters should be singletons (warns every 10 instances). Related Shiki discussion: shikijs/shiki#756
Suggested fix: cache a module-level Promise<Highlighter> (same langs/themes) and reuse it across remounts. Optionally also share/dispose the Node-side highlighters created in packages/histoire/src/node/markdown.ts (createMarkdownRenderer is invoked from both the Vite markdown plugin and the markdown file watcher without reuse).
I do not plan to open a PR unless maintainers want one.
Reproduction
- Open the Vue 3 Histoire starter: https://stackblitz.com/edit/histoire-vue3-starter
- Run Histoire (
pnpm run story:dev / the StackBlitz Histoire script).
- Open any story so the Source panel is visible.
- Switch between stories (or variants that remount the source panel) 10+ times.
- Observe the Shiki singleton warning in the browser console.
No custom app code is required; the default starter is enough. The same path still exists on main as linked above.
System Info
System:
OS: macOS 26.5.2
CPU: (10) arm64 Apple M1 Max
Memory: 4.86 GB / 64.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 24.14.0 - …/bin/node
npm: 11.9.0 - …/bin/npm
pnpm: 10.30.3 - …/bin/pnpm
bun: 1.3.11 - …/bin/bun
Browsers:
Chrome: 151.0.7922.71
Edge: 150.0.4078.105
Firefox: 152.0.6
Safari: 26.5.2
npmPackages:
@histoire/plugin-vue: 1.0.0-beta.1 => 1.0.0-beta.1
@vitejs/plugin-vue: ^6.0.8 => 6.0.8
histoire: 1.0.0-beta.1 => 1.0.0-beta.1
vite: ^8.1.5 => 8.1.5
Used Package Manager
pnpm
Validations
Describe the bug
Opening / switching stories with the Source panel active repeatedly creates new Shiki highlighter instances. After enough navigations the browser console warns:
This is more noticeable in projects with many stories (e.g. browsing a large story tree), but it is not project-specific.
Root cause:
@histoire/appStorySourceCode.vuecallscreateHighlighter()insideonMountedand neither reuses a shared instance nor callsdispose()on unmount:https://github.com/histoire-dev/histoire/blob/main/packages/histoire-app/src/app/components/panel/StorySourceCode.vue#L89-L100
Shiki documents that highlighters should be singletons (warns every 10 instances). Related Shiki discussion: shikijs/shiki#756
Suggested fix: cache a module-level
Promise<Highlighter>(same langs/themes) and reuse it across remounts. Optionally also share/dispose the Node-side highlighters created inpackages/histoire/src/node/markdown.ts(createMarkdownRendereris invoked from both the Vite markdown plugin and the markdown file watcher without reuse).I do not plan to open a PR unless maintainers want one.
Reproduction
pnpm run story:dev/ the StackBlitz Histoire script).No custom app code is required; the default starter is enough. The same path still exists on
mainas linked above.System Info
System: OS: macOS 26.5.2 CPU: (10) arm64 Apple M1 Max Memory: 4.86 GB / 64.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 24.14.0 - …/bin/node npm: 11.9.0 - …/bin/npm pnpm: 10.30.3 - …/bin/pnpm bun: 1.3.11 - …/bin/bun Browsers: Chrome: 151.0.7922.71 Edge: 150.0.4078.105 Firefox: 152.0.6 Safari: 26.5.2 npmPackages: @histoire/plugin-vue: 1.0.0-beta.1 => 1.0.0-beta.1 @vitejs/plugin-vue: ^6.0.8 => 6.0.8 histoire: 1.0.0-beta.1 => 1.0.0-beta.1 vite: ^8.1.5 => 8.1.5Used Package Manager
pnpm
Validations