Skip to content

Commit 6742d0a

Browse files
authored
fix(404): Fix queue link (#15445)
Adds a fallback prop to platformLink
1 parent feb7a91 commit 6742d0a

File tree

2 files changed

+86
-8
lines changed

2 files changed

+86
-8
lines changed

docs/platforms/javascript/common/tracing/span-metrics/examples.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ Where to put this in your app:
247247
248248
<Alert>
249249
250-
This example demonstrates proper queue instrumentation patterns. For more details on instrumenting queues, see the <PlatformLink to="platforms/javascript/guides/node/tracing/instrumentation/queues-module/">Queues Module documentation</PlatformLink>.
250+
This example demonstrates proper queue instrumentation patterns. For more details on instrumenting queues, see the <PlatformLink to="/tracing/instrumentation/queues-module/" fallbackPlatform="node">Queues Module documentation</PlatformLink>.
251251
252252
</Alert>
253253

src/components/platformLink.tsx

Lines changed: 85 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {getCurrentPlatformOrGuide, getPlatform} from 'sentry-docs/docTree';
1+
import {getCurrentPlatformOrGuide, getPlatform, nodeForPath} from 'sentry-docs/docTree';
22
import {serverContext} from 'sentry-docs/serverContext';
33
import {Platform, PlatformGuide} from 'sentry-docs/types';
44

@@ -9,11 +9,44 @@ function getPlatformsWithFallback(
99
platformOrGuide: Platform | PlatformGuide
1010
) {
1111
const result = [platformOrGuide.key];
12-
let curPlatform: Platform | PlatformGuide | undefined = platformOrGuide;
13-
while (curPlatform?.fallbackPlatform) {
14-
result.push(curPlatform.fallbackPlatform);
15-
curPlatform = getPlatform(rootNode, curPlatform.fallbackPlatform);
12+
let curPlatformOrGuide: Platform | PlatformGuide | undefined = platformOrGuide;
13+
14+
while (curPlatformOrGuide) {
15+
let fallbackKey: string | undefined;
16+
17+
// For guides, check fallbackGuide first
18+
if ('fallbackGuide' in curPlatformOrGuide && curPlatformOrGuide.fallbackGuide) {
19+
// fallbackGuide is the full key like "javascript.node"
20+
result.push(curPlatformOrGuide.fallbackGuide);
21+
// After the guide fallback, also check the guide's parent platform
22+
const guidePlatform = getPlatform(rootNode, curPlatformOrGuide.platform);
23+
if (guidePlatform?.fallbackPlatform) {
24+
result.push(guidePlatform.fallbackPlatform);
25+
}
26+
break;
27+
}
28+
// For JavaScript guides without explicit fallbackGuide, check if they're server-side
29+
// If so, include node in the fallback chain
30+
else if (
31+
'platform' in curPlatformOrGuide &&
32+
curPlatformOrGuide.platform === 'javascript' &&
33+
(curPlatformOrGuide.categories?.includes('server') ||
34+
curPlatformOrGuide.categories?.includes('serverless'))
35+
) {
36+
// Include node platform for server-side JavaScript guides
37+
result.push('node');
38+
break;
39+
}
40+
// For platforms, check fallbackPlatform
41+
else if (curPlatformOrGuide.fallbackPlatform) {
42+
fallbackKey = curPlatformOrGuide.fallbackPlatform;
43+
result.push(fallbackKey);
44+
curPlatformOrGuide = getPlatform(rootNode, fallbackKey);
45+
} else {
46+
break;
47+
}
1648
}
49+
1750
return result;
1851
}
1952

@@ -33,12 +66,19 @@ const isSupported = (
3366

3467
type Props = {
3568
children: React.ReactNode;
69+
fallbackPlatform?: string;
3670
notSupported?: string[];
3771
supported?: string[];
3872
to?: string;
3973
};
4074

41-
export function PlatformLink({children, to, supported = [], notSupported = []}: Props) {
75+
export function PlatformLink({
76+
children,
77+
to,
78+
supported = [],
79+
notSupported = [],
80+
fallbackPlatform,
81+
}: Props) {
4282
if (!to) {
4383
return children;
4484
}
@@ -73,9 +113,47 @@ export function PlatformLink({children, to, supported = [], notSupported = []}:
73113

74114
let href: string;
75115
if (currentPlatformOrGuide) {
76-
href = currentPlatformOrGuide.url + to.slice(1);
116+
if (fallbackPlatform) {
117+
const pathParts = to.split('/').filter(Boolean);
118+
const platformsToCheck = getPlatformsWithFallback(rootNode, currentPlatformOrGuide);
119+
let contentExistsInChain = false;
120+
121+
for (const platformKey of platformsToCheck) {
122+
let platformPath: string[];
123+
if (platformKey.includes('.')) {
124+
const [platform, guide] = platformKey.split('.');
125+
platformPath = ['platforms', platform, 'guides', guide];
126+
} else {
127+
platformPath = ['platforms', platformKey];
128+
}
129+
130+
const targetNode = nodeForPath(rootNode, [...platformPath, ...pathParts]);
131+
132+
if (targetNode) {
133+
contentExistsInChain = true;
134+
break;
135+
}
136+
}
137+
138+
// If content exists anywhere in the natural fallback chain, use current platform URL
139+
// Otherwise, use the explicit fallbackPlatform
140+
if (contentExistsInChain) {
141+
href = currentPlatformOrGuide.url + to.slice(1);
142+
} else {
143+
const fallbackPlatformObj = getPlatform(rootNode, fallbackPlatform);
144+
if (fallbackPlatformObj) {
145+
href = fallbackPlatformObj.url + to.slice(1);
146+
} else {
147+
// Fallback platform not found, construct URL manually
148+
href = `/platforms/${fallbackPlatform}${to}`;
149+
}
150+
}
151+
} else {
152+
href = currentPlatformOrGuide.url + to.slice(1);
153+
}
77154
} else {
78155
href = `/platform-redirect/?next=${encodeURIComponent(to)}`;
79156
}
157+
80158
return <SmartLink href={href}>{children}</SmartLink>;
81159
}

0 commit comments

Comments
 (0)