fix(mobile): editor error boundary is not fully visible (#9172)

This commit is contained in:
CatsJuice
2024-12-17 02:38:11 +00:00
parent 563da3b6f4
commit 12954ec82c
4 changed files with 17 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
import { useI18n } from '@affine/i18n'; import { useI18n } from '@affine/i18n';
import { getCurrentStore } from '@toeverything/infra'; import { getCurrentStore } from '@toeverything/infra';
import clsx from 'clsx';
import { Provider } from 'jotai/react'; import { Provider } from 'jotai/react';
import type { FC } from 'react'; import type { FC } from 'react';
import { useCallback, useMemo } from 'react'; import { useCallback, useMemo } from 'react';
@@ -32,6 +33,7 @@ function getErrorFallbackComponent(error: any): FC<FallbackProps> {
export interface AffineErrorFallbackProps extends FallbackProps { export interface AffineErrorFallbackProps extends FallbackProps {
height?: number | string; height?: number | string;
className?: string;
} }
export const AffineErrorFallback: FC<AffineErrorFallbackProps> = props => { export const AffineErrorFallback: FC<AffineErrorFallbackProps> = props => {
@@ -39,7 +41,7 @@ export const AffineErrorFallback: FC<AffineErrorFallbackProps> = props => {
const Component = useMemo(() => getErrorFallbackComponent(error), [error]); const Component = useMemo(() => getErrorFallbackComponent(error), [error]);
return ( return (
<div className={styles.viewport} style={{ height }}> <div className={clsx(styles.viewport, props.className)} style={{ height }}>
<Component error={error} resetError={resetError} /> <Component error={error} resetError={resetError} />
<Provider key="JotaiProvider" store={getCurrentStore()}> <Provider key="JotaiProvider" store={getCurrentStore()}>
<DumpInfo error={error} /> <DumpInfo error={error} />

View File

@@ -8,6 +8,7 @@ export { type FallbackProps } from './error-basic/fallback-creator';
export interface AffineErrorBoundaryProps extends PropsWithChildren { export interface AffineErrorBoundaryProps extends PropsWithChildren {
height?: number | string; height?: number | string;
className?: string;
} }
/** /**
@@ -16,9 +17,15 @@ export interface AffineErrorBoundaryProps extends PropsWithChildren {
export const AffineErrorBoundary: FC<AffineErrorBoundaryProps> = props => { export const AffineErrorBoundary: FC<AffineErrorBoundaryProps> = props => {
const fallbackRender: FallbackRender = useCallback( const fallbackRender: FallbackRender = useCallback(
fallbackProps => { fallbackProps => {
return <AffineErrorFallback {...fallbackProps} height={props.height} />; return (
<AffineErrorFallback
{...fallbackProps}
height={props.height}
className={props.className}
/>
);
}, },
[props.height] [props.height, props.className]
); );
const onError = useCallback((error: unknown, componentStack?: string) => { const onError = useCallback((error: unknown, componentStack?: string) => {

View File

@@ -80,6 +80,10 @@ export const affineDocViewport = style({
}, },
}); });
export const errorBoundary = style({
flex: 1,
});
export const scrollbar = style({ export const scrollbar = style({
marginRight: '4px', marginRight: '4px',
}); });

View File

@@ -205,7 +205,7 @@ const DetailPageImpl = () => {
)} )}
> >
{/* Add a key to force rerender when page changed, to avoid error boundary persisting. */} {/* Add a key to force rerender when page changed, to avoid error boundary persisting. */}
<AffineErrorBoundary key={doc.id}> <AffineErrorBoundary key={doc.id} className={styles.errorBoundary}>
<PageDetailEditor onLoad={onLoad} /> <PageDetailEditor onLoad={onLoad} />
</AffineErrorBoundary> </AffineErrorBoundary>
</div> </div>