Skip to content

Commit

Permalink
fix: React-router to merge components
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Dec 6, 2018
1 parent 3b11866 commit f45fee0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
5 changes: 2 additions & 3 deletions src/reconciler/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ export const areSwappable = (a, b) => {
if (isFunctional(a)) {
const nameA = getComponentDisplayName(a)
return (
(areNamesEqual(nameA, getComponentDisplayName(b)) &&
nameA !== 'Component') ||
haveTextSimilarity(String(a), String(b))
areNamesEqual(nameA, getComponentDisplayName(b)) ||
(nameA !== 'Component' && haveTextSimilarity(String(a), String(b)))
)
}
return false
Expand Down
34 changes: 23 additions & 11 deletions test/AppContainer.dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ describe(`AppContainer (dev)`, () => {

class MountSpy extends PureComponent {
static displayName = 'MountSpy'

componentWillUnmount() {
spy()
}
Expand All @@ -826,6 +827,7 @@ describe(`AppContainer (dev)`, () => {
return <span>I am old</span>
}
}

const FRW = React.forwardRef(() => (
<span>
<MountSpy />
Expand All @@ -851,6 +853,7 @@ describe(`AppContainer (dev)`, () => {
{
class MountSpy extends PureComponent {
static displayName = 'MountSpy'

componentWillUnmount() {
spy()
}
Expand All @@ -859,6 +862,7 @@ describe(`AppContainer (dev)`, () => {
return <span>I am new</span>
}
}

const FRW = React.forwardRef(() => (
<span>
<MountSpy />
Expand All @@ -882,6 +886,7 @@ describe(`AppContainer (dev)`, () => {

class MountSpy extends PureComponent {
static displayName = 'MountSpy'

componentWillUnmount() {
spy()
}
Expand Down Expand Up @@ -921,6 +926,7 @@ describe(`AppContainer (dev)`, () => {
{
class MountSpy extends PureComponent {
static displayName = 'MountSpy'

componentWillUnmount() {
spy()
}
Expand Down Expand Up @@ -1651,19 +1657,25 @@ describe(`AppContainer (dev)`, () => {
}

let child = 1
const childA = () => (
<div>
a <MountSpy />
</div>
)
const childB = () => (
<div>
b <MountSpy />
</div>
)
const childs = [
function Child() {
return (
<div>
a <MountSpy />
</div>
)
},
function Child() {
return (
<div>
b <MountSpy />
</div>
)
},
]

function getChild() {
return child === 1 ? childA : childB
return child === 1 ? childs[0] : childs[1]
}

class Layout extends Component {
Expand Down

0 comments on commit f45fee0

Please sign in to comment.