Visualize Your Ideas With Code
fix(docs): support multiple fiddles again (#574)
Jacobd1867e90998f
diff --git a/packages/docs/src/components/Fiddle/SharedPlayer.ts b/packages/docs/src/components/Fiddle/SharedPlayer.tsindex 0ece0da4..b14429c2 100644--- a/packages/docs/src/components/Fiddle/SharedPlayer.ts+++ b/packages/docs/src/components/Fiddle/SharedPlayer.ts@@ -81,6 +81,12 @@ export function borrowPlayer(PlayerInstance.playback.previousScene,);});+ PlayerInstance.onRecalculated.subscribe(() => {+ if (StageInstance.finalBuffer.parentElement !== CurrentParent) {+ CurrentParent?.append(StageInstance.finalBuffer);+ CurrentSetter(PlayerInstance);+ }+ });// TODO Find a way to attach the logger only for DEV:// ProjectInstance.logger.onLogged.subscribe(console.log);@@ -93,9 +99,6 @@ export function borrowPlayer(PlayerInstance.activate();PlayerInstance.requestReset();-- CurrentParent?.append(StageInstance.finalBuffer);- CurrentSetter(PlayerInstance);return PlayerInstance;}diff --git a/packages/docs/src/components/Fiddle/index.tsx b/packages/docs/src/components/Fiddle/index.tsxindex c1c9eee1..f1a85257 100644--- a/packages/docs/src/components/Fiddle/index.tsx+++ b/packages/docs/src/components/Fiddle/index.tsx@@ -62,16 +62,12 @@ export default function Fiddle({children}: FiddleProps) {const [initialState, setInitialState] = useState<EditorState>(null);const update = (newDoc: Text, animate = true) => {- if (lastDoc?.eq(newDoc)) {- return;- }-borrowPlayer(setPlayer, previewRef.current);const newError = transform(newDoc.sliceString(0));setError(newError);if (!newError) {setLastDoc(newDoc);- if (animate) {+ if (animate && !lastDoc?.eq(newDoc)) {previewRef.current.animate(highlight(), {duration: 300});}}