Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor for uplifting react-error-boundary to v5 #31711

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions superset-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion superset-frontend/packages/superset-ui-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
Fragment,
} from 'react';

import ErrorBoundary, {
import {
ErrorBoundary,
ErrorBoundaryProps,
FallbackProps,
} from 'react-error-boundary';
Expand All @@ -46,7 +47,9 @@ const defaultProps = {
enableNoResults: true,
};

export type FallbackPropsWithDimension = FallbackProps & Partial<Dimension>;
export type FallbackPropsWithDimension = FallbackProps & {
componentStack?: string;
} & Partial<Dimension>;

export type WrapperProps = Dimension & {
children: ReactNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<ThemeProvider theme={supersetTheme}>
<FallbackComponent {...props} />
Expand All @@ -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();
});
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -165,7 +165,7 @@ describe('SuperChart', () => {
const inactiveErrorHandler = jest.fn();
const activeErrorHandler = jest.fn();
mount(
<ErrorBoundary onError={activeErrorHandler}>
<ErrorBoundary onError={activeErrorHandler} fallbackRender={() => null}>
<SuperChart
disableErrorBoundary
chartType={ChartKeys.BUGGY}
Expand Down
Loading