From f001b112a213ad603753bc1ad2f83b754a949373 Mon Sep 17 00:00:00 2001 From: Maarten Veenstra Date: Wed, 14 Jul 2021 14:47:44 +0200 Subject: [PATCH] avoid potentially slow regex call in renderJsx --- addons/docs/src/frameworks/react/jsxDecorator.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/docs/src/frameworks/react/jsxDecorator.tsx b/addons/docs/src/frameworks/react/jsxDecorator.tsx index 57dee05a5189..3e1ef836a41b 100644 --- a/addons/docs/src/frameworks/react/jsxDecorator.tsx +++ b/addons/docs/src/frameworks/react/jsxDecorator.tsx @@ -115,12 +115,14 @@ export const renderJsx = (code: React.ReactElement, options: JSXOptions) => { // @ts-ignore FIXME: workaround react-element-to-jsx-string const child = typeof c === 'number' ? c.toString() : c; let string = applyBeforeRender(reactElementToJSXString(child, opts as Options), options); - const matches = string.match(/\S+=\\"([^"]*)\\"/g); - if (matches) { - matches.forEach((match) => { - string = string.replace(match, match.replace(/"/g, "'")); - }); + if (string.indexOf('"') > -1) { + const matches = string.match(/\S+=\\"([^"]*)\\"/g); + if (matches) { + matches.forEach((match) => { + string = string.replace(match, match.replace(/"/g, "'")); + }); + } } return string;