Skip to content

Commit 4a0718a

Browse files
Merge pull request #489 from thejackshelton/main
fix(code flicker): removes code flicker on page load
2 parents 1450870 + 63d40d4 commit 4a0718a

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

apps/website/src/routes/docs/_components/highlight/highlight.tsx

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,32 @@ export const Highlight = component$(
2727
}: HighlightProps) => {
2828
const codeSig = useSignal('');
2929

30-
useVisibleTask$(async function createHighlightedCode() {
31-
const highlighter = await (window as any).shikiji;
32-
let modifiedCode: string = code;
30+
useVisibleTask$(
31+
async function createHighlightedCode() {
32+
const highlighter = await (window as any).shikiji;
33+
let modifiedCode: string = code;
3334

34-
let partsOfCode = modifiedCode.split(splitCommentStart);
35-
if (partsOfCode.length > 1) {
36-
modifiedCode = partsOfCode[1];
37-
}
35+
let partsOfCode = modifiedCode.split(splitCommentStart);
36+
if (partsOfCode.length > 1) {
37+
modifiedCode = partsOfCode[1];
38+
}
3839

39-
partsOfCode = modifiedCode.split(splitCommentEnd);
40-
if (partsOfCode.length > 1) {
41-
modifiedCode = partsOfCode[0];
42-
}
40+
partsOfCode = modifiedCode.split(splitCommentEnd);
41+
if (partsOfCode.length > 1) {
42+
modifiedCode = partsOfCode[0];
43+
}
4344

44-
const str = await highlighter.codeToHtml(modifiedCode, {
45-
lang: language,
46-
themes: {
47-
light: 'github-dark',
48-
dark: 'github-dark',
49-
},
50-
});
51-
codeSig.value = str.toString();
52-
});
45+
const str = await highlighter.codeToHtml(modifiedCode, {
46+
lang: language,
47+
themes: {
48+
light: 'github-dark',
49+
dark: 'github-dark',
50+
},
51+
});
52+
codeSig.value = str.toString();
53+
},
54+
{ strategy: 'document-idle' },
55+
);
5356

5457
return (
5558
<div class="code-example relative max-h-[31.25rem] rounded-b-xl">

0 commit comments

Comments
 (0)