File tree 1 file changed +11
-9
lines changed
src/js/packages/@reactpy/client/src
1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -120,13 +120,8 @@ function ScriptElement({ model }: { model: ReactPyVdom }) {
120
120
const ref = useRef < HTMLDivElement | null > ( null ) ;
121
121
122
122
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 ) {
130
125
return ;
131
126
}
132
127
@@ -136,8 +131,15 @@ function ScriptElement({ model }: { model: ReactPyVdom }) {
136
131
scriptElement . setAttribute ( k , v ) ;
137
132
}
138
133
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
141
143
ref . current . appendChild ( scriptElement ) ;
142
144
143
145
// Remove the script element when the component is unmounted
You can’t perform that action at this time.
0 commit comments