Skip to content

Commit cdf21f6

Browse files
author
Bianca Del Carretto
committed
fix script evaluation on mount (without editing html markup) and replace eval with new Function (testing-library#10)
1 parent 3db3273 commit cdf21f6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Diff for: src/components/Preview.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,17 @@ function Preview({ markup, accessibleRoles, elements, dispatch }) {
6060
);
6161

6262
useEffect(() => {
63-
if (scripts.length) {
63+
if (scripts.length && htmlRoot.current) {
6464
try {
6565
scripts.forEach((script) => {
66-
window.eval(script.scriptCode);
66+
const executeScript = new Function(script.scriptCode);
67+
executeScript();
6768
});
6869
} catch {
6970
return;
7071
}
7172
}
72-
}, [scripts]);
73+
}, [scripts, htmlRoot.current]);
7374

7475
useEffect(() => {
7576
setRoles(Object.keys(accessibleRoles || {}).sort());

0 commit comments

Comments
 (0)