From 44a0010b0d07d805594a6c7678f32112c24f0162 Mon Sep 17 00:00:00 2001 From: hainenber Date: Sun, 5 Jan 2025 12:22:59 +0700 Subject: [PATCH] chore: refactor for uplifting react-error-boundary to v5 Signed-off-by: hainenber --- superset-frontend/package-lock.json | 35 ++++++++++++------- .../packages/superset-ui-core/package.json | 2 +- .../src/chart/components/SuperChart.tsx | 7 ++-- .../components/FallbackComponent.test.tsx | 19 +++++++--- .../test/chart/components/SuperChart.test.tsx | 4 +-- 5 files changed, 45 insertions(+), 22 deletions(-) diff --git a/superset-frontend/package-lock.json b/superset-frontend/package-lock.json index f55751e25bf58..2a3e7421be5ae 100644 --- a/superset-frontend/package-lock.json +++ b/superset-frontend/package-lock.json @@ -45379,13 +45379,6 @@ "react-dom": ">= 16.3.0" } }, - "node_modules/react-error-boundary": { - "version": "1.2.5", - "license": "MIT", - "peerDependencies": { - "react": "^16.0.0-beta.1" - } - }, "node_modules/react-hot-loader": { "version": "4.13.1", "license": "MIT", @@ -55666,7 +55659,7 @@ "lodash": "^4.17.21", "math-expression-evaluator": "^1.3.8", "pretty-ms": "^9.2.0", - "react-error-boundary": "^1.2.5", + "react-error-boundary": "^5.0.0", "react-markdown": "^8.0.7", "rehype-raw": "^7.0.0", "rehype-sanitize": "^6.0.0", @@ -56106,6 +56099,18 @@ "url": "https://opencollective.com/unified" } }, + "packages/superset-ui-core/node_modules/react-error-boundary": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/react-error-boundary/-/react-error-boundary-5.0.0.tgz", + "integrity": "sha512-tnjAxG+IkpLephNcePNA7v6F/QpWLH8He65+DmedchDwg162JZqx4NmbXj0mlAYVVEd81OW7aFhmbsScYfiAFQ==", + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.12.5" + }, + "peerDependencies": { + "react": ">=16.13.1" + } + }, "packages/superset-ui-core/node_modules/remark-gfm": { "version": "3.0.1", "license": "MIT", @@ -66521,7 +66526,7 @@ "lodash": "^4.17.21", "math-expression-evaluator": "^1.3.8", "pretty-ms": "^9.2.0", - "react-error-boundary": "^1.2.5", + "react-error-boundary": "^5.0.0", "react-markdown": "^8.0.7", "rehype-raw": "^7.0.0", "rehype-sanitize": "^6.0.0", @@ -66807,6 +66812,14 @@ "uvu": "^0.5.0" } }, + "react-error-boundary": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/react-error-boundary/-/react-error-boundary-5.0.0.tgz", + "integrity": "sha512-tnjAxG+IkpLephNcePNA7v6F/QpWLH8He65+DmedchDwg162JZqx4NmbXj0mlAYVVEd81OW7aFhmbsScYfiAFQ==", + "requires": { + "@babel/runtime": "^7.12.5" + } + }, "remark-gfm": { "version": "3.0.1", "requires": { @@ -90605,10 +90618,6 @@ "prop-types": "^15.8.1" } }, - "react-error-boundary": { - "version": "1.2.5", - "requires": {} - }, "react-hot-loader": { "version": "4.13.1", "requires": { diff --git a/superset-frontend/packages/superset-ui-core/package.json b/superset-frontend/packages/superset-ui-core/package.json index 227a5231893c5..1993f6f2f57df 100644 --- a/superset-frontend/packages/superset-ui-core/package.json +++ b/superset-frontend/packages/superset-ui-core/package.json @@ -38,7 +38,7 @@ "lodash": "^4.17.21", "math-expression-evaluator": "^1.3.8", "pretty-ms": "^9.2.0", - "react-error-boundary": "^1.2.5", + "react-error-boundary": "^5.0.0", "react-markdown": "^8.0.7", "rehype-raw": "^7.0.0", "rehype-sanitize": "^6.0.0", diff --git a/superset-frontend/packages/superset-ui-core/src/chart/components/SuperChart.tsx b/superset-frontend/packages/superset-ui-core/src/chart/components/SuperChart.tsx index 473a3506a411e..10db67c26d850 100644 --- a/superset-frontend/packages/superset-ui-core/src/chart/components/SuperChart.tsx +++ b/superset-frontend/packages/superset-ui-core/src/chart/components/SuperChart.tsx @@ -25,7 +25,8 @@ import { Fragment, } from 'react'; -import ErrorBoundary, { +import { + ErrorBoundary, ErrorBoundaryProps, FallbackProps, } from 'react-error-boundary'; @@ -46,7 +47,9 @@ const defaultProps = { enableNoResults: true, }; -export type FallbackPropsWithDimension = FallbackProps & Partial; +export type FallbackPropsWithDimension = FallbackProps & { + componentStack?: string; +} & Partial; export type WrapperProps = Dimension & { children: ReactNode; diff --git a/superset-frontend/packages/superset-ui-core/test/chart/components/FallbackComponent.test.tsx b/superset-frontend/packages/superset-ui-core/test/chart/components/FallbackComponent.test.tsx index 2a52c62e5e8ec..9a1d0df3860b1 100644 --- a/superset-frontend/packages/superset-ui-core/test/chart/components/FallbackComponent.test.tsx +++ b/superset-frontend/packages/superset-ui-core/test/chart/components/FallbackComponent.test.tsx @@ -24,7 +24,7 @@ import { ThemeProvider, supersetTheme } from '../../../src/style'; import FallbackComponent from '../../../src/chart/components/FallbackComponent'; -const renderWithTheme = (props: FallbackProps) => +const renderWithTheme = (props: FallbackProps & { componentStack?: string }) => render( @@ -38,23 +38,34 @@ test('renders error and stack trace', () => { const { getByText } = renderWithTheme({ componentStack: STACK_TRACE, error: ERROR, + resetErrorBoundary: jest.fn(), }); expect(getByText('Error: CaffeineOverLoadException')).toBeInTheDocument(); expect(getByText('Error at line 1: x.drink(coffee)')).toBeInTheDocument(); }); test('renders error only', () => { - const { getByText } = renderWithTheme({ error: ERROR }); + const { getByText } = renderWithTheme({ + error: ERROR, + resetErrorBoundary: jest.fn(), + }); expect(getByText('Error: CaffeineOverLoadException')).toBeInTheDocument(); }); test('renders stacktrace only', () => { - const { getByText } = renderWithTheme({ componentStack: STACK_TRACE }); + const { getByText } = renderWithTheme({ + componentStack: STACK_TRACE, + error: undefined, + resetErrorBoundary: jest.fn(), + }); expect(getByText('Unknown Error')).toBeInTheDocument(); expect(getByText('Error at line 1: x.drink(coffee)')).toBeInTheDocument(); }); test('renders when nothing is given', () => { - const { getByText } = renderWithTheme({}); + const { getByText } = renderWithTheme({ + error: undefined, + resetErrorBoundary: jest.fn(), + }); expect(getByText('Unknown Error')).toBeInTheDocument(); }); diff --git a/superset-frontend/packages/superset-ui-core/test/chart/components/SuperChart.test.tsx b/superset-frontend/packages/superset-ui-core/test/chart/components/SuperChart.test.tsx index a602279ba8761..9627487ed0555 100644 --- a/superset-frontend/packages/superset-ui-core/test/chart/components/SuperChart.test.tsx +++ b/superset-frontend/packages/superset-ui-core/test/chart/components/SuperChart.test.tsx @@ -20,7 +20,7 @@ import { ReactElement } from 'react'; import mockConsole, { RestoreConsole } from 'jest-mock-console'; import { triggerResizeObserver } from 'resize-observer-polyfill'; -import ErrorBoundary from 'react-error-boundary'; +import { ErrorBoundary } from 'react-error-boundary'; import { promiseTimeout, @@ -165,7 +165,7 @@ describe('SuperChart', () => { const inactiveErrorHandler = jest.fn(); const activeErrorHandler = jest.fn(); mount( - + null}>