From 66dd2cf1947ad2888e313615ecfe82f07ceb277e Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 18 Sep 2026 11:13:23 +0200 Subject: [PATCH 1/2] refactor(js): centralize server/browser category predicates Extract the repeated `categories.includes('server') || includes('serverless')` logic into shared `hasServerCategory` / `hasBrowserCategory` helpers (src/categories.ts) and use them in `sdkOption` and `platformLink`. Behavior-preserving cleanup; no rendered output changes. The `nextjs` / `sveltekit` env-var exclusion in `shouldShowEnvVar` is intentionally left as a framework-specific special case (it is not a "server-only" proxy: other meta-frameworks such as astro/remix/nuxt do read process.env on their server side and should keep the ENV row). The new `browser-only` / `server-only` categories are consumed generically by `PlatformCategorySection` from MDX and need no dedicated code path here. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/categories.ts | 26 ++++++++++++++++++++++++++ src/components/platformLink.tsx | 4 ++-- src/components/sdkOption.tsx | 22 ++++++---------------- 3 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 src/categories.ts diff --git a/src/categories.ts b/src/categories.ts new file mode 100644 index 0000000000000..bc8532fff6e7a --- /dev/null +++ b/src/categories.ts @@ -0,0 +1,26 @@ +import {PlatformCategory} from './types'; + +/** + * Category predicates shared across components. + * + * A platform or guide can carry several categories at once. Meta-frameworks + * (e.g. Next.js, Remix) run in both the browser and on a server, so they carry + * both `browser` and `server`. The `browser-only` / `server-only` categories + * mark platforms that run *exclusively* on one side (something the `browser` / + * `server` tags alone cannot express) and are primarily consumed from MDX via + * ``. + */ + +/** Whether the categories include a server-side runtime (`server` or `serverless`). */ +export function hasServerCategory( + categories?: PlatformCategory[] | null +): boolean { + return !!categories?.some(c => c === 'server' || c === 'serverless'); +} + +/** Whether the categories include the browser runtime. */ +export function hasBrowserCategory( + categories?: PlatformCategory[] | null +): boolean { + return !!categories?.includes('browser'); +} diff --git a/src/components/platformLink.tsx b/src/components/platformLink.tsx index 29aa5c4846cca..cb22a82147ce8 100644 --- a/src/components/platformLink.tsx +++ b/src/components/platformLink.tsx @@ -1,3 +1,4 @@ +import {hasServerCategory} from 'sentry-docs/categories'; import {getCurrentPlatformOrGuide, getPlatform, nodeForPath} from 'sentry-docs/docTree'; import {serverContext} from 'sentry-docs/serverContext'; import {Platform, PlatformGuide} from 'sentry-docs/types'; @@ -30,8 +31,7 @@ function getPlatformsWithFallback( else if ( 'platform' in curPlatformOrGuide && curPlatformOrGuide.platform === 'javascript' && - (curPlatformOrGuide.categories?.includes('server') || - curPlatformOrGuide.categories?.includes('serverless')) + hasServerCategory(curPlatformOrGuide.categories) ) { // Include node platform for server-side JavaScript guides result.push('node'); diff --git a/src/components/sdkOption.tsx b/src/components/sdkOption.tsx index c877764af3b76..a9a8debf998d1 100644 --- a/src/components/sdkOption.tsx +++ b/src/components/sdkOption.tsx @@ -1,3 +1,4 @@ +import {hasBrowserCategory, hasServerCategory} from 'sentry-docs/categories'; import {getCurrentPlatformOrGuide} from 'sentry-docs/docTree'; import {serverContext} from 'sentry-docs/serverContext'; import {PlatformCategory} from 'sentry-docs/types'; @@ -31,9 +32,7 @@ export function SdkOption({ const shouldShowEnvVar = () => { if (!currentPlatformOrGuide) return false; - const isServerPlatform = - currentPlatformOrGuide.categories?.includes('server') || - currentPlatformOrGuide.categories?.includes('serverless'); + const isServerPlatform = hasServerCategory(currentPlatformOrGuide.categories); const isExcludedPlatform = currentPlatformOrGuide.key === 'javascript.nextjs' || @@ -91,25 +90,16 @@ export function getPlatformHints(categorySupported: PlatformCategory[]) { const currentPlatformOrGuide = getCurrentPlatformOrGuide(rootNode, path); const currentCategories = currentPlatformOrGuide?.categories || []; - // We only handle browser, server & serverless here for now - const currentIsBrowser = currentCategories.includes('browser'); - const currentIsServer = currentCategories.includes('server'); - const currentIsServerless = currentCategories.includes('serverless'); - const currentIsServerLike = currentIsServer || currentIsServerless; - const hasCategorySupported = categorySupported.length > 0; const supportedBrowserOnly = - categorySupported.includes('browser') && - !categorySupported.includes('server') && - !categorySupported.includes('serverless'); + hasBrowserCategory(categorySupported) && !hasServerCategory(categorySupported); const supportedServerLikeOnly = - !categorySupported.includes('browser') && - (categorySupported.includes('server') || categorySupported.includes('serverless')); + !hasBrowserCategory(categorySupported) && hasServerCategory(categorySupported); const showBrowserOnly = - hasCategorySupported && supportedBrowserOnly && currentIsServerLike; + hasCategorySupported && supportedBrowserOnly && hasServerCategory(currentCategories); const showServerLikeOnly = - hasCategorySupported && supportedServerLikeOnly && currentIsBrowser; + hasCategorySupported && supportedServerLikeOnly && hasBrowserCategory(currentCategories); return {showBrowserOnly, showServerLikeOnly}; } From 18ba9aeb113de900622c7d1b60749cd56101b4c3 Mon Sep 17 00:00:00 2001 From: "getsantry[bot]" <66042841+getsantry[bot]@users.noreply.github.com> Date: Fri, 18 Sep 2026 10:25:34 +0000 Subject: [PATCH 2/2] [getsentry/action-github-commit] Auto commit --- src/categories.ts | 8 ++------ src/components/sdkOption.tsx | 4 +++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/categories.ts b/src/categories.ts index bc8532fff6e7a..ab2f5964c6446 100644 --- a/src/categories.ts +++ b/src/categories.ts @@ -12,15 +12,11 @@ import {PlatformCategory} from './types'; */ /** Whether the categories include a server-side runtime (`server` or `serverless`). */ -export function hasServerCategory( - categories?: PlatformCategory[] | null -): boolean { +export function hasServerCategory(categories?: PlatformCategory[] | null): boolean { return !!categories?.some(c => c === 'server' || c === 'serverless'); } /** Whether the categories include the browser runtime. */ -export function hasBrowserCategory( - categories?: PlatformCategory[] | null -): boolean { +export function hasBrowserCategory(categories?: PlatformCategory[] | null): boolean { return !!categories?.includes('browser'); } diff --git a/src/components/sdkOption.tsx b/src/components/sdkOption.tsx index a9a8debf998d1..1b8a405b10dec 100644 --- a/src/components/sdkOption.tsx +++ b/src/components/sdkOption.tsx @@ -99,7 +99,9 @@ export function getPlatformHints(categorySupported: PlatformCategory[]) { const showBrowserOnly = hasCategorySupported && supportedBrowserOnly && hasServerCategory(currentCategories); const showServerLikeOnly = - hasCategorySupported && supportedServerLikeOnly && hasBrowserCategory(currentCategories); + hasCategorySupported && + supportedServerLikeOnly && + hasBrowserCategory(currentCategories); return {showBrowserOnly, showServerLikeOnly}; }