Skip to content

Commit e12717c

Browse files
authored
fix(apply): custom apps for 1.2.78 (#3643)
1 parent 53b97e8 commit e12717c

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/apply/apply.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ func insertCustomApp(jsPath string, flags Flag) {
273273
// React element/route patterns for path matching
274274
elementPatterns := []string{
275275
// JSX pattern (1.2.78+): (0,S.jsx)(se.qh,{path:"/collection/*",element:...})
276-
`(\([\w$\.,]+\))\(([\w\.]+),\{path:"/collection(?:/[\w\*]+)?",?(element|children)?`,
276+
// Settings page should be more consistent with having no conditional renders
277+
`(\([\w$\.,]+\))\(([\w\.]+),\{path:"/settings(?:/[\w\*]+)?",?(element|children)?`,
277278
// createElement pattern: X.createElement(Y,{path:"/collection"...})
278279
`([\w_\$][\w_\$\d]*(?:\(\))?\.createElement|\([\w$\.,]+\))\(([\w\.]+),\{path:"\/collection"(?:,(element|children)?[:.\w,{}()$/*"]+)?\}`,
279280
}
@@ -332,12 +333,20 @@ func insertCustomApp(jsPath string, flags Flag) {
332333
return fmt.Sprintf("{%s%s", appMap, submatches[1])
333334
})
334335

335-
utils.ReplaceOnce(
336-
&content,
336+
// Seek to the full matched React.lazy pattern
337+
matchedReactPattern = utils.SeekToCloseParen(
338+
content,
337339
matchedReactPattern,
338-
func(submatches ...string) string {
339-
return fmt.Sprintf("%s%s", submatches[0], appReactMap)
340-
})
340+
'(',
341+
')',
342+
)
343+
344+
content = strings.Replace(
345+
content,
346+
matchedReactPattern,
347+
fmt.Sprintf("%s%s", matchedReactPattern, appReactMap),
348+
1,
349+
)
341350

342351
utils.ReplaceOnce(
343352
&content,

src/utils/utils.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,18 @@ func SeekToCloseParen(content string, regexpTerm string, leftChar, rightChar byt
351351
start := loc[0]
352352
end := start
353353
count := 0
354+
init := false
355+
354356
for {
355-
if content[end] == leftChar {
357+
switch content[end] {
358+
case leftChar:
356359
count += 1
357-
} else if content[end] == rightChar {
360+
init = true
361+
case rightChar:
358362
count -= 1
359363
}
360364
end += 1
361-
if count == 0 {
365+
if count == 0 && init {
362366
break
363367
}
364368
}

0 commit comments

Comments
 (0)