From 6a42e6959d99e10e0cc13b08406b127abe623134 Mon Sep 17 00:00:00 2001 From: Maria Hutt Date: Mon, 19 May 2025 13:08:31 -0700 Subject: [PATCH] chore(rr6): run lint --- .../src/ReactRouter/ReactRouterViewStack.tsx | 74 ++++--------------- .../src/ReactRouter/utils/matchPath.ts | 8 +- 2 files changed, 17 insertions(+), 65 deletions(-) diff --git a/packages/react-router/src/ReactRouter/ReactRouterViewStack.tsx b/packages/react-router/src/ReactRouter/ReactRouterViewStack.tsx index be25c2b5c8..9886c81a76 100644 --- a/packages/react-router/src/ReactRouter/ReactRouterViewStack.tsx +++ b/packages/react-router/src/ReactRouter/ReactRouterViewStack.tsx @@ -12,12 +12,7 @@ */ import type { RouteInfo, ViewItem } from '@ionic/react'; -import { - IonRoute, - ViewLifeCycleManager, - ViewStacks, - generateId, -} from '@ionic/react'; +import { IonRoute, ViewLifeCycleManager, ViewStacks, generateId } from '@ionic/react'; import React from 'react'; import type { PathMatch } from 'react-router'; import { Routes } from 'react-router'; @@ -33,12 +28,7 @@ export class ReactRouterViewStack extends ViewStacks { * Creates a new view item for the given outlet and react route element. * Associates route props with the matched route path for further lookups. */ - createViewItem = ( - outletId: string, - reactElement: React.ReactElement, - routeInfo: RouteInfo, - page?: HTMLElement - ) => { + createViewItem = (outletId: string, reactElement: React.ReactElement, routeInfo: RouteInfo, page?: HTMLElement) => { const viewItem: ViewItem = { id: generateId('viewItem'), outletId, @@ -80,18 +70,12 @@ export class ReactRouterViewStack extends ViewStacks { } return ( - this.remove(viewItem)} - > + this.remove(viewItem)}> {/** * Wrapped in to ensure React Router v6 correctly processes nested route elements * `key` is provided to enforce remounting of Routes when switching between view items. */} - - {React.cloneElement(viewItem.reactElement)} - + {React.cloneElement(viewItem.reactElement)} ); }; @@ -106,25 +90,16 @@ export class ReactRouterViewStack extends ViewStacks { * 3. Returns a list of React components that will be rendered inside the outlet * Each view is wrapped in to manage lifecycle and rendering */ - getChildrenToRender = ( - outletId: string, - ionRouterOutlet: React.ReactElement, - routeInfo: RouteInfo - ) => { + getChildrenToRender = (outletId: string, ionRouterOutlet: React.ReactElement, routeInfo: RouteInfo) => { const viewItems = this.getViewItemsForOutlet(outletId); // Sync child elements with stored viewItems (e.g. to reflect new props) - React.Children.forEach( - ionRouterOutlet.props.children, - (child: React.ReactElement) => { - const viewItem = viewItems.find((v) => - matchComponent(child, v.routeData.childProps.path) - ); - if (viewItem) { - viewItem.reactElement = child; - } + React.Children.forEach(ionRouterOutlet.props.children, (child: React.ReactElement) => { + const viewItem = viewItems.find((v) => matchComponent(child, v.routeData.childProps.path)); + if (viewItem) { + viewItem.reactElement = child; } - ); + }); // Render all view items using renderViewItem return viewItems.map((viewItem) => this.renderViewItem(viewItem, routeInfo)); @@ -133,15 +108,8 @@ export class ReactRouterViewStack extends ViewStacks { /** * Finds a view item matching the current route, optionally updating its match state. */ - findViewItemByRouteInfo = ( - routeInfo: RouteInfo, - outletId?: string, - updateMatch?: boolean - ) => { - const { viewItem, match } = this.findViewItemByPath( - routeInfo.pathname, - outletId - ); + findViewItemByRouteInfo = (routeInfo: RouteInfo, outletId?: string, updateMatch?: boolean) => { + const { viewItem, match } = this.findViewItemByPath(routeInfo.pathname, outletId); const shouldUpdateMatch = updateMatch === undefined || updateMatch === true; if (shouldUpdateMatch && viewItem && match) { viewItem.routeData.match = match; @@ -152,16 +120,8 @@ export class ReactRouterViewStack extends ViewStacks { /** * Finds the view item that was previously active before a route change. */ - findLeavingViewItemByRouteInfo = ( - routeInfo: RouteInfo, - outletId?: string, - mustBeIonRoute = true - ) => { - const { viewItem } = this.findViewItemByPath( - routeInfo.lastPathname!, - outletId, - mustBeIonRoute - ); + findLeavingViewItemByRouteInfo = (routeInfo: RouteInfo, outletId?: string, mustBeIonRoute = true) => { + const { viewItem } = this.findViewItemByPath(routeInfo.lastPathname!, outletId, mustBeIonRoute); return viewItem; }; @@ -177,11 +137,7 @@ export class ReactRouterViewStack extends ViewStacks { * Core function that matches a given pathname against all view items. * Returns both the matched view item and match metadata. */ - private findViewItemByPath( - pathname: string, - outletId?: string, - mustBeIonRoute?: boolean - ) { + private findViewItemByPath(pathname: string, outletId?: string, mustBeIonRoute?: boolean) { let viewItem: ViewItem | undefined; let match: PathMatch | null = null; let viewStack: ViewItem[]; diff --git a/packages/react-router/src/ReactRouter/utils/matchPath.ts b/packages/react-router/src/ReactRouter/utils/matchPath.ts index cb1d0e01d7..3623e0c992 100644 --- a/packages/react-router/src/ReactRouter/utils/matchPath.ts +++ b/packages/react-router/src/ReactRouter/utils/matchPath.ts @@ -23,15 +23,11 @@ interface MatchPathOptions { * The matchPath function is used only for matching paths, not rendering components or elements. * @see https://reactrouter.com/v6/utils/match-path */ -export const matchPath = ({ - pathname, - componentProps, -}: MatchPathOptions): PathMatch | null => { +export const matchPath = ({ pathname, componentProps }: MatchPathOptions): PathMatch | null => { const { path, ...restProps } = componentProps; if (!path) { - console.warn( - '[Ionic] matchPath: No path prop provided. This will always return null.', { + console.warn('[Ionic] matchPath: No path prop provided. This will always return null.', { componentProps, }); return null;