From 9cf2bf11997eb6341af5fc5c7031ade849c42235 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Thu, 26 May 2022 19:05:03 +0800 Subject: [PATCH] fix(core): always treat error boundary fallback as a callback (#7492) Co-authored-by: sebastienlorber --- .../src/index.d.ts | 23 +++++++++---------- .../src/theme/Layout/index.tsx | 4 +++- packages/docusaurus/src/client/App.tsx | 4 +--- .../src/client/exports/ErrorBoundary.tsx | 22 +++++++++++++----- website/docs/docusaurus-core.md | 8 ++++++- 5 files changed, 38 insertions(+), 23 deletions(-) diff --git a/packages/docusaurus-module-type-aliases/src/index.d.ts b/packages/docusaurus-module-type-aliases/src/index.d.ts index 3a900c907d77..c8f2c995f012 100644 --- a/packages/docusaurus-module-type-aliases/src/index.d.ts +++ b/packages/docusaurus-module-type-aliases/src/index.d.ts @@ -77,14 +77,9 @@ declare module '@theme-original/*'; declare module '@theme-init/*'; declare module '@theme/Error' { - import type {ComponentProps} from 'react'; - import type ErrorBoundary from '@docusaurus/ErrorBoundary'; + import type {FallbackParams} from '@docusaurus/ErrorBoundary'; - type ErrorProps = ComponentProps< - NonNullable['fallback']> - >; - - export interface Props extends ErrorProps {} + export interface Props extends FallbackParams {} export default function Error(props: Props): JSX.Element; } @@ -125,13 +120,17 @@ declare module '@docusaurus/constants' { } declare module '@docusaurus/ErrorBoundary' { - import type {ReactNode, ComponentType} from 'react'; + import type {ReactNode} from 'react'; + + export type FallbackParams = { + readonly error: Error; + readonly tryAgain: () => void; + }; + + export type FallbackFunction = (params: FallbackParams) => JSX.Element; export interface Props { - readonly fallback?: ComponentType<{ - readonly error: Error; - readonly tryAgain: () => void; - }>; + readonly fallback?: FallbackFunction; readonly children: ReactNode; } export default function ErrorBoundary(props: Props): JSX.Element; diff --git a/packages/docusaurus-theme-classic/src/theme/Layout/index.tsx b/packages/docusaurus-theme-classic/src/theme/Layout/index.tsx index c5503edcaaa2..7f58712af95c 100644 --- a/packages/docusaurus-theme-classic/src/theme/Layout/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Layout/index.tsx @@ -45,7 +45,9 @@ export default function Layout(props: Props): JSX.Element {
- {children} + }> + {children} +
{!noFooter &&