File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
src/renderers/shared/shared/__tests__ Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,7 @@ src/renderers/shared/shared/__tests__/ReactUpdates-test.js
89
89
* throws in setState if the update callback is not a function
90
90
* throws in replaceState if the update callback is not a function
91
91
* throws in forceUpdate if the update callback is not a function
92
+ * handles reentrant mounting in synchronous mode
92
93
93
94
src/renderers/shared/shared/__tests__/refs-test.js
94
95
* Should increase refs with an increase in divs
Original file line number Diff line number Diff line change @@ -1105,4 +1105,41 @@ describe('ReactUpdates', () => {
1105
1105
} ) ;
1106
1106
expect ( container . textContent ) . toBe ( 'b' ) ;
1107
1107
} ) ;
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
+ } ) ;
1108
1145
} ) ;
You can’t perform that action at this time.
0 commit comments