Skip to content

Commit

Permalink
[fix] Fix white screen when error handled by AppErrorBoundary (twenty…
Browse files Browse the repository at this point in the history
…hq#5017)

[In a previous PR](twentyhq#5008) I was
fixing dark mode by calling useTheme in AppErrorBoundary while there was
actually no parent ThemeProvider. This was causing a bug when an error
was actually intercepted by AppErrorBoundary because theme was empty.

Now I am providing the error theme in GenericErrorFallback, fallbacking
to THEME_LIGHT as it can be called from outside a ThemeProvider (as it
is the case today), but also reading into ThemeProvider in case we end
up using this component in a part of the application where it is
available, not to necessarily use THEME_LIGHT.

## How was it tested?
with @thaisguigon 
Locally (dark mode works + error mode works (throwing an error in
RecoilDebugObserver))
  • Loading branch information
ijreilly authored Apr 18, 2024
1 parent 03e0fd2 commit 3e60c00
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ErrorInfo, ReactNode } from 'react';
import { ErrorBoundary } from 'react-error-boundary';
import { ThemeProvider, useTheme } from '@emotion/react';

import { GenericErrorFallback } from '@/error-handler/components/GenericErrorFallback';

Expand All @@ -9,16 +8,12 @@ export const AppErrorBoundary = ({ children }: { children: ReactNode }) => {
// TODO: log error to Sentry
};

const theme = useTheme();

return (
<ThemeProvider theme={theme}>
<ErrorBoundary
FallbackComponent={GenericErrorFallback}
onError={handleError}
>
{children}
</ErrorBoundary>
</ThemeProvider>
<ErrorBoundary
FallbackComponent={GenericErrorFallback}
onError={handleError}
>
{children}
</ErrorBoundary>
);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { FallbackProps } from 'react-error-boundary';
import { IconRefresh } from 'twenty-ui';
import { ThemeProvider, useTheme } from '@emotion/react';
import isEmpty from 'lodash.isempty';
import { IconRefresh, THEME_LIGHT } from 'twenty-ui';

import { Button } from '@/ui/input/button/components/Button';
import AnimatedPlaceholder from '@/ui/layout/animated-placeholder/components/AnimatedPlaceholder';
Expand All @@ -16,23 +18,26 @@ export const GenericErrorFallback = ({
error,
resetErrorBoundary,
}: GenericErrorFallbackProps) => {
const theme = useTheme();
return (
<AnimatedPlaceholderEmptyContainer>
<AnimatedPlaceholder type="errorIndex" />
<AnimatedPlaceholderEmptyTextContainer>
<AnimatedPlaceholderEmptyTitle>
Server’s on a coffee break
</AnimatedPlaceholderEmptyTitle>
<AnimatedPlaceholderEmptySubTitle>
{error.message}
</AnimatedPlaceholderEmptySubTitle>
</AnimatedPlaceholderEmptyTextContainer>
<Button
Icon={IconRefresh}
title="Reload"
variant={'secondary'}
onClick={() => resetErrorBoundary()}
/>
</AnimatedPlaceholderEmptyContainer>
<ThemeProvider theme={isEmpty(theme) ? THEME_LIGHT : theme}>
<AnimatedPlaceholderEmptyContainer>
<AnimatedPlaceholder type="errorIndex" />
<AnimatedPlaceholderEmptyTextContainer>
<AnimatedPlaceholderEmptyTitle>
Server’s on a coffee break
</AnimatedPlaceholderEmptyTitle>
<AnimatedPlaceholderEmptySubTitle>
{error.message}
</AnimatedPlaceholderEmptySubTitle>
</AnimatedPlaceholderEmptyTextContainer>
<Button
Icon={IconRefresh}
title="Reload"
variant={'secondary'}
onClick={() => resetErrorBoundary()}
/>
</AnimatedPlaceholderEmptyContainer>
</ThemeProvider>
);
};

0 comments on commit 3e60c00

Please sign in to comment.