Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Archmonger committed Jan 21, 2025
1 parent 832a398 commit 43c7a44
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/js/packages/@reactpy/client/src/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,8 @@ function ScriptElement({ model }: { model: ReactPyVdom }) {
const ref = useRef<HTMLDivElement | null>(null);

React.useEffect(() => {
// Fetch the script's content
const scriptContent = model?.children?.filter(
(value): value is string => typeof value == "string",
)[0];

// Don't run if the parent element or script content is missing
if (!ref.current || !scriptContent) {
// Don't run if the parent element is missing
if (!ref.current) {
return;
}

Expand All @@ -136,8 +131,15 @@ function ScriptElement({ model }: { model: ReactPyVdom }) {
scriptElement.setAttribute(k, v);
}

// Append the script content to the script element
scriptElement.appendChild(document.createTextNode(scriptContent));
// Add the script content as text
const scriptContent = model?.children?.filter(
(value): value is string => typeof value == "string",
)[0];
if (scriptContent) {
scriptElement.appendChild(document.createTextNode(scriptContent));
}

// Append the script element to the parent element
ref.current.appendChild(scriptElement);

// Remove the script element when the component is unmounted
Expand Down

0 comments on commit 43c7a44

Please sign in to comment.