fix: pre-bundle shiki/@pierre deps to stop dev dynamic-import failures (#1643)

* fix(ui): pre-bundle shiki/@pierre deps to stop dev dynamic-import failures

shiki lazy-imports a grammar per language and these libs only live inside
lazy route components, so Vite's startup scanner never sees them. They get
discovered on first thread navigation, triggering a dep re-optimize +
force-reload that aborts the in-flight route-chunk import, surfacing as
"Failed to fetch dynamically imported module: .../$threadId.tsx".

Pre-bundle them (and the github themes + common code-block languages) via
optimizeDeps.include so the optimize happens once at startup. Dev-only;
production bundles are unaffected.

* fix: pre-bundle canonical shiki docker/make langs instead of aliases

---------

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
This commit is contained in:
Johannes du Plessis 2026-06-29 11:06:34 -07:00 • committed by GitHub
parent 92dbf6f932
commit db2ae58edb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -74,8 +74,62 @@ function mockHarnessProxy(): Plugin | null {
}
}
// shiki lazily `import()`s one grammar per language on first render. These libs
// also only live inside lazy route components, so Vite's startup scanner never
// reaches them — it discovers them on first thread navigation, re-optimizes deps,
// and force-reloads, aborting the in-flight route-chunk import ("Failed to fetch
// dynamically imported module"). Pre-bundling them up front avoids the reload.
// Uncommon languages not listed just trigger a one-time, graceful re-optimize.
const SHIKI_LANGS = [
"bash",
"c",
"cpp",
"csharp",
"css",
"diff",
"docker",
"go",
"graphql",
"html",
"java",
"javascript",
"json",
"jsonc",
"jsx",
"kotlin",
"lua",
"make",
"markdown",
"php",
"python",
"ruby",
"rust",
"scala",
"shellscript",
"sql",
"swift",
"toml",
"tsx",
"typescript",
"xml",
"yaml",
]
const config = defineConfig({
optimizeDeps: { include: ["workbox-window"] },
optimizeDeps: {
include: [
"workbox-window",
"streamdown",
"shiki",
"@pierre/diffs",
"@pierre/diffs/react",
"@pierre/trees",
"@pierre/trees/react",
"@shikijs/themes/github-light",
"@shikijs/themes/github-dark",
...SHIKI_LANGS.map((lang) => `@shikijs/langs/${lang}`),
],
},
worker: { format: "es" },
plugins: [
mockHarnessProxy(),