Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions packages/components/src/utils/shiki/worker-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@ function getShikiWorker(): ShikiWorkerInstance {
if (instance) {
return instance;
}
const worker = new Worker(new URL("./worker.js", import.meta.url), {
type: "module",
});
instance = wrap(worker);
return instance;
try {
const worker = new Worker(new URL("./worker.js", import.meta.url), {
type: "module",
});
instance = wrap(worker);
return instance;
} catch (error) {
console.warn(
"@mintlify/components: Shiki worker unavailable, using synchronous highlighting",
error
);
return undefined;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeated worker creation attempts on failure

Medium Severity

When worker creation fails in the catch block, instance remains undefined. This causes every subsequent call to getShikiWorker() to retry creating the worker, fail again, and log another warning. Since this function is called for every large code block, this can result in console spam and unnecessary overhead. The failed initialization state needs to be tracked to prevent repeated retry attempts.

Fix in Cursor Fix in Web

}

export { getShikiWorker };
8 changes: 8 additions & 0 deletions packages/components/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { defineConfig } from "vite";
import dts from "vite-plugin-dts";

export default defineConfig({
base: "",
plugins: [
react(),
tailwindcss(),
Expand All @@ -26,6 +27,13 @@ export default defineConfig({
},
worker: {
format: "es",
rollupOptions: {
external: [],
output: {
entryFileNames: "utils/shiki/worker.js",
inlineDynamicImports: true,
},
},
},
build: {
lib: {
Expand Down