Skip to content

Commit f45fee0

Browse files
committed
fix: React-router to merge components
1 parent 3b11866 commit f45fee0

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

src/reconciler/utils.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,8 @@ export const areSwappable = (a, b) => {
7676
if (isFunctional(a)) {
7777
const nameA = getComponentDisplayName(a)
7878
return (
79-
(areNamesEqual(nameA, getComponentDisplayName(b)) &&
80-
nameA !== 'Component') ||
81-
haveTextSimilarity(String(a), String(b))
79+
areNamesEqual(nameA, getComponentDisplayName(b)) ||
80+
(nameA !== 'Component' && haveTextSimilarity(String(a), String(b)))
8281
)
8382
}
8483
return false

test/AppContainer.dev.test.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ describe(`AppContainer (dev)`, () => {
818818

819819
class MountSpy extends PureComponent {
820820
static displayName = 'MountSpy'
821+
821822
componentWillUnmount() {
822823
spy()
823824
}
@@ -826,6 +827,7 @@ describe(`AppContainer (dev)`, () => {
826827
return <span>I am old</span>
827828
}
828829
}
830+
829831
const FRW = React.forwardRef(() => (
830832
<span>
831833
<MountSpy />
@@ -851,6 +853,7 @@ describe(`AppContainer (dev)`, () => {
851853
{
852854
class MountSpy extends PureComponent {
853855
static displayName = 'MountSpy'
856+
854857
componentWillUnmount() {
855858
spy()
856859
}
@@ -859,6 +862,7 @@ describe(`AppContainer (dev)`, () => {
859862
return <span>I am new</span>
860863
}
861864
}
865+
862866
const FRW = React.forwardRef(() => (
863867
<span>
864868
<MountSpy />
@@ -882,6 +886,7 @@ describe(`AppContainer (dev)`, () => {
882886

883887
class MountSpy extends PureComponent {
884888
static displayName = 'MountSpy'
889+
885890
componentWillUnmount() {
886891
spy()
887892
}
@@ -921,6 +926,7 @@ describe(`AppContainer (dev)`, () => {
921926
{
922927
class MountSpy extends PureComponent {
923928
static displayName = 'MountSpy'
929+
924930
componentWillUnmount() {
925931
spy()
926932
}
@@ -1651,19 +1657,25 @@ describe(`AppContainer (dev)`, () => {
16511657
}
16521658

16531659
let child = 1
1654-
const childA = () => (
1655-
<div>
1656-
a <MountSpy />
1657-
</div>
1658-
)
1659-
const childB = () => (
1660-
<div>
1661-
b <MountSpy />
1662-
</div>
1663-
)
1660+
const childs = [
1661+
function Child() {
1662+
return (
1663+
<div>
1664+
a <MountSpy />
1665+
</div>
1666+
)
1667+
},
1668+
function Child() {
1669+
return (
1670+
<div>
1671+
b <MountSpy />
1672+
</div>
1673+
)
1674+
},
1675+
]
16641676

16651677
function getChild() {
1666-
return child === 1 ? childA : childB
1678+
return child === 1 ? childs[0] : childs[1]
16671679
}
16681680

16691681
class Layout extends Component {

0 commit comments

Comments
 (0)