@@ -2,6 +2,7 @@ import {useMemo} from 'react';
22import { getMDXComponent } from 'mdx-bundler/client' ;
33import { Metadata } from 'next' ;
44import { notFound } from 'next/navigation' ;
5+ import { Suspense } from 'react' ;
56
67import { apiCategories } from 'sentry-docs/build/resolveOpenAPI' ;
78import { ApiCategoryPage } from 'sentry-docs/components/apiCategoryPage' ;
@@ -58,52 +59,13 @@ function MDXLayoutRenderer({mdxSource, ...rest}) {
5859 return < MDXLayout components = { mdxComponentsWithWrapper } { ...rest } /> ;
5960}
6061
61- export default async function Page ( props : { params : Promise < { path ?: string [ ] } > } ) {
62- const params = await props . params ;
63- // get frontmatter of all docs in tree
64- const rootNode = await getDocsRootNode ( ) ;
65-
66- setServerContext ( {
67- rootNode,
68- path : params . path ?? [ ] ,
69- } ) ;
70-
71- if ( ! params . path && ! isDeveloperDocs ) {
72- return < Home /> ;
73- }
74-
75- const pageNode = nodeForPath ( rootNode , params . path ?? '' ) ;
76-
77- if ( ! pageNode ) {
78- // eslint-disable-next-line no-console
79- console . warn ( 'no page node' , params . path ) ;
80- return notFound ( ) ;
81- }
82-
83- // gather previous and next page that will be displayed in the bottom pagination
84- const getPaginationDetails = (
85- getNode : ( node : DocNode ) => DocNode | undefined | 'root' ,
86- page : PaginationNavNode | undefined
87- ) => {
88- if ( page && 'path' in page && 'title' in page ) {
89- return page ;
90- }
91-
92- const node = getNode ( pageNode ) ;
93-
94- if ( node === 'root' ) {
95- return { path : '' , title : 'Welcome to Sentry' } ;
96- }
97-
98- return node ? { path : node . path , title : node . frontmatter . title } : undefined ;
99- } ;
100-
101- const previousPage = getPaginationDetails (
102- getPreviousNode ,
103- pageNode ?. frontmatter ?. previousPage
104- ) ;
105- const nextPage = getPaginationDetails ( getNextNode , pageNode ?. frontmatter ?. nextPage ) ;
62+ // Create a loading component
63+ function LoadingIndicator ( ) {
64+ return < div className = "loading-docs" > Loading documentation...</ div > ;
65+ }
10666
67+ // Create a separate MDX content component to use with Suspense
68+ async function MDXContent ( { pageNode, params} ) {
10769 if ( isDeveloperDocs ) {
10870 // get the MDX for the current doc and render it
10971 let doc : Awaited < ReturnType < typeof getFileBySlug > > | null = null ;
@@ -118,6 +80,31 @@ export default async function Page(props: {params: Promise<{path?: string[]}>})
11880 throw e ;
11981 }
12082 const { mdxSource, frontMatter} = doc ;
83+
84+ // gather previous and next page that will be displayed in the bottom pagination
85+ const getPaginationDetails = (
86+ getNode : ( node : DocNode ) => DocNode | undefined | 'root' ,
87+ page : PaginationNavNode | undefined
88+ ) => {
89+ if ( page && 'path' in page && 'title' in page ) {
90+ return page ;
91+ }
92+
93+ const node = getNode ( pageNode ) ;
94+
95+ if ( node === 'root' ) {
96+ return { path : '' , title : 'Welcome to Sentry' } ;
97+ }
98+
99+ return node ? { path : node . path , title : node . frontmatter . title } : undefined ;
100+ } ;
101+
102+ const previousPage = getPaginationDetails (
103+ getPreviousNode ,
104+ pageNode ?. frontmatter ?. previousPage
105+ ) ;
106+ const nextPage = getPaginationDetails ( getNextNode , pageNode ?. frontmatter ?. nextPage ) ;
107+
121108 // pass frontmatter tree into sidebar, rendered page + fm into middle, headers into toc
122109 return (
123110 < MDXLayoutRenderer
@@ -161,6 +148,30 @@ export default async function Page(props: {params: Promise<{path?: string[]}>})
161148 const allFm = await getDocsFrontMatter ( ) ;
162149 const versions = getVersionsFromDoc ( allFm , pageNode . path ) ;
163150
151+ // gather previous and next page that will be displayed in the bottom pagination
152+ const getPaginationDetails = (
153+ getNode : ( node : DocNode ) => DocNode | undefined | 'root' ,
154+ page : PaginationNavNode | undefined
155+ ) => {
156+ if ( page && 'path' in page && 'title' in page ) {
157+ return page ;
158+ }
159+
160+ const node = getNode ( pageNode ) ;
161+
162+ if ( node === 'root' ) {
163+ return { path : '' , title : 'Welcome to Sentry' } ;
164+ }
165+
166+ return node ? { path : node . path , title : node . frontmatter . title } : undefined ;
167+ } ;
168+
169+ const previousPage = getPaginationDetails (
170+ getPreviousNode ,
171+ pageNode ?. frontmatter ?. previousPage
172+ ) ;
173+ const nextPage = getPaginationDetails ( getNextNode , pageNode ?. frontmatter ?. nextPage ) ;
174+
164175 // pass frontmatter tree into sidebar, rendered page + fm into middle, headers into toc.
165176 return (
166177 < MDXLayoutRenderer
@@ -172,6 +183,35 @@ export default async function Page(props: {params: Promise<{path?: string[]}>})
172183 ) ;
173184}
174185
186+ export default async function Page ( props : { params : Promise < { path ?: string [ ] } > } ) {
187+ const params = await props . params ;
188+ // get frontmatter of all docs in tree
189+ const rootNode = await getDocsRootNode ( ) ;
190+
191+ setServerContext ( {
192+ rootNode,
193+ path : params . path ?? [ ] ,
194+ } ) ;
195+
196+ if ( ! params . path && ! isDeveloperDocs ) {
197+ return < Home /> ;
198+ }
199+
200+ const pageNode = nodeForPath ( rootNode , params . path ?? '' ) ;
201+
202+ if ( ! pageNode ) {
203+ // eslint-disable-next-line no-console
204+ console . warn ( 'no page node' , params . path ) ;
205+ return notFound ( ) ;
206+ }
207+
208+ return (
209+ < Suspense fallback = { < LoadingIndicator /> } >
210+ < MDXContent pageNode = { pageNode } params = { params } />
211+ </ Suspense >
212+ ) ;
213+ }
214+
175215type MetadataProps = {
176216 params : Promise < {
177217 path ?: string [ ] ;
0 commit comments