File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -199,7 +199,7 @@ class OutPortal<C extends Component<any>> extends React.PureComponent<OutPortalP
199
199
200
200
// If we're switching portal nodes, we need to clean up the current one first.
201
201
if ( this . currentPortalNode && node !== this . currentPortalNode ) {
202
- this . currentPortalNode . unmount ( ) ;
202
+ this . currentPortalNode . unmount ( this . placeholderNode . current ! ) ;
203
203
this . currentPortalNode = node ;
204
204
}
205
205
Original file line number Diff line number Diff line change @@ -226,6 +226,40 @@ storiesOf('Portals', module)
226
226
< Parent />
227
227
</ div > ;
228
228
} )
229
+ . add ( "swap nodes between different locations" , ( ) => {
230
+ const numberOfNodes = 5 ;
231
+ const initialOrder = [ ] ;
232
+ for ( let i = 0 ; i < numberOfNodes ; i ++ ) {
233
+ initialOrder [ i ] = i ;
234
+ }
235
+
236
+ const ExampleContent = ( { content } ) => String ( content ) ;
237
+
238
+ const ChangeLayoutWithoutUnmounting = ( ) => {
239
+ const nodes = React . useMemo (
240
+ ( ) => initialOrder . map ( createHtmlPortalNode ) ,
241
+ [ ]
242
+ ) ;
243
+ const [ order , setOrder ] = React . useState ( initialOrder ) ;
244
+ return (
245
+ < div >
246
+ < button onClick = { ( ) => setOrder ( order . slice ( ) . reverse ( ) ) } >
247
+ Click to reverse the order
248
+ </ button >
249
+ { nodes . map ( ( node , index ) => (
250
+ < InPortal node = { node } >
251
+ < ExampleContent content = { index } />
252
+ </ InPortal >
253
+ ) ) }
254
+ { order . map ( ( position ) => (
255
+ < OutPortal node = { nodes [ position ] } />
256
+ ) ) }
257
+ </ div >
258
+ ) ;
259
+ } ;
260
+
261
+ return < ChangeLayoutWithoutUnmounting /> ;
262
+ } )
229
263
. add ( 'Example from README' , ( ) => {
230
264
const MyExpensiveComponent = ( ) => 'expensive!' ;
231
265
You can’t perform that action at this time.
0 commit comments