This commit is contained in:
Hk-Gosuto
2024-10-28 13:09:30 +08:00
parent 0660a50dd4
commit 40b673054b
8 changed files with 148 additions and 13 deletions

View File

@@ -121,7 +121,25 @@ export function PreCode(props: { children: any }) {
codeElement.style.whiteSpace = "pre-wrap";
}
});
setTimeout(renderArtifacts, 1);
const observer = new MutationObserver((mutations) => {
for (const mutation of mutations) {
if (
mutation.type === "characterData" ||
mutation.type === "childList"
) {
renderArtifacts();
break;
}
}
});
observer.observe(ref.current, {
childList: true,
subtree: true,
characterData: true,
});
renderArtifacts();
return () => observer.disconnect();
}
}, []);