diff --git a/src/apply/apply.go b/src/apply/apply.go index 58c40222bc..d66a245131 100644 --- a/src/apply/apply.go +++ b/src/apply/apply.go @@ -273,7 +273,8 @@ func insertCustomApp(jsPath string, flags Flag) { // React element/route patterns for path matching elementPatterns := []string{ // JSX pattern (1.2.78+): (0,S.jsx)(se.qh,{path:"/collection/*",element:...}) - `(\([\w$\.,]+\))\(([\w\.]+),\{path:"/collection(?:/[\w\*]+)?",?(element|children)?`, + // Settings page should be more consistent with having no conditional renders + `(\([\w$\.,]+\))\(([\w\.]+),\{path:"/settings(?:/[\w\*]+)?",?(element|children)?`, // createElement pattern: X.createElement(Y,{path:"/collection"...}) `([\w_\$][\w_\$\d]*(?:\(\))?\.createElement|\([\w$\.,]+\))\(([\w\.]+),\{path:"\/collection"(?:,(element|children)?[:.\w,{}()$/*"]+)?\}`, } @@ -332,12 +333,20 @@ func insertCustomApp(jsPath string, flags Flag) { return fmt.Sprintf("{%s%s", appMap, submatches[1]) }) - utils.ReplaceOnce( - &content, + // Seek to the full matched React.lazy pattern + matchedReactPattern = utils.SeekToCloseParen( + content, matchedReactPattern, - func(submatches ...string) string { - return fmt.Sprintf("%s%s", submatches[0], appReactMap) - }) + '(', + ')', + ) + + content = strings.Replace( + content, + matchedReactPattern, + fmt.Sprintf("%s%s", matchedReactPattern, appReactMap), + 1, + ) utils.ReplaceOnce( &content, diff --git a/src/utils/utils.go b/src/utils/utils.go index cd342cfe4c..f5d52d3239 100644 --- a/src/utils/utils.go +++ b/src/utils/utils.go @@ -351,14 +351,18 @@ func SeekToCloseParen(content string, regexpTerm string, leftChar, rightChar byt start := loc[0] end := start count := 0 + init := false + for { - if content[end] == leftChar { + switch content[end] { + case leftChar: count += 1 - } else if content[end] == rightChar { + init = true + case rightChar: count -= 1 } end += 1 - if count == 0 { + if count == 0 && init { break } }