Skip to content

Commit

Permalink
Merge pull request #15581 from maerten/avoid-slow-docs-render-perf
Browse files Browse the repository at this point in the history
Avoid slow regex.match call in renderJsx
  • Loading branch information
shilman committed Jul 16, 2021
2 parents c09ce85 + f001b11 commit 12c6e95
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions addons/docs/src/frameworks/react/jsxDecorator.tsx
Expand Up @@ -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;
Expand Down

0 comments on commit 12c6e95

Please sign in to comment.