Skip to content
Draft
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
14 changes: 12 additions & 2 deletions app/[[...path]]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import {Fragment, useMemo} from 'react';
import * as Sentry from '@sentry/nextjs';
import {Metadata} from 'next';
import nextDynamic from 'next/dynamic';
import {notFound} from 'next/navigation';

import {apiCategories} from 'sentry-docs/build/resolveOpenAPI';
import {ApiCategoryPage} from 'sentry-docs/components/apiCategoryPage';
import {ApiPage} from 'sentry-docs/components/apiPage';
import {DocPage} from 'sentry-docs/components/docPage';
import {Home} from 'sentry-docs/components/home';
import {Include} from 'sentry-docs/components/include';
Expand Down Expand Up @@ -33,6 +32,17 @@ import {setServerContext} from 'sentry-docs/serverContext';
import {PaginationNavNode} from 'sentry-docs/types/paginationNavNode';
import {stripVersion} from 'sentry-docs/versioning';

// Dynamic imports for API page components to avoid loading mdx-bundler at module load time.
// mdx-bundler is excluded from serverless bundles, so we must only import it when actually needed.
const ApiCategoryPage = nextDynamic(
() => import('sentry-docs/components/apiCategoryPage').then(mod => mod.ApiCategoryPage),
{ssr: true}
);
const ApiPage = nextDynamic(
() => import('sentry-docs/components/apiPage').then(mod => mod.ApiPage),
Comment on lines +37 to +42
Copy link

Choose a reason for hiding this comment

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

Bug: The ApiCategoryPage async Server Component is imported using next/dynamic. This unsupported pattern will likely cause rendering failures for API documentation pages.
Severity: HIGH

Suggested Fix

Remove the next/dynamic wrapper around the ApiCategoryPage import. Since it is a Server Component, it should be imported directly like any other module. This ensures React's rendering engine can correctly handle the async component on the server.

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: app/[[...path]]/page.tsx#L37-L42

Potential issue: The code uses `next/dynamic` with `{ssr: true}` to import
`ApiCategoryPage`, which is an `async` Server Component. The `next/dynamic` API is
primarily designed for lazy-loading client-side components and is not intended to handle
the `Promise` returned by an `async` Server Component. This will likely lead to a
runtime error during server-side rendering, such as "Objects are not valid as a React
child," because the component's promise is not being awaited. Consequently, API
documentation category pages will fail to render.

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

{ssr: true}
);

export async function generateStaticParams() {
const docs = await (isDeveloperDocs ? getDevDocsFrontMatter() : getDocsFrontMatter());
const paths: {path: string[] | undefined}[] = docs.map(doc => {
Expand Down
Loading