Skip to content

Commit 43c7a44

Browse files
committed
Fix tests
1 parent 832a398 commit 43c7a44

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/js/packages/@reactpy/client/src/components.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,8 @@ function ScriptElement({ model }: { model: ReactPyVdom }) {
120120
const ref = useRef<HTMLDivElement | null>(null);
121121

122122
React.useEffect(() => {
123-
// Fetch the script's content
124-
const scriptContent = model?.children?.filter(
125-
(value): value is string => typeof value == "string",
126-
)[0];
127-
128-
// Don't run if the parent element or script content is missing
129-
if (!ref.current || !scriptContent) {
123+
// Don't run if the parent element is missing
124+
if (!ref.current) {
130125
return;
131126
}
132127

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

139-
// Append the script content to the script element
140-
scriptElement.appendChild(document.createTextNode(scriptContent));
134+
// Add the script content as text
135+
const scriptContent = model?.children?.filter(
136+
(value): value is string => typeof value == "string",
137+
)[0];
138+
if (scriptContent) {
139+
scriptElement.appendChild(document.createTextNode(scriptContent));
140+
}
141+
142+
// Append the script element to the parent element
141143
ref.current.appendChild(scriptElement);
142144

143145
// Remove the script element when the component is unmounted

0 commit comments

Comments
 (0)