Skip to content

Commit 46bae24

Browse files
committed
fix(react): Add transaction name guards for rapid lazy-route navigations.
1 parent a3875c5 commit 46bae24

File tree

8 files changed

+496
-33
lines changed

8 files changed

+496
-33
lines changed

dev-packages/e2e-tests/test-applications/react-router-7-lazy-routes/src/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ const router = sentryCreateBrowserRouter(
126126
lazyChildren: () => import('./pages/deep/Level1Routes').then(module => module.level2Routes),
127127
},
128128
},
129+
{
130+
path: '/slow-fetch',
131+
handle: {
132+
// This lazy handler takes 500ms due to the top-level await in SlowFetchLazyRoutes.tsx
133+
// It also makes a fetch request during loading which creates a span
134+
lazyChildren: () => import('./pages/SlowFetchLazyRoutes').then(module => module.slowFetchRoutes),
135+
},
136+
},
129137
],
130138
{
131139
async patchRoutesOnNavigation({ matches, patch }: Parameters<PatchRoutesOnNavigationFunction>[0]) {

dev-packages/e2e-tests/test-applications/react-router-7-lazy-routes/src/pages/DelayedLazyRoute.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ const DelayedLazyRoute = () => {
2323
Back Home
2424
</Link>
2525
<br />
26+
<Link to="/slow-fetch/222" id="delayed-lazy-to-slow-fetch">
27+
Go to Slow Fetch Route (500ms)
28+
</Link>
29+
<br />
30+
<Link to="/another-lazy/sub" id="delayed-lazy-to-another-lazy">
31+
Go to Another Lazy Route
32+
</Link>
33+
<br />
2634
<Link to={`/delayed-lazy/${id}?view=detailed`} id="link-to-query-view-detailed">
2735
View: Detailed (query param)
2836
</Link>

dev-packages/e2e-tests/test-applications/react-router-7-lazy-routes/src/pages/Index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ const Index = () => {
3131
<Link to="/deep/level2/level3/123" id="navigation-to-deep">
3232
Navigate to Deep Nested Route (3 levels, 900ms total)
3333
</Link>
34+
<br />
35+
<Link to="/slow-fetch/123" id="navigation-to-slow-fetch">
36+
Navigate to Slow Fetch Route (500ms delay with fetch)
37+
</Link>
3438
</>
3539
);
3640
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from 'react';
2+
import { Link, useParams } from 'react-router-dom';
3+
4+
// Simulate a slow async fetch during lazy route loading
5+
// This delay happens before the module exports, simulating network latency
6+
const fetchPromise = fetch('/api/slow-data')
7+
.then(res => res.json())
8+
.catch(() => ({ message: 'fallback data' }));
9+
10+
// Add a 500ms delay to simulate slow lazy loading
11+
await new Promise(resolve => setTimeout(resolve, 500));
12+
13+
// Component that displays the lazy-loaded data
14+
const SlowFetchComponent = () => {
15+
const { id } = useParams<{ id: string }>();
16+
const [data, setData] = React.useState<{ message: string } | null>(null);
17+
18+
React.useEffect(() => {
19+
fetchPromise.then(setData);
20+
}, []);
21+
22+
return (
23+
<div id="slow-fetch-content">
24+
<h1>Slow Fetch Route</h1>
25+
<p id="slow-fetch-id">ID: {id}</p>
26+
<p id="slow-fetch-data">Data: {data?.message || 'loading...'}</p>
27+
<Link to="/" id="slow-fetch-home-link">
28+
Go Home
29+
</Link>
30+
<Link to="/another-lazy/sub/999/888" id="slow-fetch-to-another">
31+
Go to Another Lazy Route
32+
</Link>
33+
</div>
34+
);
35+
};
36+
37+
export const slowFetchRoutes = [
38+
{
39+
path: ':id',
40+
element: <SlowFetchComponent />,
41+
},
42+
];

0 commit comments

Comments
 (0)