Skip to content

Commit 0a1e72e

Browse files
authored
fix(compat mode): don't inject inline scripts on server (#40)
1 parent 87d8099 commit 0a1e72e

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

components/HTMLBlock.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ const PropTypes = require('prop-types');
77
* @arg {string} html the HTML from which to extract script tags.
88
*/
99
const extractScripts = html => {
10+
if (typeof window === 'undefined' || !html) return () => {};
11+
1012
const regex = /<script\b[^>]*>([\s\S]*?)<\/script>/gim;
1113
const scripts = [...html.matchAll(regex)].map(m => m[1].trim());
14+
1215
return () => scripts.map(js => window.eval(js));
1316
};
1417

0 commit comments

Comments
 (0)