Skip to content

Commit 7e80881

Browse files
committed
fix: Fragment with a single element. fixes #956
1 parent 949f859 commit 7e80881

File tree

2 files changed

+72
-3
lines changed

2 files changed

+72
-3
lines changed

Diff for: src/reconciler/hotReplacementRender.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ const mergeInject = (a, b, instance) => {
215215
const transformFlowNode = flow =>
216216
flow.reduce((acc, node) => {
217217
if (isFragmentNode(node) && node.props && node.props.children) {
218-
return [...acc, ...filterNullArray(node.props.children)]
218+
return [...acc, ...filterNullArray(asArray(node.props.children))]
219219
}
220220
return [...acc, node]
221221
}, [])

Diff for: test/AppContainer.dev.test.js

+71-2
Original file line numberDiff line numberDiff line change
@@ -1871,6 +1871,69 @@ describe(`AppContainer (dev)`, () => {
18711871
expect(wrapper.update().text()).toBe('PATCHED + 6 v2')
18721872
})
18731873

1874+
it('hot-reloads children inside simple Fragments', () => {
1875+
if (React.version.startsWith('16')) {
1876+
const unmount = jest.fn()
1877+
1878+
class InnerComponent extends Component {
1879+
componentWillUnmount() {
1880+
unmount()
1881+
}
1882+
1883+
render() {
1884+
return <span>internal</span>
1885+
}
1886+
}
1887+
InnerComponent.displayName = 'InnerComponent'
1888+
1889+
const App = () => (
1890+
<React.Fragment>
1891+
<button>
1892+
text <InnerComponent />
1893+
</button>
1894+
</React.Fragment>
1895+
)
1896+
1897+
RHL.register(App, 'App', 'test.js')
1898+
1899+
const wrapper = mount(
1900+
<AppContainer>
1901+
<App />
1902+
</AppContainer>,
1903+
)
1904+
1905+
{
1906+
class InnerComponent extends Component {
1907+
componentWillUnmount() {
1908+
unmount()
1909+
}
1910+
1911+
render() {
1912+
return <span>internal</span>
1913+
}
1914+
}
1915+
InnerComponent.displayName = 'InnerComponent'
1916+
1917+
const App = () => (
1918+
<React.Fragment>
1919+
<button>
1920+
another text<InnerComponent />
1921+
</button>
1922+
</React.Fragment>
1923+
)
1924+
RHL.register(App, 'App', 'test.js')
1925+
1926+
wrapper.setProps({ children: <App /> })
1927+
}
1928+
1929+
expect(unmount).toHaveBeenCalledTimes(0)
1930+
expect(wrapper.update().text()).toBe('another textinternal')
1931+
} else {
1932+
// React 15 is always ok
1933+
expect(true).toBe(true)
1934+
}
1935+
})
1936+
18741937
it('hot-reloads children inside Fragments', () => {
18751938
if (React.version.startsWith('16')) {
18761939
const unmount = jest.fn()
@@ -1904,6 +1967,9 @@ describe(`AppContainer (dev)`, () => {
19041967
<InnerItem />
19051968
</li>
19061969
<li>3</li>
1970+
<React.Fragment>
1971+
<span>F</span>
1972+
</React.Fragment>
19071973
</React.Fragment>
19081974
)
19091975
//
@@ -1920,7 +1986,7 @@ describe(`AppContainer (dev)`, () => {
19201986
)
19211987

19221988
expect(wrapper.update().text()).toBe(
1923-
'1-1-OldInnerComponent-3-OldInnerComponent3',
1989+
'1-1-OldInnerComponent-3-OldInnerComponent3F',
19241990
)
19251991
{
19261992
class InnerComponent extends Component {
@@ -1941,6 +2007,9 @@ describe(`AppContainer (dev)`, () => {
19412007
-2-<InnerComponent />
19422008
{false && <div>hole</div>}
19432009
-3-<InnerComponent />
2010+
<React.Fragment>
2011+
<span>*</span>
2012+
</React.Fragment>
19442013
</React.Fragment>
19452014
)
19462015
RHL.register(InnerItem, 'InnerItem', 'test.js')
@@ -1949,7 +2018,7 @@ describe(`AppContainer (dev)`, () => {
19492018
}
19502019
expect(unmount).toHaveBeenCalledTimes(0)
19512020
expect(wrapper.update().text()).toBe(
1952-
'1-2-NewInnerComponent-3-NewInnerComponent3',
2021+
'1-2-NewInnerComponent-3-NewInnerComponent*3F', // it should not be so!
19532022
)
19542023
} else {
19552024
// React 15 is always ok

0 commit comments

Comments
 (0)