3030 Placement,
3131 Update,
3232 Callback,
33+ ContentReset,
3334} = require ( 'ReactTypeOfSideEffect' ) ;
3435
3536module . exports = function < T , P , I , TI , C > (
@@ -38,6 +39,7 @@ module.exports = function<T, P, I, TI, C>(
3839) {
3940
4041 const commitUpdate = config . commitUpdate ;
42+ const resetTextContent = config . resetTextContent ;
4143 const commitTextUpdate = config . commitTextUpdate ;
4244
4345 const appendChild = config . appendChild ;
@@ -83,6 +85,17 @@ module.exports = function<T, P, I, TI, C>(
8385 throw new Error ( 'Expected to find a host parent.' ) ;
8486 }
8587
88+ function getHostParentFiber ( fiber : Fiber ) : Fiber {
89+ let parent = fiber . return ;
90+ while ( parent ) {
91+ if ( isHostParent ( parent ) ) {
92+ return parent ;
93+ }
94+ parent = parent . return ;
95+ }
96+ throw new Error ( 'Expected to find a host parent.' ) ;
97+ }
98+
8699 function isHostParent ( fiber : Fiber ) : boolean {
87100 return (
88101 fiber . tag === HostComponent ||
@@ -133,12 +146,29 @@ module.exports = function<T, P, I, TI, C>(
133146 }
134147
135148 function commitPlacement ( finishedWork : Fiber ) : void {
136- // Clear effect from effect tag before any errors can be thrown, so that
137- // we don't attempt to do this again
138- finishedWork . effectTag &= ~ Placement ;
139-
140149 // Recursively insert all host nodes into the parent.
141- const parent = getHostParent ( finishedWork ) ;
150+ const parentFiber = getHostParentFiber ( finishedWork ) ;
151+ let parent ;
152+ switch ( parentFiber . tag ) {
153+ case HostComponent :
154+ parent = parentFiber . stateNode ;
155+ break ;
156+ case HostContainer :
157+ parent = parentFiber . stateNode . containerInfo ;
158+ break ;
159+ case Portal :
160+ parent = parentFiber . stateNode . containerInfo ;
161+ break ;
162+ default :
163+ throw new Error ( 'Invalid host parent fiber.' ) ;
164+ }
165+ if ( parentFiber . effectTag & ContentReset ) {
166+ // Reset the text content of the parent before doing any insertions
167+ resetTextContent ( parent ) ;
168+ // Clear ContentReset from the effect tag
169+ parentFiber . effectTag &= ~ ContentReset ;
170+ }
171+
142172 const before = getHostSibling ( finishedWork ) ;
143173 // We only have the top Fiber that was inserted but we need recurse down its
144174 // children to find all the terminal nodes.
0 commit comments