Skip to content

Commit

Permalink
perf: Add suspense boundry for smoother hydration
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjaiyan-dev authored Oct 31, 2023
1 parent a7144df commit da1933e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import React, {Suspense} from 'react';
import clsx from 'clsx';
import Layout from '@theme/Layout';
import BlogSidebar from '@theme/BlogSidebar';
Expand All @@ -28,7 +28,7 @@ export default function BlogLayout(props: Props): JSX.Element {
})}
itemScope
itemType="https://schema.org/Blog">
{children}
<Suspense>{children}</Suspense>
</main>
{toc && <div className="col col--2">{toc}</div>}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import React, {useState} from 'react';
import React, {useState, Suspense} from 'react';
import {useDocsSidebar} from '@docusaurus/theme-common/internal';
import BackToTopButton from '@theme/BackToTopButton';
import DocRootLayoutSidebar from '@theme/DocRoot/Layout/Sidebar';
Expand All @@ -29,7 +29,7 @@ export default function DocRootLayout({children}: Props): JSX.Element {
/>
)}
<DocRootLayoutMain hiddenSidebarContainer={hiddenSidebarContainer}>
{children}
<Suspense>{children}</Suspense>
</DocRootLayoutMain>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-theme-classic/src/theme/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import React, {Suspense} from 'react';
import clsx from 'clsx';
import ErrorBoundary from '@docusaurus/ErrorBoundary';
import {
Expand Down Expand Up @@ -53,7 +53,7 @@ export default function Layout(props: Props): JSX.Element {
wrapperClassName,
)}>
<ErrorBoundary fallback={(params) => <ErrorPageContent {...params} />}>
{children}
<Suspense>{children}</Suspense>
</ErrorBoundary>
</div>

Expand Down
10 changes: 6 additions & 4 deletions packages/docusaurus-theme-classic/src/theme/MDXPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import React, {Suspense} from 'react';
import clsx from 'clsx';
import {
PageMetadata,
Expand Down Expand Up @@ -51,9 +51,11 @@ export default function MDXPage(props: Props): JSX.Element {
<div className={clsx('col', !hideTableOfContents && 'col--8')}>
{unlisted && <Unlisted />}
<article>
<MDXContent>
<MDXPageContent />
</MDXContent>
<Suspense>
<MDXContent>
<MDXPageContent />
</MDXContent>
</Suspense>
</article>
</div>
{!hideTableOfContents && MDXPageContent.toc.length > 0 && (
Expand Down

0 comments on commit da1933e

Please sign in to comment.