2929 Placement,
3030 Update,
3131 Callback,
32+ ContentReset,
3233} = require ( 'ReactTypeOfSideEffect' ) ;
3334
3435module . exports = function < T , P , I , TI , C > (
@@ -37,6 +38,7 @@ module.exports = function<T, P, I, TI, C>(
3738) {
3839
3940 const updateContainer = config . updateContainer ;
41+ const resetTextContent = config . resetTextContent ;
4042 const commitUpdate = config . commitUpdate ;
4143 const commitTextUpdate = config . commitTextUpdate ;
4244
@@ -67,12 +69,12 @@ module.exports = function<T, P, I, TI, C>(
6769 }
6870 }
6971
70- function getHostParent ( fiber : Fiber ) : ?I {
72+ function getHostParent ( fiber : Fiber ) : ?Fiber {
7173 let parent = fiber . return ;
7274 while ( parent ) {
7375 switch ( parent . tag ) {
7476 case HostComponent :
75- return parent . stateNode ;
77+ return parent ;
7678 case HostContainer :
7779 // TODO: Currently we use the updateContainer feature to update these,
7880 // but we should be able to handle this case too.
@@ -124,10 +126,19 @@ module.exports = function<T, P, I, TI, C>(
124126
125127 function commitInsertion ( finishedWork : Fiber ) : void {
126128 // Recursively insert all host nodes into the parent.
127- const parent = getHostParent ( finishedWork ) ;
128- if ( ! parent ) {
129+ const parentFiber = getHostParent ( finishedWork ) ;
130+ if ( ! parentFiber ) {
129131 return ;
130132 }
133+ const parent : I = parentFiber . stateNode ;
134+
135+ if ( parentFiber . effectTag & ContentReset ) {
136+ // Reset the text content of the parent before doing any insertions
137+ resetTextContent ( parent ) ;
138+ // Clear ContentReset from the effect tag
139+ parentFiber . effectTag &= ~ ContentReset ;
140+ }
141+
131142 const before = getHostSibling ( finishedWork ) ;
132143 // We only have the top Fiber that was inserted but we need recurse down its
133144 // children to find all the terminal nodes.
@@ -219,7 +230,8 @@ module.exports = function<T, P, I, TI, C>(
219230
220231 function commitDeletion ( current : Fiber ) : void {
221232 // Recursively delete all host nodes from the parent.
222- const parent = getHostParent ( current ) ;
233+ const parentFiber = getHostParent ( current ) ;
234+ const parent = parentFiber ? parentFiber . stateNode : null ;
223235 // Detach refs and call componentWillUnmount() on the whole subtree.
224236 unmountHostComponents ( parent , current ) ;
225237
0 commit comments