Skip to content

Commit 3027788

Browse files
rudraswamy.crudraswamy.c
authored andcommitted
PWA-3260 :colud instance working fine now
1 parent 1466903 commit 3027788

File tree

1 file changed

+22
-26
lines changed
  • packages/venia-ui/lib/RootComponents/CMS

1 file changed

+22
-26
lines changed

packages/venia-ui/lib/RootComponents/CMS/cms.js

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,30 @@ const CMSPage = props => {
1515
const talonProps = useCmsPage({ identifier });
1616
const { cmsPage, shouldShowLoadingIndicator } = talonProps;
1717
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);
3935
}
4036
}
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+
});
4642
if (shouldShowLoadingIndicator) {
4743
return <CMSPageShimmer classes={classes} />;
4844
}

0 commit comments

Comments
 (0)