Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(compat mode): don't inject inline scripts on server
  • Loading branch information
rafegoldberg committed Aug 11, 2020
commit b98a1e8f6ed71a9231e9b481e2c8d2861cfeeca3
3 changes: 3 additions & 0 deletions components/HTMLBlock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ const PropTypes = require('prop-types');
* @arg {string} html the HTML from which to extract script tags.
*/
const extractScripts = html => {
if (typeof window === 'undefined' || !html) return () => {};

const regex = /<script\b[^>]*>([\s\S]*?)<\/script>/gim;
const scripts = [...html.matchAll(regex)].map(m => m[1].trim());

return () => scripts.map(js => window.eval(js));
};

Expand Down