Skip to content

Commit fc6e482

Browse files
committed
chore(react-router): cleaning up console logs
1 parent 7fd0659 commit fc6e482

File tree

7 files changed

+1
-133
lines changed

7 files changed

+1
-133
lines changed

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

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ export class ReactRouterViewStack extends ViewStacks {
187187
// Add infinite loop detection with a more reasonable limit
188188
// In complex navigation flows, we may have many view items across different outlets
189189
if (this.viewItemCounter > 100) {
190-
console.warn(`[ReactRouterViewStack] Many view items created (${this.viewItemCounter}). Performing cleanup.`);
191190
// Clean up all outlets to prevent memory leaks
192191
this.getStackIds().forEach((stackId) => this.cleanupStaleViewItems(stackId));
193192
// Reset counter to a lower value after cleanup
@@ -477,10 +476,6 @@ export class ReactRouterViewStack extends ViewStacks {
477476
if (hasRelativeRoutes || hasIndexRoute) {
478477
const segments = routeInfo.pathname.split('/').filter(Boolean);
479478

480-
if (process.env.NODE_ENV !== 'production') {
481-
console.log(`[ReactRouterViewStack] getChildrenToRender outlet=${outletId}: computing parentPath for ${routeInfo.pathname}`);
482-
}
483-
484479
// Two-pass algorithm:
485480
// Pass 1: Look for specific route matches OR index routes (prefer real routes)
486481
// Pass 2: If no match found, use wildcard fallback
@@ -511,9 +506,6 @@ export class ReactRouterViewStack extends ViewStacks {
511506
});
512507

513508
if (hasSpecificMatch) {
514-
if (process.env.NODE_ENV !== 'production') {
515-
console.log(`[ReactRouterViewStack] Found specific match at parentPath=${testParentPath}, remaining=${testRemainingPath}`);
516-
}
517509
parentPath = testParentPath;
518510
break;
519511
}
@@ -525,9 +517,6 @@ export class ReactRouterViewStack extends ViewStacks {
525517
if (!wildcardFallbackPath && (testRemainingPath === '' || testRemainingPath === '/')) {
526518
const hasIndexMatch = routeChildren.some((route) => !!(route.props as any).index);
527519
if (hasIndexMatch) {
528-
if (process.env.NODE_ENV !== 'production') {
529-
console.log(`[ReactRouterViewStack] Found index match at parentPath=${testParentPath}`);
530-
}
531520
parentPath = testParentPath;
532521
break;
533522
}
@@ -570,9 +559,6 @@ export class ReactRouterViewStack extends ViewStacks {
570559

571560
// Pass 2: If no specific/index match found, use wildcard fallback
572561
if (!parentPath && wildcardFallbackPath) {
573-
if (process.env.NODE_ENV !== 'production') {
574-
console.log(`[ReactRouterViewStack] Using wildcard fallback at parentPath=${wildcardFallbackPath}`);
575-
}
576562
parentPath = wildcardFallbackPath;
577563
}
578564
}
@@ -646,9 +632,6 @@ export class ReactRouterViewStack extends ViewStacks {
646632
findLeavingViewItemByRouteInfo = (routeInfo: RouteInfo, outletId?: string, mustBeIonRoute = true) => {
647633
// If the lastPathname is not set, we cannot find a leaving view item
648634
if (!routeInfo.lastPathname) {
649-
if (process.env.NODE_ENV !== 'production') {
650-
console.warn(`[ReactRouterViewStack] No matching leaving view item found for: ${routeInfo.pathname}`);
651-
}
652635
return undefined;
653636
}
654637

@@ -732,16 +715,6 @@ export class ReactRouterViewStack extends ViewStacks {
732715
// Do not adopt across outlets; if we didn't find a view for this outlet,
733716
// defer to route matching to create a new one.
734717

735-
if (!viewItem && process.env.NODE_ENV !== 'production') {
736-
const allViewItems = this.getAllViewItems();
737-
console.warn(
738-
`[ReactRouterViewStack] No matching view item found for: ${pathname}. Available views:`,
739-
allViewItems
740-
.map((v) => `${v.id}(outlet:${v.outletId}, path:${v.routeData?.childProps?.path || 'undefined'})`)
741-
.join(', ')
742-
);
743-
}
744-
745718
return { viewItem, match };
746719

747720
/**

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

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,6 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
239239
bestPath = indexMatchAtMount;
240240
}
241241

242-
if (process.env.NODE_ENV !== 'production') {
243-
console.log(
244-
`[getParentPath] outlet=${this.id}, pathname=${currentPathname}: ` +
245-
`specific=${firstSpecificMatch}, wildcard=${firstWildcardMatch}, index=${indexMatchAtMount}, best=${bestPath}`
246-
);
247-
}
248-
249242
// Store the mount path when we first successfully match a route
250243
if (!this.outletMountPath && bestPath) {
251244
this.outletMountPath = bestPath;
@@ -331,18 +324,11 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
331324
* Set a flag to indicate that we should transition the page after
332325
* the component has updated (i.e., in `componentDidUpdate`).
333326
*/
334-
if (process.env.NODE_ENV !== 'production') {
335-
console.log(`[StackManager] Outlet ${this.id} not ready yet, setting pendingPageTransition=true for ${routeInfo.pathname}`);
336-
}
337327
this.pendingPageTransition = true;
338328
} else {
339329
let enteringViewItem = this.context.findViewItemByRouteInfo(routeInfo, this.id);
340330
let leavingViewItem = this.context.findLeavingViewItemByRouteInfo(routeInfo, this.id);
341331

342-
if (process.env.NODE_ENV !== 'production') {
343-
console.log(`[StackManager:handlePageTransition] outlet=${this.id}, pathname=${routeInfo.pathname}, entering=${enteringViewItem?.id}, leaving=${leavingViewItem?.id}, enteringIsNav=${isNavigateViewItem(enteringViewItem)}, leavingIsNav=${isNavigateViewItem(leavingViewItem)}`);
344-
}
345-
346332
/**
347333
* If we don't have a leaving view item, but the route info indicates
348334
* that the user has routed from a previous path, then the leaving view
@@ -443,13 +429,7 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
443429
: [];
444430

445431
// Unmount and remove all views in this outlet immediately to avoid leftover content
446-
if (process.env.NODE_ENV !== 'production') {
447-
console.log(`[StackManager:outOfScope] outlet=${this.id} is out of scope, removing ${allViewsInOutlet.length} views`);
448-
}
449432
allViewsInOutlet.forEach((viewItem) => {
450-
if (process.env.NODE_ENV !== 'production') {
451-
console.log(`[StackManager:outOfScope] Removing view ${viewItem.id} from outlet ${this.id}, isNavigate=${isNavigateViewItem(viewItem)}`);
452-
}
453433
if (viewItem.ionPageElement) {
454434
viewItem.ionPageElement.classList.add('ion-page-hidden');
455435
viewItem.ionPageElement.setAttribute('aria-hidden', 'true');
@@ -490,9 +470,6 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
490470
leavingViewItem.ionPageElement.setAttribute('aria-hidden', 'true');
491471
}
492472
if (leavingViewItem) {
493-
if (isNavigateViewItem(leavingViewItem) && process.env.NODE_ENV !== 'production') {
494-
console.log(`[StackManager:hasRelativeRoutes] Setting mount=false on Navigate ${leavingViewItem.id}, outlet=${this.id}, pathname=${routeInfo.pathname}`);
495-
}
496473
leavingViewItem.mount = false;
497474
}
498475
this.forceUpdate();
@@ -506,32 +483,16 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
506483
parentPath
507484
) as React.ReactElement;
508485

509-
if (enteringRoute && process.env.NODE_ENV !== 'production') {
510-
const routeElement = enteringRoute.props?.element;
511-
const isNavigate = React.isValidElement(routeElement) && routeElement.type === Navigate;
512-
console.log(
513-
`[StackManager] Found entering route for ${routeInfo.pathname} in outlet ${this.id}: path="${
514-
enteringRoute.props?.path ?? '(index)'
515-
}", isNavigate=${isNavigate}`
516-
);
517-
}
518-
519486
// If this is a nested outlet (has an explicit ID) and no route matches,
520487
// it means this outlet shouldn't handle this route
521488
if (this.id !== 'routerOutlet' && !enteringRoute && !enteringViewItem) {
522-
if (process.env.NODE_ENV !== 'production') {
523-
console.log(`[StackManager:noMatchingRoute] outlet=${this.id} has no matching route for ${routeInfo.pathname}, leavingViewItem=${leavingViewItem?.id}`);
524-
}
525489
// Hide any visible views in this outlet since it has no matching route
526490
if (leavingViewItem && leavingViewItem.ionPageElement) {
527491
leavingViewItem.ionPageElement.classList.add('ion-page-hidden');
528492
leavingViewItem.ionPageElement.setAttribute('aria-hidden', 'true');
529493
}
530494
// Unmount the leaving view to prevent components from staying active
531495
if (leavingViewItem) {
532-
if (isNavigateViewItem(leavingViewItem) && process.env.NODE_ENV !== 'production') {
533-
console.log(`[StackManager:noMatchingRoute] Setting mount=false on Navigate ${leavingViewItem.id}, outlet=${this.id}, pathname=${routeInfo.pathname}`);
534-
}
535496
leavingViewItem.mount = false;
536497
}
537498
this.forceUpdate();
@@ -545,18 +506,9 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
545506
if (enteringViewItem && enteringRoute) {
546507
// Update existing view item
547508
enteringViewItem.reactElement = enteringRoute;
548-
if (process.env.NODE_ENV !== 'production') {
549-
console.log(`[StackManager] Updated existing view item ${enteringViewItem.id} for outlet ${this.id}`);
550-
}
551509
} else if (enteringRoute) {
552-
if (process.env.NODE_ENV !== 'production') {
553-
console.log(`[StackManager] Creating new view item for outlet ${this.id}, route path="${enteringRoute.props?.path ?? '(index)'}"`);
554-
}
555510
enteringViewItem = this.context.createViewItem(this.id, enteringRoute, routeInfo);
556511
this.context.addViewItem(enteringViewItem);
557-
if (process.env.NODE_ENV !== 'production') {
558-
console.log(`[StackManager] Added view item ${enteringViewItem.id} to outlet ${this.id}`);
559-
}
560512
}
561513

562514
/**
@@ -716,9 +668,6 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
716668
* and repeatedly hide the leaving view. Treat this as a no-op transition and allow
717669
* the follow-up navigation to proceed.
718670
*/
719-
if (process.env.NODE_ENV !== 'production') {
720-
console.log(`[StackManager:Navigate] outlet=${this.id}, entering=${enteringViewItem?.id}, leaving=${leavingViewItem?.id}, shouldUnmount=${shouldUnmountLeavingViewItem}, pathname=${routeInfo.pathname}`);
721-
}
722671
this.waitingForIonPage = false;
723672
if (this.ionPageWaitTimeout) {
724673
clearTimeout(this.ionPageWaitTimeout);
@@ -735,9 +684,6 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
735684
// This happens during chained Navigate redirects where the same Navigate view item
736685
// is being processed multiple times before it can render and trigger the redirect
737686
if (shouldUnmountLeavingViewItem && leavingViewItem && enteringViewItem !== leavingViewItem) {
738-
if (isNavigateViewItem(leavingViewItem) && process.env.NODE_ENV !== 'production') {
739-
console.log(`[StackManager:Navigate:unmountLeaving] Setting mount=false on Navigate ${leavingViewItem.id}, outlet=${this.id}`);
740-
}
741687
leavingViewItem.mount = false;
742688
}
743689

@@ -754,18 +700,9 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
754700
* while we wait for the entering view's IonPage to mount, then retry the
755701
* transition once the page is ready.
756702
*/
757-
if (process.env.NODE_ENV !== 'production') {
758-
console.log(
759-
`[StackManager] Entering view ${enteringViewItem.id} has no ionPageElement yet, will hide leaving view and retry`
760-
);
761-
}
762-
763703
if (leavingViewItem?.ionPageElement) {
764704
leavingViewItem.ionPageElement.classList.add('ion-page-hidden');
765705
leavingViewItem.ionPageElement.setAttribute('aria-hidden', 'true');
766-
if (process.env.NODE_ENV !== 'production') {
767-
console.log(`[StackManager] HIDING leaving view ${leavingViewItem.id} (no entering ionPage yet)`);
768-
}
769706
}
770707

771708
this.waitingForIonPage = true;
@@ -787,21 +724,13 @@ export class StackManager extends React.PureComponent<StackManagerProps, StackMa
787724
this.context.findLeavingViewItemByRouteInfo(routeInfo, this.id) ?? leavingViewItem;
788725

789726
if (latestEnteringView?.ionPageElement) {
790-
if (process.env.NODE_ENV !== 'production') {
791-
console.log(`[StackManager] Retrying transition for ${latestEnteringView.id}`);
792-
}
793-
794727
this.transitionPage(routeInfo, latestEnteringView, latestLeavingView ?? undefined);
795728

796729
if (shouldUnmountLeavingViewItem && latestLeavingView && latestEnteringView !== latestLeavingView) {
797730
latestLeavingView.mount = false;
798731
}
799732

800733
this.forceUpdate();
801-
} else if (process.env.NODE_ENV !== 'production') {
802-
console.log(
803-
`[StackManager] Still no ionPageElement for ${latestEnteringView?.id ?? enteringViewItem?.id ?? 'unknown'}, skipping transition`
804-
);
805734
}
806735
}, 50);
807736

@@ -1205,12 +1134,6 @@ function findRouteByRouteInfo(node: React.ReactNode, routeInfo: RouteInfo, paren
12051134
const parentSegments = normalizedParent.split('/').filter(Boolean);
12061135
const relativeSegments = pathSegments.slice(parentSegments.length);
12071136
pathnameToMatch = relativeSegments.join('/'); // Empty string is valid for index routes
1208-
1209-
if (process.env.NODE_ENV !== 'production') {
1210-
console.log(
1211-
`[findRouteByRouteInfo] Computed relative path: "${pathnameToMatch}" from pathname="${routeInfo.pathname}" parentPath="${parentPath}"`
1212-
);
1213-
}
12141137
}
12151138
}
12161139

@@ -1222,13 +1145,6 @@ function findRouteByRouteInfo(node: React.ReactNode, routeInfo: RouteInfo, paren
12221145
});
12231146

12241147
if (match) {
1225-
if (process.env.NODE_ENV !== 'production') {
1226-
console.log(
1227-
`[findRouteByRouteInfo] Matched route for ${routeInfo.pathname} in outlet ${parentPath ?? 'root'} with path="${
1228-
child.props.path ?? '(index)'
1229-
}"`
1230-
);
1231-
}
12321148
matchedNode = child;
12331149
break;
12341150
}

packages/react-router/src/ReactRouter/utils/matchRoutesFromChildren.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,6 @@ export function computeParentPathFromRoutes(
142142
continue;
143143
}
144144

145-
if (process.env.NODE_ENV !== 'production') {
146-
console.log(
147-
`[matchRoutesFromChildren] Found match for ${pathname}: parentPath=${testParentPath}, matchedRoute.path=${matchedRoute.path ?? '(index)'}, pathnameBase=${lastMatch.pathnameBase}`
148-
);
149-
}
150-
151145
return {
152146
parentPath: testParentPath,
153147
matchedRoute,
@@ -164,11 +158,6 @@ export function computeParentPathFromRoutes(
164158
// Only consider this if it's an index route (we're exactly at the parent)
165159
if (lastMatch.route.index) {
166160
const parentPath = '/' + segments.join('/');
167-
if (process.env.NODE_ENV !== 'production') {
168-
console.log(
169-
`[matchRoutesFromChildren] Index route match for ${pathname}: parentPath=${parentPath}`
170-
);
171-
}
172161
return {
173162
parentPath,
174163
matchedRoute: lastMatch.route,

packages/react-router/test/base/src/pages/routing/Tabs.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect } from 'react';
1+
import React from 'react';
22
import { IonTabs, IonRouterOutlet, IonTabBar, IonTabButton, IonIcon, IonLabel, IonPage, IonContent } from '@ionic/react';
33
import { Route, Navigate } from 'react-router';
44
import Tab1 from './Tab1';
@@ -11,9 +11,6 @@ import SettingsDetails from './SettingsDetails';
1111
interface TabsProps {}
1212

1313
const Tabs: React.FC = () => {
14-
useEffect(() => {
15-
console.log('[Tabs] Mounted');
16-
}, []);
1714
return (
1815
<IonTabs>
1916
<IonRouterOutlet id="tabs">

packages/react/src/components/IonRouterOutlet.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ class IonRouterOutletContainer extends React.Component<InternalProps, InternalSt
3737
const { children, forwardedRef, ...props } = this.props;
3838
const outletId = props.id ?? this.outletId;
3939

40-
console.log(`[IonRouterOutlet] Rendering with id: "${outletId}", all props:`, Object.keys(props));
41-
4240
return this.context.hasIonicRouter() ? (
4341
props.ionPage ? (
4442
<OutletPageManager StackManager={StackManager} routeInfo={this.context.routeInfo} {...props}>

packages/react/src/routing/LocationHistory.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,9 @@ export class LocationHistory {
9696
// Get the current route that's being replaced
9797
const currentRoute = this.locationHistory[this.locationHistory.length - 1];
9898

99-
console.log('[LocationHistory._replace] currentRoute:', currentRoute?.pathname, 'tab:', currentRoute?.tab);
100-
console.log('[LocationHistory._replace] newRoute:', routeInfo.pathname, 'tab:', routeInfo.tab);
101-
10299
// Only pop from global history if we're replacing in the same outlet context.
103100
// Don't pop if we're entering a nested outlet (current route has no tab, new route has a tab)
104101
const isEnteringNestedOutlet = currentRoute && !currentRoute.tab && !!routeInfo.tab;
105-
console.log('[LocationHistory._replace] isEnteringNestedOutlet:', isEnteringNestedOutlet);
106102

107103
if (!isEnteringNestedOutlet) {
108104
this.locationHistory.pop();

packages/react/src/routing/PageManager.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export class PageManager extends React.PureComponent<PageManagerProps> {
4141
if (this.context.isInOutlet()) {
4242
this.ionPageElementRef.current.classList.add('ion-page-invisible');
4343
}
44-
console.log('[PageManager] componentDidMount for', this.props.routeInfo?.pathname);
4544
this.context.registerIonPage(this.ionPageElementRef.current, this.props.routeInfo!);
4645
this.ionPageElementRef.current.addEventListener('ionViewWillEnter', this.ionViewWillEnterHandler);
4746
this.ionPageElementRef.current.addEventListener('ionViewDidEnter', this.ionViewDidEnterHandler);

0 commit comments

Comments
 (0)