fix(nextjs): Use dynamic imports for API page components#16240
Draft
jaffrepaul wants to merge 1 commit intomasterfrom
Draft
fix(nextjs): Use dynamic imports for API page components#16240jaffrepaul wants to merge 1 commit intomasterfrom
jaffrepaul wants to merge 1 commit intomasterfrom
Conversation
Fixes DOCS-A5B regression where pages fail to load at runtime because mdx-bundler cannot be found. The previous fix (PR #16232) excluded mdx-bundler from serverless bundles to avoid CJS/ESM compatibility issues. However, the static import of ApiPage in page.tsx caused mdx-bundler to be loaded at module initialization time, even for non-API pages like /changelog. This change uses next/dynamic to lazily import ApiCategoryPage and ApiPage only when actually rendering API routes, preventing the mdx-bundler import from executing for regular doc pages. Co-Authored-By: Claude <[email protected]> Co-authored-by: Cursor <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Comment on lines
+37
to
+42
| 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), |
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes DOCS-A5B regression where pages fail to load at runtime because
mdx-bundlercannot be found.Root cause: PR #16232 excluded
mdx-bundlerfrom serverless bundles to fix CJS/ESM compatibility issues. However, the static import ofApiPageinpage.tsxcausedmdx-bundlerto be loaded at module initialization time, even for non-API pages like/changelog.Fix: Use
next/dynamicto lazily importApiCategoryPageandApiPageonly when actually rendering API routes, preventing themdx-bundlerimport from executing for regular doc pages.Changes
ApiCategoryPageandApiPagewith dynamic imports usingnext/dynamic{ssr: true}to ensure server-side rendering still works for API pagesTest plan
/changelog) load without errors🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]
Made with Cursor