Skip to content

Commit c6934ed

Browse files
authored
Merge pull request #774 from webermayank/fix-multiple-p5scriptTag
fix Reference pages with multiple examples load p5 multiple times
2 parents 8e571e8 + d18276e commit c6934ed

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/components/CodeEmbed/index.jsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ export const CodeEmbed = (props) => {
6767
setRendered(true);
6868

6969
// Includes p5.min.js script to be used by `CodeFrame` iframe(s)
70-
const p5ScriptElement = document.createElement("script");
71-
p5ScriptElement.id = "p5ScriptTag";
72-
p5ScriptElement.src = cdnLibraryUrl;
73-
document.head.appendChild(p5ScriptElement);
70+
if (!document.getElementById("p5ScriptTag")) {
71+
const p5ScriptElement = document.createElement("script");
72+
p5ScriptElement.id = "p5ScriptTag";
73+
p5ScriptElement.src = cdnLibraryUrl;
74+
document.head.appendChild(p5ScriptElement);
75+
}
7476
}, []);
7577

7678
if (!rendered) return <div className="code-placeholder" />;

0 commit comments

Comments
 (0)