Skip to content

Commit 008ff95

Browse files
committed
fix(react): synchronous outlet cleanup on unmount
1 parent 92398dc commit 008ff95

File tree

2 files changed

+2
-18
lines changed

2 files changed

+2
-18
lines changed

packages/react-router/src/ReactRouter/StackManager.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export class StackManager extends React.PureComponent<StackManagerProps> {
7171
isInOutlet: () => true,
7272
};
7373

74-
private clearOutletTimeout: any;
7574
private pendingPageTransition = false;
7675
private waitingForIonPage = false;
7776
private ionPageWaitTimeout?: ReturnType<typeof setTimeout>;
@@ -756,18 +755,6 @@ export class StackManager extends React.PureComponent<StackManagerProps> {
756755

757756
componentDidMount() {
758757
this._isMounted = true;
759-
if (this.clearOutletTimeout) {
760-
/**
761-
* The clearOutlet integration with React Router is a bit hacky.
762-
* It uses a timeout to clear the outlet after a transition.
763-
* In React v18, components are mounted and unmounted in development mode
764-
* to check for side effects.
765-
*
766-
* This clearTimeout prevents the outlet from being cleared when the component is re-mounted,
767-
* which should only happen in development mode and as a result of a hot reload.
768-
*/
769-
clearTimeout(this.clearOutletTimeout);
770-
}
771758
if (this.routerOutletElement) {
772759
this.setupRouterOutlet(this.routerOutletElement);
773760
this.handlePageTransition(this.props.routeInfo);
@@ -822,7 +809,7 @@ export class StackManager extends React.PureComponent<StackManagerProps> {
822809
hideIonPageElement(viewItem.ionPageElement);
823810
});
824811

825-
this.clearOutletTimeout = this.context.clearOutlet(this.id);
812+
this.context.clearOutlet(this.id);
826813
}
827814

828815
/**

packages/react/src/routing/ViewStacks.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ export abstract class ViewStacks {
2222
}
2323

2424
clear(outletId: string) {
25-
// Give some time for the leaving views to transition before removing
26-
return setTimeout(() => {
27-
delete this.viewStacks[outletId];
28-
}, 500);
25+
delete this.viewStacks[outletId];
2926
}
3027

3128
getViewItemsForOutlet(outletId: string) {

0 commit comments

Comments
 (0)