Skip to content

Commit 884df62

Browse files
committed
Test case for reentrant mounting in synchronous mode
1 parent c79af45 commit 884df62

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

scripts/fiber/tests-failing.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ src/renderers/shared/shared/__tests__/ReactUpdates-test.js
8989
* throws in setState if the update callback is not a function
9090
* throws in replaceState if the update callback is not a function
9191
* throws in forceUpdate if the update callback is not a function
92+
* handles reentrant mounting in synchronous mode
9293

9394
src/renderers/shared/shared/__tests__/refs-test.js
9495
* Should increase refs with an increase in divs

src/renderers/shared/shared/__tests__/ReactUpdates-test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,4 +1105,41 @@ describe('ReactUpdates', () => {
11051105
});
11061106
expect(container.textContent).toBe('b');
11071107
});
1108+
1109+
it('handles reentrant mounting in synchronous mode', () => {
1110+
var mounts = 0;
1111+
class Editor extends React.Component {
1112+
render() {
1113+
return <div>{this.props.text}</div>;
1114+
}
1115+
componentDidMount() {
1116+
mounts++;
1117+
// This should be called only once but we guard just in case.
1118+
if (!this.props.rendered) {
1119+
this.props.onChange({rendered: true});
1120+
}
1121+
}
1122+
}
1123+
1124+
var container = document.createElement('div');
1125+
function render() {
1126+
ReactDOM.render(
1127+
<Editor
1128+
onChange={(newProps) => {
1129+
props = {...props, ...newProps};
1130+
render();
1131+
}}
1132+
{...props}
1133+
/>,
1134+
container
1135+
);
1136+
}
1137+
1138+
var props = {text: 'hello', rendered: false};
1139+
render();
1140+
props = {...props, text: 'goodbye'};
1141+
render();
1142+
expect(container.textContent).toBe('goodbye');
1143+
expect(mounts).toBe(1);
1144+
});
11081145
});

0 commit comments

Comments
 (0)