File tree Expand file tree Collapse file tree 1 file changed +11
-9
lines changed
src/js/packages/@reactpy/client/src Expand file tree Collapse file tree 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 }) {
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
You can’t perform that action at this time.
0 commit comments