@@ -18,7 +18,8 @@ interface StackManagerProps {
18
18
19
19
interface StackManagerState { }
20
20
21
- const isViewVisible = ( el : HTMLElement ) => ! el . classList . contains ( 'ion-page-invisible' ) && ! el . classList . contains ( 'ion-page-hidden' ) ;
21
+ const isViewVisible = ( el : HTMLElement ) =>
22
+ ! el . classList . contains ( 'ion-page-invisible' ) && ! el . classList . contains ( 'ion-page-hidden' ) ;
22
23
23
24
export class StackManager extends React . PureComponent < StackManagerProps , StackManagerState > {
24
25
id : string ;
@@ -33,6 +34,7 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
33
34
isInOutlet : ( ) => true ,
34
35
} ;
35
36
37
+ private clearOutletTimeout : any ;
36
38
private pendingPageTransition = false ;
37
39
38
40
constructor ( props : StackManagerProps ) {
@@ -46,9 +48,20 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
46
48
}
47
49
48
50
componentDidMount ( ) {
51
+ if ( this . clearOutletTimeout ) {
52
+ /**
53
+ * The clearOutlet integration with React Router is a bit hacky.
54
+ * It uses a timeout to clear the outlet after a transition.
55
+ * In React v18, components are mounted and unmounted in development mode
56
+ * to check for side effects.
57
+ *
58
+ * This clearTimeout prevents the outlet from being cleared when the component is re-mounted,
59
+ * which should only happen in development mode and as a result of a hot reload.
60
+ */
61
+ clearTimeout ( this . clearOutletTimeout ) ;
62
+ }
49
63
if ( this . routerOutletElement ) {
50
64
this . setupRouterOutlet ( this . routerOutletElement ) ;
51
- // console.log(`SM Mount - ${this.routerOutletElement.id} (${this.id})`);
52
65
this . handlePageTransition ( this . props . routeInfo ) ;
53
66
}
54
67
}
@@ -67,8 +80,7 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
67
80
}
68
81
69
82
componentWillUnmount ( ) {
70
- // console.log(`SM UNMount - ${(this.routerOutletElement?.id as any).id} (${this.id})`);
71
- this . context . clearOutlet ( this . id ) ;
83
+ this . clearOutletTimeout = this . context . clearOutlet ( this . id ) ;
72
84
}
73
85
74
86
async handlePageTransition ( routeInfo : RouteInfo ) {
@@ -142,13 +154,20 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
142
154
* to find the leaving view item to transition between.
143
155
*/
144
156
if ( ! leavingViewItem && this . props . routeInfo . prevRouteLastPathname ) {
145
- leavingViewItem = this . context . findViewItemByPathname ( this . props . routeInfo . prevRouteLastPathname , this . id ) ;
157
+ leavingViewItem = this . context . findViewItemByPathname (
158
+ this . props . routeInfo . prevRouteLastPathname ,
159
+ this . id
160
+ ) ;
146
161
}
147
162
148
163
/**
149
164
* If the entering view is already visible and the leaving view is not, the transition does not need to occur.
150
165
*/
151
- if ( isViewVisible ( enteringViewItem . ionPageElement ) && leavingViewItem !== undefined && ! isViewVisible ( leavingViewItem . ionPageElement ! ) ) {
166
+ if (
167
+ isViewVisible ( enteringViewItem . ionPageElement ) &&
168
+ leavingViewItem !== undefined &&
169
+ ! isViewVisible ( leavingViewItem . ionPageElement ! )
170
+ ) {
152
171
return ;
153
172
}
154
173
@@ -197,11 +216,16 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
197
216
const canStart = ( ) => {
198
217
const config = getConfig ( ) ;
199
218
const swipeEnabled = config && config . get ( 'swipeBackEnabled' , routerOutlet . mode === 'ios' ) ;
200
- if ( ! swipeEnabled ) { return false ; }
219
+ if ( ! swipeEnabled ) {
220
+ return false ;
221
+ }
201
222
202
223
const { routeInfo } = this . props ;
203
224
204
- const propsToUse = ( this . prevProps && this . prevProps . routeInfo . pathname === routeInfo . pushedByRoute ) ? this . prevProps . routeInfo : { pathname : routeInfo . pushedByRoute || '' } as any ;
225
+ const propsToUse =
226
+ this . prevProps && this . prevProps . routeInfo . pathname === routeInfo . pushedByRoute
227
+ ? this . prevProps . routeInfo
228
+ : ( { pathname : routeInfo . pushedByRoute || '' } as any ) ;
205
229
const enteringViewItem = this . context . findViewItemByRouteInfo ( propsToUse , this . id , false ) ;
206
230
207
231
return (
@@ -213,7 +237,6 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
213
237
* root url.
214
238
*/
215
239
enteringViewItem . mount &&
216
-
217
240
/**
218
241
* When on the first page (whatever view
219
242
* you land on after the root url) it
@@ -229,7 +252,10 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
229
252
const onStart = async ( ) => {
230
253
const { routeInfo } = this . props ;
231
254
232
- const propsToUse = ( this . prevProps && this . prevProps . routeInfo . pathname === routeInfo . pushedByRoute ) ? this . prevProps . routeInfo : { pathname : routeInfo . pushedByRoute || '' } as any ;
255
+ const propsToUse =
256
+ this . prevProps && this . prevProps . routeInfo . pathname === routeInfo . pushedByRoute
257
+ ? this . prevProps . routeInfo
258
+ : ( { pathname : routeInfo . pushedByRoute || '' } as any ) ;
233
259
const enteringViewItem = this . context . findViewItemByRouteInfo ( propsToUse , this . id , false ) ;
234
260
const leavingViewItem = this . context . findViewItemByRouteInfo ( routeInfo , this . id , false ) ;
235
261
@@ -257,7 +283,10 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
257
283
*/
258
284
const { routeInfo } = this . props ;
259
285
260
- const propsToUse = ( this . prevProps && this . prevProps . routeInfo . pathname === routeInfo . pushedByRoute ) ? this . prevProps . routeInfo : { pathname : routeInfo . pushedByRoute || '' } as any ;
286
+ const propsToUse =
287
+ this . prevProps && this . prevProps . routeInfo . pathname === routeInfo . pushedByRoute
288
+ ? this . prevProps . routeInfo
289
+ : ( { pathname : routeInfo . pushedByRoute || '' } as any ) ;
261
290
const enteringViewItem = this . context . findViewItemByRouteInfo ( propsToUse , this . id , false ) ;
262
291
const leavingViewItem = this . context . findViewItemByRouteInfo ( routeInfo , this . id , false ) ;
263
292
@@ -279,12 +308,12 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
279
308
ionPageElement . classList . add ( 'ion-page-hidden' ) ;
280
309
}
281
310
}
282
- }
311
+ } ;
283
312
284
313
routerOutlet . swipeHandler = {
285
314
canStart,
286
315
onStart,
287
- onEnd
316
+ onEnd,
288
317
} ;
289
318
}
290
319
@@ -333,7 +362,7 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
333
362
progressAnimation,
334
363
animationBuilder : routeInfo . routeAnimation ,
335
364
} ) ;
336
- }
365
+ } ;
337
366
338
367
const routerOutlet = this . routerOutletElement ! ;
339
368
0 commit comments