mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-15 01:03:03 +08:00
fix(react): duplicate page transitions do not happen on react 18 (#25798)
resolves #25797
This commit is contained in:
@ -206,8 +206,18 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
|
|||||||
registerIonPage(page: HTMLElement, routeInfo: RouteInfo) {
|
registerIonPage(page: HTMLElement, routeInfo: RouteInfo) {
|
||||||
const foundView = this.context.findViewItemByRouteInfo(routeInfo, this.id);
|
const foundView = this.context.findViewItemByRouteInfo(routeInfo, this.id);
|
||||||
if (foundView) {
|
if (foundView) {
|
||||||
|
const oldPageElement = foundView.ionPageElement;
|
||||||
foundView.ionPageElement = page;
|
foundView.ionPageElement = page;
|
||||||
foundView.ionRoute = true;
|
foundView.ionRoute = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* React 18 will unmount and remount IonPage
|
||||||
|
* elements in development mode when using createRoot.
|
||||||
|
* This can cause duplicate page transitions to occur.
|
||||||
|
*/
|
||||||
|
if (oldPageElement === page) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.handlePageTransition(routeInfo);
|
this.handlePageTransition(routeInfo);
|
||||||
}
|
}
|
||||||
|
@ -18,16 +18,26 @@ export class OutletPageManager extends React.Component<OutletPageManagerProps> {
|
|||||||
ionLifeCycleContext!: React.ContextType<typeof IonLifeCycleContext>;
|
ionLifeCycleContext!: React.ContextType<typeof IonLifeCycleContext>;
|
||||||
context!: React.ContextType<typeof StackContext>;
|
context!: React.ContextType<typeof StackContext>;
|
||||||
ionRouterOutlet: HTMLIonRouterOutletElement | undefined;
|
ionRouterOutlet: HTMLIonRouterOutletElement | undefined;
|
||||||
|
outletIsReady: boolean;
|
||||||
|
|
||||||
constructor(props: OutletPageManagerProps) {
|
constructor(props: OutletPageManagerProps) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
|
this.outletIsReady = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
if (this.ionRouterOutlet) {
|
if (this.ionRouterOutlet) {
|
||||||
|
/**
|
||||||
|
* This avoids multiple raf calls
|
||||||
|
* when React unmounts + remounts components.
|
||||||
|
*/
|
||||||
|
if (!this.outletIsReady) {
|
||||||
componentOnReady(this.ionRouterOutlet, () => {
|
componentOnReady(this.ionRouterOutlet, () => {
|
||||||
|
this.outletIsReady = true;
|
||||||
this.context.registerIonPage(this.ionRouterOutlet!, this.props.routeInfo!);
|
this.context.registerIonPage(this.ionRouterOutlet!, this.props.routeInfo!);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.ionRouterOutlet.addEventListener(
|
this.ionRouterOutlet.addEventListener(
|
||||||
'ionViewWillEnter',
|
'ionViewWillEnter',
|
||||||
|
Reference in New Issue
Block a user