fix(live-codeblock): stabilize react-live transformCode callback, fix editor/preview desync (#9631)

This commit is contained in:
Sébastien Lorber 2023-12-14 12:56:28 +01:00 committed by GitHub
parent 61116e2ad6
commit 991429ff8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -98,6 +98,10 @@ function EditorWithHeader() {
);
}
// this should rather be a stable function
// see https://github.com/facebook/docusaurus/issues/9630#issuecomment-1855682643
const DEFAULT_TRANSFORM_CODE = (code: string) => `${code};`;
export default function Playground({
children,
transformCode,
@ -118,7 +122,7 @@ export default function Playground({
<LiveProvider
code={children.replace(/\n$/, '')}
noInline={noInline}
transformCode={transformCode ?? ((code) => `${code};`)}
transformCode={transformCode ?? DEFAULT_TRANSFORM_CODE}
theme={prismTheme}
{...props}>
{playgroundPosition === 'top' ? (