Skip to content

Commit aa64e2d

Browse files
committed
refactor: add a helper fn
1 parent b5e7c6c commit aa64e2d

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

packages/nextjs/src/client/routing/isrRoutingTracing.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,23 @@ export function removeIsrSsgTraceMetaTags(): void {
4545
return;
4646
}
4747

48+
// Helper function to remove a meta tag
49+
const removeMetaTag = (metaName: string) => {
50+
try {
51+
const meta = document.querySelector(`meta[name="${metaName}"]`);
52+
if (meta) {
53+
meta.remove();
54+
}
55+
} catch {
56+
// ignore errors when removing the meta tag
57+
}
58+
};
59+
4860
if (!isIsrSsgRoute(window.location.pathname)) {
4961
return;
5062
}
5163

5264
// Remove the meta tags so browserTracingIntegration won't pick them up
53-
const sentryTraceMeta = document.querySelector('meta[name="sentry-trace"]');
54-
if (sentryTraceMeta) {
55-
sentryTraceMeta.remove();
56-
}
57-
58-
const baggageMeta = document.querySelector('meta[name="baggage"]');
59-
if (baggageMeta) {
60-
baggageMeta.remove();
61-
}
65+
removeMetaTag('sentry-trace');
66+
removeMetaTag('baggage');
6267
}

0 commit comments

Comments
 (0)