@@ -15,34 +15,30 @@ const CMSPage = props => {
15
15
const talonProps = useCmsPage ( { identifier } ) ;
16
16
const { cmsPage, shouldShowLoadingIndicator } = talonProps ;
17
17
const classes = useStyle ( defaultClasses , props . classes ) ;
18
-
19
- useEffect ( ( ) => {
20
- // Function to execute inline scripts safely
21
- const executeInlineScripts = document => {
22
- const scripts = document . getElementsByTagName ( 'script' ) ;
23
- for ( let i = 0 ; i < scripts . length ; i ++ ) {
24
- const scriptContent =
25
- scripts [ i ] . textContent || scripts [ i ] . innerText ;
26
- if ( scriptContent ) {
27
- try {
28
- // Execute script in a sandboxed environment
29
- const sandbox = { } ;
30
- const codeToExecute = `(function() { ${ scriptContent } })();` ;
31
- const executedScript = new Function (
32
- 'sandbox' ,
33
- codeToExecute
34
- ) ;
35
- executedScript ( sandbox ) ;
36
- } catch ( error ) {
37
- console . error ( 'Error executing inline script:' , error ) ;
38
- }
18
+ const executeInlineScript = ( ) => {
19
+ const scripts = document . getElementsByTagName ( 'script' ) ;
20
+ for ( let i = 0 ; i < scripts . length ; i ++ ) {
21
+ const scriptContent =
22
+ scripts [ i ] . textContent || scripts [ i ] . innerText ;
23
+ if ( scriptContent ) {
24
+ try {
25
+ // Execute script in a sandboxed environment
26
+ const sandbox = { } ;
27
+ const codeToExecute = `(function() { ${ scriptContent } })();` ;
28
+ const executedScript = new Function (
29
+ 'sandbox' ,
30
+ codeToExecute
31
+ ) ;
32
+ executedScript ( sandbox ) ;
33
+ } catch ( error ) {
34
+ console . error ( 'Error executing inline script:' , error ) ;
39
35
}
40
36
}
41
- } ;
42
-
43
- executeInlineScripts ( document ) ; // Pass the document or a specific element containing the content
44
- } , [ shouldShowLoadingIndicator ] ) ;
45
-
37
+ }
38
+ } ;
39
+ useEffect ( ( ) => {
40
+ executeInlineScript ( ) ;
41
+ } ) ;
46
42
if ( shouldShowLoadingIndicator ) {
47
43
return < CMSPageShimmer classes = { classes } /> ;
48
44
}
0 commit comments