Skip to content

Commit 35d0dd4

Browse files
fix: avoid requestAnimationFrame undefined
1 parent 39b0cd4 commit 35d0dd4

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

components/content/ProsePre.vue

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,9 @@
4040
const codeBlock = ref(null);
4141
4242
watch(() => props.code, (newVal) => {
43-
requestAnimationFrame(() => {
44-
requestAnimationFrame(() => {
45-
if (codeBlock.value && newVal.length > 0) {
46-
highlightCodeBlocks(codeBlock.value);
47-
}
48-
})
49-
});
43+
if (codeBlock.value && newVal.length > 0) {
44+
highlightCodeBlocks(codeBlock.value);
45+
}
5046
}, {immediate: true});
5147
5248
function hoverCode() {

composables/useShiki.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default function useShiki() {
5555
const shiki = ref<ReturnType<typeof getShiki>>()
5656

5757
async function highlightCodeBlocks(root: HTMLElement = document.body) {
58-
return new Promise<void>(resolve => nextTick(() => requestAnimationFrame(async () => {
58+
return new Promise<void>(resolve => nextTick(async () => {
5959
const blocks = root.querySelectorAll('pre > code')
6060
for(const block of blocks) {
6161
const preClassList = block.parentElement?.classList;
@@ -93,7 +93,7 @@ export default function useShiki() {
9393
}
9494
}
9595
resolve();
96-
})));
96+
});
9797
}
9898

9999
onMounted(async () => {

0 commit comments

Comments
 (0)