@ionic/react-router 9.0.15-nightly.20261130 → 9.0.15-nightly.20261201

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1959,8 +1959,15 @@ class StackManager extends React.PureComponent {
1959
1959
  return;
1960
1960
  }
1961
1961
  this.lastTransition = currentTransition;
1962
- const shouldSkipAnimation = this.applySkipAnimationIfNeeded(enteringViewItem, leavingViewItem);
1963
- this.transitionPage(routeInfo, enteringViewItem, leavingViewItem, undefined, false, shouldSkipAnimation);
1962
+ // A page-less leaving view (e.g. a redirect) has nothing to animate out,
1963
+ // so transition the page shown before it instead. Look it up once and reuse
1964
+ // it for cleanup: applySkipAnimationIfNeeded may hide it, and the fallback
1965
+ // lookup only matches visible pages.
1966
+ const pageBehindPagelessView = this.findPageBehindPagelessView(routeInfo, enteringViewItem, leavingViewItem);
1967
+ const pageBehindIsVisible = pageBehindPagelessView?.ionPageElement && isViewVisible(pageBehindPagelessView.ionPageElement);
1968
+ const transitionLeavingViewItem = pageBehindIsVisible ? pageBehindPagelessView : leavingViewItem;
1969
+ const shouldSkipAnimation = this.applySkipAnimationIfNeeded(enteringViewItem, transitionLeavingViewItem);
1970
+ this.transitionPage(routeInfo, enteringViewItem, transitionLeavingViewItem, undefined, false, shouldSkipAnimation);
1964
1971
  if (shouldUnmountLeavingViewItem && leavingViewItem && enteringViewItem !== leavingViewItem) {
1965
1972
  // For replace actions, skip setting mount=false here. handleLeavingViewUnmount
1966
1973
  // sets it only after its container-to-container guard passes, avoiding zombie state.
@@ -1982,7 +1989,8 @@ class StackManager extends React.PureComponent {
1982
1989
  }
1983
1990
  this.handleLeavingViewUnmount(routeInfo, enteringViewItem, leavingViewItem);
1984
1991
  }
1985
- // Clean up orphaned sibling views after replace actions (redirects)
1992
+ this.cleanupPageBehindPagelessView(routeInfo, pageBehindPagelessView);
1993
+ // Clean up orphaned sibling views after replace actions or push-to-container navigations
1986
1994
  this.cleanupOrphanedSiblingViews(routeInfo, enteringViewItem, leavingViewItem);
1987
1995
  // On a fresh push, browser forward history is invalidated. Any views we
1988
1996
  // previously preserved on pop (to support forward navigation) are now
@@ -2012,17 +2020,8 @@ class StackManager extends React.PureComponent {
2012
2020
  this.preservedViewItems.delete(viewItem);
2013
2021
  continue;
2014
2022
  }
2015
- viewItem.mount = false;
2016
2023
  this.preservedViewItems.delete(viewItem);
2017
- const viewToUnmount = viewItem;
2018
- setTimeout(() => {
2019
- // Skip if a follow-up transition re-entered the view (mount flipped back to true).
2020
- if (viewToUnmount.mount) {
2021
- return;
2022
- }
2023
- this.context.unMountViewItem(viewToUnmount);
2024
- this.forceUpdate();
2025
- }, VIEW_UNMOUNT_DELAY_MS);
2024
+ this.scheduleViewUnmount(viewItem);
2026
2025
  }
2027
2026
  }
