Skip to content

Commit b9417bc

Browse files
committed
add parse and checks
1 parent b80c7e6 commit b9417bc

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,26 @@ const globalWithInjectedManifest = GLOBAL_OBJ as typeof GLOBAL_OBJ & {
66
};
77

88
export const maybeParameterizeRoute = (route: string): string | undefined => {
9-
const manifest = globalWithInjectedManifest._sentryRouteManifest;
9+
if (
10+
!globalWithInjectedManifest._sentryRouteManifest ||
11+
typeof globalWithInjectedManifest._sentryRouteManifest !== 'string'
12+
) {
13+
return undefined;
14+
}
1015

11-
if (!manifest) {
16+
let manifest: RouteManifest = {
17+
staticRoutes: [],
18+
dynamicRoutes: [],
19+
};
20+
21+
// Shallow check if the manifest is actually what we expect it to be
22+
try {
23+
manifest = JSON.parse(globalWithInjectedManifest._sentryRouteManifest);
24+
if (!Array.isArray(manifest.staticRoutes) || !Array.isArray(manifest.dynamicRoutes)) {
25+
return undefined;
26+
}
27+
} catch (error) {
28+
// Something went wrong while parsing the manifest, so we'll fallback to no parameterization
1229
return undefined;
1330
}
1431

0 commit comments

Comments
 (0)