Skip to content

ref(react): Use WeakSet to keep track of navigation instrumented clients #12273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/react/src/reactrouterv6.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ let _createRoutesFromChildren: CreateRoutesFromChildren;
let _matchRoutes: MatchRoutes;
let _stripBasename: boolean = false;

const CLIENTS_WITH_INSTRUMENT_NAVIGATION: Client[] = [];
const CLIENTS_WITH_INSTRUMENT_NAVIGATION = new WeakSet<Client>();

interface ReactRouterOptions {
useEffect: UseEffect;
Expand Down Expand Up @@ -108,7 +108,7 @@ export function reactRouterV6BrowserTracingIntegration(
}

if (instrumentNavigation) {
CLIENTS_WITH_INSTRUMENT_NAVIGATION.push(client);
CLIENTS_WITH_INSTRUMENT_NAVIGATION.add(client);
}
},
};
Expand Down Expand Up @@ -222,7 +222,7 @@ function handleNavigation(
const branches = Array.isArray(matches) ? matches : _matchRoutes(routes, location, basename);

const client = getClient();
if (!client || !CLIENTS_WITH_INSTRUMENT_NAVIGATION.includes(client)) {
if (!client || !CLIENTS_WITH_INSTRUMENT_NAVIGATION.has(client)) {
return;
}

Expand Down
Loading