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
22 changes: 22 additions & 0 deletions src/categories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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
* `<PlatformCategorySection>`.
*/
Comment on lines +10 to +12

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The hasServerCategory and hasBrowserCategory helpers fail to check for the 'server-only' and 'browser-only' categories, respectively, making them logically incomplete.
Severity: LOW

Suggested Fix

Update the helper functions to include checks for the '-only' category variants. The hasServerCategory function should be modified to also return true if the categories include 'server-only', and hasBrowserCategory should be updated to include 'browser-only'.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/categories.ts#L10-L12

Potential issue: The new helper functions `hasServerCategory` and `hasBrowserCategory`
do not correctly handle all possible category types. Specifically, `hasServerCategory`
checks for `'server'` and `'serverless'` but omits the `'server-only'` category.
Similarly, `hasBrowserCategory` checks for `'browser'` but omits `'browser-only'`. While
these `'-only'` categories are defined in the `PlatformCategory` type, they are not
currently used in the codebase. This means the bug is latent and would only be triggered
if a developer creates a new platform using these categories, which could lead to
incorrect UI rendering or logic.

Also affects:

  • src/categories.ts:18~20

Did we get this right? 👍 / 👎 to inform future reviews.


/** 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');
}
4 changes: 2 additions & 2 deletions src/components/platformLink.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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');
Expand Down
24 changes: 8 additions & 16 deletions src/components/sdkOption.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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' ||
Expand Down Expand Up @@ -91,25 +90,18 @@ 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};
}
Loading