Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ Where to put this in your app:

<Alert>

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>.
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>.

</Alert>

Expand Down
92 changes: 85 additions & 7 deletions src/components/platformLink.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {getCurrentPlatformOrGuide, getPlatform} from 'sentry-docs/docTree';
import {getCurrentPlatformOrGuide, getPlatform, nodeForPath} from 'sentry-docs/docTree';
import {serverContext} from 'sentry-docs/serverContext';
import {Platform, PlatformGuide} from 'sentry-docs/types';

Expand All @@ -9,11 +9,44 @@ function getPlatformsWithFallback(
platformOrGuide: Platform | PlatformGuide
) {
const result = [platformOrGuide.key];
let curPlatform: Platform | PlatformGuide | undefined = platformOrGuide;
while (curPlatform?.fallbackPlatform) {
result.push(curPlatform.fallbackPlatform);
curPlatform = getPlatform(rootNode, curPlatform.fallbackPlatform);
let curPlatformOrGuide: Platform | PlatformGuide | undefined = platformOrGuide;

while (curPlatformOrGuide) {
let fallbackKey: string | undefined;

// For guides, check fallbackGuide first
if ('fallbackGuide' in curPlatformOrGuide && curPlatformOrGuide.fallbackGuide) {
// fallbackGuide is the full key like "javascript.node"
result.push(curPlatformOrGuide.fallbackGuide);
// After the guide fallback, also check the guide's parent platform
const guidePlatform = getPlatform(rootNode, curPlatformOrGuide.platform);
if (guidePlatform?.fallbackPlatform) {
result.push(guidePlatform.fallbackPlatform);
}
break;
}
// For JavaScript guides without explicit fallbackGuide, check if they're server-side
// If so, include node in the fallback chain
else if (
'platform' in curPlatformOrGuide &&
curPlatformOrGuide.platform === 'javascript' &&
(curPlatformOrGuide.categories?.includes('server') ||
curPlatformOrGuide.categories?.includes('serverless'))
) {
// Include node platform for server-side JavaScript guides
result.push('node');
break;
}
// For platforms, check fallbackPlatform
else if (curPlatformOrGuide.fallbackPlatform) {
fallbackKey = curPlatformOrGuide.fallbackPlatform;
result.push(fallbackKey);
curPlatformOrGuide = getPlatform(rootNode, fallbackKey);
} else {
break;
}
}

return result;
}

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

type Props = {
children: React.ReactNode;
fallbackPlatform?: string;
notSupported?: string[];
supported?: string[];
to?: string;
};

export function PlatformLink({children, to, supported = [], notSupported = []}: Props) {
export function PlatformLink({
children,
to,
supported = [],
notSupported = [],
fallbackPlatform,
}: Props) {
if (!to) {
return children;
}
Expand Down Expand Up @@ -73,9 +113,47 @@ export function PlatformLink({children, to, supported = [], notSupported = []}:

let href: string;
if (currentPlatformOrGuide) {
href = currentPlatformOrGuide.url + to.slice(1);
if (fallbackPlatform) {
const pathParts = to.split('/').filter(Boolean);
const platformsToCheck = getPlatformsWithFallback(rootNode, currentPlatformOrGuide);
let contentExistsInChain = false;

for (const platformKey of platformsToCheck) {
let platformPath: string[];
if (platformKey.includes('.')) {
const [platform, guide] = platformKey.split('.');
platformPath = ['platforms', platform, 'guides', guide];
} else {
platformPath = ['platforms', platformKey];
}

const targetNode = nodeForPath(rootNode, [...platformPath, ...pathParts]);

if (targetNode) {
contentExistsInChain = true;
break;
}
}

// If content exists anywhere in the natural fallback chain, use current platform URL
// Otherwise, use the explicit fallbackPlatform
if (contentExistsInChain) {
href = currentPlatformOrGuide.url + to.slice(1);
} else {
const fallbackPlatformObj = getPlatform(rootNode, fallbackPlatform);
if (fallbackPlatformObj) {
href = fallbackPlatformObj.url + to.slice(1);
} else {
// Fallback platform not found, construct URL manually
href = `/platforms/${fallbackPlatform}${to}`;
}
}
} else {
href = currentPlatformOrGuide.url + to.slice(1);
}
} else {
href = `/platform-redirect/?next=${encodeURIComponent(to)}`;
}

return <SmartLink href={href}>{children}</SmartLink>;
}
Loading