Skip to content

Commit

Permalink
Always render script element as plain HTML
Browse files Browse the repository at this point in the history
---

Co-authored-by: James Hutchison <[email protected]>
  • Loading branch information
Archmonger and JamesHutchison committed Oct 31, 2024
1 parent 0facdca commit 23c894f
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/js/packages/@reactpy/client/src/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,15 @@ function ScriptElement({ model }: { model: ReactPyVdom }) {
(value): value is string => typeof value == "string",
)[0];

let scriptElement: HTMLScriptElement;
if (model.attributes) {
scriptElement = document.createElement("script");
for (const [k, v] of Object.entries(model.attributes)) {
scriptElement.setAttribute(k, v);
}
if (scriptContent) {
scriptElement.appendChild(document.createTextNode(scriptContent));
}
ref.current.appendChild(scriptElement);
} else if (scriptContent) {
const scriptResult = eval(scriptContent);
if (typeof scriptResult == "function") {
return scriptResult();
}
const scriptElement: HTMLScriptElement = document.createElement("script");
for (const [k, v] of Object.entries(model.attributes || {})) {
scriptElement.setAttribute(k, v);
}
if (scriptContent) {
scriptElement.appendChild(document.createTextNode(scriptContent));
}
}, [model.key, ref.current]);
ref.current.appendChild(scriptElement);
}, [model.key]);

return <div ref={ref} />;
}
Expand Down

0 comments on commit 23c894f

Please sign in to comment.