Skip to content

Commit cad32ad

Browse files
committed
fix(shiki): fix random "memory access out of bounds" error
1 parent 99a4e0d commit cad32ad

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

apps/website/src/components/highlight/highlight.tsx

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { ClassList, PropsOf, component$, useSignal, useTask$ } from '@builder.io/qwik';
22
import { CodeCopy } from '../code-copy/code-copy';
3-
import { getHighlighterCore } from 'shiki';
43
import { cn } from '@qwik-ui/utils';
5-
import getWasm from 'shiki/wasm';
4+
import { highlighter } from './highlighter';
65

76
export type HighlightProps = PropsOf<'div'> & {
87
code: string;
@@ -23,7 +22,6 @@ export const Highlight = component$(
2322
}: HighlightProps) => {
2423
const codeSig = useSignal('');
2524

26-
// eslint-disable-next-line qwik/no-use-visible-task
2725
useTask$(async function createHighlightedCode() {
2826
let modifiedCode: string = code;
2927

@@ -37,19 +35,6 @@ export const Highlight = component$(
3735
modifiedCode = partsOfCode[0];
3836
}
3937

40-
const highlighter = await getHighlighterCore({
41-
themes: [
42-
// or a dynamic import if you want to do chunk splitting
43-
import('shiki/themes/poimandres.mjs'),
44-
],
45-
langs: [
46-
import('shiki/langs/html.mjs'),
47-
import('shiki/langs/tsx.mjs'),
48-
import('shiki/langs/css.mjs'),
49-
],
50-
loadWasm: getWasm,
51-
});
52-
5338
const str = highlighter.codeToHtml(modifiedCode, {
5439
lang: language,
5540
themes: {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { getHighlighterCore } from 'shiki/index.mjs';
2+
import getWasm from 'shiki/wasm';
3+
import poimandres from 'shiki/themes/poimandres.mjs';
4+
import html from 'shiki/langs/html.mjs';
5+
import css from 'shiki/langs/css.mjs';
6+
import ts from 'shiki/langs/typescript.mjs';
7+
import tsx from 'shiki/langs/tsx.mjs';
8+
import js from 'shiki/langs/javascript.mjs';
9+
10+
export const highlighter = await getHighlighterCore({
11+
themes: [
12+
// or a dynamic import if you want to do chunk splitting
13+
poimandres,
14+
],
15+
langs: [html, css, js, ts, tsx],
16+
loadWasm: getWasm,
17+
});

0 commit comments

Comments
 (0)