2028
2027
  /**
@@ -2034,16 +2033,7 @@ class StackManager extends React.PureComponent {
2034
2033
  return;
2035
2034
  }
2036
2035
  if (!leavingViewItem.ionPageElement) {
2037
- leavingViewItem.mount = false;
2038
- const viewToUnmount = leavingViewItem;
2039
- setTimeout(() => {
2040
- // Skip if a follow-up transition re-entered the view (mount flipped back to true).
2041
- if (viewToUnmount.mount) {
2042
- return;
2043
- }
2044
- this.context.unMountViewItem(viewToUnmount);
2045
- this.forceUpdate();
2046
- }, VIEW_UNMOUNT_DELAY_MS);
2036
+ this.scheduleViewUnmount(leavingViewItem);
2047
2037
  return;
2048
2038
  }
2049
2039
  const enteringRoutePath = enteringViewItem.reactElement?.props?.path;
@@ -2059,35 +2049,106 @@ class StackManager extends React.PureComponent {
2059
2049
  if (isEnteringContainerRoute && !isLeavingSpecificRoute) {
2060
2050
  return;
2061
2051
  }
2062
- leavingViewItem.mount = false;
2063
- const viewToUnmount = leavingViewItem;
2052
+ this.scheduleViewUnmount(leavingViewItem);
2053
+ }
2054
+ /**
2055
+ * Marks a view unmounted and removes it after VIEW_UNMOUNT_DELAY_MS, unless a
2056
+ * follow-up transition re-enters it first (mount flips back to true).
2057
+ */
2058
+ scheduleViewUnmount(viewItem) {
2059
+ viewItem.mount = false;
2064
2060
  setTimeout(() => {
2065
- // Skip if a follow-up transition re-entered the view (mount flipped back to true).
2066
- if (viewToUnmount.mount) {
2061
+ if (viewItem.mount) {
2067
2062
  return;
2068
2063
  }
2069
- this.context.unMountViewItem(viewToUnmount);
2064
+ this.context.unMountViewItem(viewItem);
2070
2065
  this.forceUpdate();
2071
2066
  }, VIEW_UNMOUNT_DELAY_MS);
2072
2067
  }
2073
2068
  /**
2074
- * Cleans up orphaned sibling views after replace actions or push-to-container navigations.
2069
+ * Returns the ids of this outlet's views that a location history entry still
2070
+ * resolves to. Those views are reachable with back.
2071
+ */
2072
+ getViewIdsInHistory() {
2073
+ const viewIds = new Set();
2074
+ for (const pathname of this.context.getLocationHistoryPathnames()) {
2075
+ const viewItem = this.context.findViewItemByPathname(pathname, this.id);
2076
+ if (viewItem) {
2077
+ viewIds.add(viewItem.id);
2078
+ }
2079
+ }
2080
+ return viewIds;
2081
+ }
2082
+ /**
2083
+ * When the leaving view renders no IonPage (a redirect, or a component that
2084
+ * navigates on mount), returns the page shown before it.
2085
+ */
2086
+ findPageBehindPagelessView(routeInfo, enteringViewItem, leavingViewItem) {
2087
+ if (!leavingViewItem ||
2088
+ leavingViewItem.ionPageElement ||
2089
+ !routeInfo.prevRouteLastPathname ||
2090
+ (routeInfo.routeAction !== 'push' && routeInfo.routeAction !== 'replace')) {
2091
+ return undefined;
2092
+ }
2093
+ const isCandidate = (viewItem) => !!viewItem &&
2094
+ viewItem !== enteringViewItem &&
2095
+ viewItem !== leavingViewItem &&
2096
+ viewItem.mount &&
2097
+ !!viewItem.ionPageElement;
2098
+ const pageBehind = this.context.findViewItemByPathname(routeInfo.prevRouteLastPathname, this.id);
2099
+ if (isCandidate(pageBehind)) {
2100
+ return pageBehind;
2101
+ }
2102
+ // In a chain of page-less redirects the previous pathname is another hop,
2103
+ // often already unmounted. The page the user was on is the one still
2104
+ // showing in this outlet.
2105
+ return this.context
2106
+ .getViewItemsForOutlet(this.id)
2107
+ .find((viewItem) => isCandidate(viewItem) &&
2108
+ isViewVisible(viewItem.ionPageElement) &&
2109
+ !viewItem.reactElement?.props?.path?.endsWith('/*'));
2110
+ }
2111
+ /**
2112
+ * Unmounts the page shown before a page-less view (a redirect, or a component
2113
+ * that navigates on mount) unless back can still reach it, since the replace
2114
+ * only unmounts the page-less view itself.
2115
+ */
2116
+ cleanupPageBehindPagelessView(routeInfo, pageBehindPagelessView) {
2117
+ if (routeInfo.routeAction !== 'replace') {
2118
+ return;
2119
+ }
2120
+ if (!pageBehindPagelessView || this.getViewIdsInHistory().has(pageBehindPagelessView.id)) {
2121
+ return;
2122
+ }
2123
+ // Container views (e.g. /tabs/*) host their own nested outlets; leave them alone.
2124
+ const pageBehindPagelessViewPath = pageBehindPagelessView.reactElement?.props?.path;
2125
+ if (pageBehindPagelessViewPath?.endsWith('/*')) {
2126
+ return;
2127
+ }
2128
+ // No explicit hide: the transition already animates this page out, and
2129
+ // hiding it now would cut that animation short.
2130
+ this.scheduleViewUnmount(pageBehindPagelessView);
2131
+ }
2132
+ /**
2133
+ * Cleans up orphaned sibling views after replace actions or push-to-container
2134
+ * navigations. A view that the location history still resolves to is
2135
+ * reachable with back, so it is kept.
2075
2136
  */
2076
2137
  cleanupOrphanedSiblingViews(routeInfo, enteringViewItem, leavingViewItem) {
2077
2138
  const enteringRoutePath = enteringViewItem.reactElement?.props?.path;
2078
2139
  if (!enteringRoutePath) {
2079
2140
  return;
2080
2141
  }
2081
- const leavingRoutePath = leavingViewItem?.reactElement?.props?.path;
2082
- const isContainerRoute = (path) => path?.endsWith('/*');
2083
- const isReplaceAction = routeInfo.routeAction === 'replace';
2084
- const isPushToContainer = routeInfo.routeAction === 'push' && routeInfo.routeDirection === 'none' && isContainerRoute(enteringRoutePath);
2085
- if (!isReplaceAction && !isPushToContainer) {
2142
+ // A push into a container (e.g. a menu link to /tabs/*) can leave behind
2143
+ // siblings that an earlier pop already took out of history
2144
+ const isPushToContainer = routeInfo.routeAction === 'push' && routeInfo.routeDirection === 'none' && enteringRoutePath.endsWith('/*');
2145
+ if (routeInfo.routeAction !== 'replace' && !isPushToContainer) {
2086
2146
  return;
2087
2147
  }
2148
+ const leavingRoutePath = leavingViewItem?.reactElement?.props?.path;
2088
2149
  // Skip cleanup for tab switches
2089
2150
  const isSameView = enteringViewItem === leavingViewItem;
2090
- const isSameContainerRoute = isContainerRoute(enteringRoutePath) && leavingRoutePath === enteringRoutePath;
2151
+ const isSameContainerRoute = enteringRoutePath.endsWith('/*') && leavingRoutePath === enteringRoutePath;
2091
2152
  const isNavigatingWithinContainer = isPushToContainer &&
2092
2153
  !leavingViewItem &&
2093
2154
  routeInfo.prevRouteLastPathname?.startsWith(enteringRoutePath.replace(/\/\*$/, ''));
@@ -2095,6 +2156,9 @@ class StackManager extends React.PureComponent {
2095
2156
  return;
2096
2157
  }
2097
2158
  const allViewsInOutlet = this.context.getViewItemsForOutlet(this.id);
2159
+ // Views still in history are reachable with back, so they are not orphaned
2160
+ // even when they are siblings of the entering route.
2161
+ const viewIdsInHistory = this.getViewIdsInHistory();
2098
2162
  const areSiblingRoutes = (path1, path2) => {
2099
2163
  const path1IsRelative = !path1.startsWith('/');
2100
2164
  const path2IsRelative = !path2.startsWith('/');
@@ -2130,30 +2194,18 @@ class StackManager extends React.PureComponent {
2130
2194
  (leavingViewItem && viewItem.id === leavingViewItem.id) ||
2131
2195
  !viewItem.mount ||
2132
2196
  !viewRoutePath ||
2197
+ viewIdsInHistory.has(viewItem.id) ||
2133
2198
  // Don't clean up container routes when entering a container route
2134
2199
  // (e.g., /tabs/* and /settings/* coexist for tab switching)
2135
2200
  (viewRoutePath.endsWith('/*') && enteringRoutePath.endsWith('/*'));
2136
2201
  if (shouldSkip) {
2137
2202
  continue;
2138
2203
  }
2139
- const isOrphanedSpecificRoute = !viewRoutePath.endsWith('/*');
2140
2204
  // Clean up sibling non-container routes that are no longer reachable.
2141
- let shouldCleanup = false;
2142
- if ((isReplaceAction || isPushToContainer) && isOrphanedSpecificRoute) {
2143
- shouldCleanup = areSiblingRoutes(enteringRoutePath, viewRoutePath);
2144
- }
2145
- if (shouldCleanup) {
2205
+ const isSpecificRoute = !viewRoutePath.endsWith('/*');
2206
+ if (isSpecificRoute && areSiblingRoutes(enteringRoutePath, viewRoutePath)) {
2146
2207
  hideIonPageElement(viewItem.ionPageElement);
2147
- viewItem.mount = false;
2148
- const viewToRemove = viewItem;
2149
- setTimeout(() => {
2150
- // Skip if a follow-up transition re-entered the view (mount flipped back to true).
2151
- if (viewToRemove.mount) {
2152
- return;
2153
- }
2154
- this.context.unMountViewItem(viewToRemove);
2155
- this.forceUpdate();
2156
- }, VIEW_UNMOUNT_DELAY_MS);
2208
+ this.scheduleViewUnmount(viewItem);
2157
2209
  }
2158
2210
  }
2159
2211
  }
@@ -3762,6 +3814,7 @@ const IonRouter = ({ children, registerHistoryListener }) => {
3762
3814
  findViewItemByPathname: viewStack.current.findViewItemByPathname,
3763
3815
  getChildrenToRender: viewStack.current.getChildrenToRender,
3764
3816
  getViewItemsForOutlet: viewStack.current.getViewItemsForOutlet.bind(viewStack.current),
3817
+ getLocationHistoryPathnames: () => locationHistory.current.getPathnames(),
3765
3818
  goBack: () => handleNavigateBack(),
3766
3819
  createViewItem: viewStack.current.createViewItem,
3767
3820
  findViewItemByRouteInfo: viewStack.current.findViewItemByRouteInfo,