mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-22 04:26:23 +08:00
fix(core): rerender error boundary when route change and improve sentry report (#5147)
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
|||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
|
import { type Map as YMap } from 'yjs';
|
||||||
|
|
||||||
import { Skeleton } from '../../ui/skeleton';
|
import { Skeleton } from '../../ui/skeleton';
|
||||||
import {
|
import {
|
||||||
@@ -82,17 +83,21 @@ export class NoPageRootError extends Error {
|
|||||||
super('Page root not found when render editor!');
|
super('Page root not found when render editor!');
|
||||||
|
|
||||||
// Log info to let sentry collect more message
|
// Log info to let sentry collect more message
|
||||||
const spaceVectors = Array.from(page.doc.spaces.entries()).map(
|
const hasExpectSpace = Array.from(page.doc.spaces.values()).some(
|
||||||
([pageId, doc]) => `${pageId} > ${doc.guid}`
|
doc => page.spaceDoc.guid === doc.guid
|
||||||
|
);
|
||||||
|
const blocks = page.spaceDoc.getMap('blocks') as YMap<YMap<any>>;
|
||||||
|
const havePageBlock = Array.from(blocks.values()).some(
|
||||||
|
block => block.get('sys:flavour') === 'affine:page'
|
||||||
);
|
);
|
||||||
const blocks = page.doc.getMap('blocks');
|
|
||||||
console.info(
|
console.info(
|
||||||
'NoPageRootError current data: %s',
|
'NoPageRootError current data: %s',
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
expectPageId: page.id,
|
expectPageId: page.id,
|
||||||
expectGuid: page.spaceDoc.guid,
|
expectGuid: page.spaceDoc.guid,
|
||||||
spaceVectors,
|
hasExpectSpace,
|
||||||
blockSize: blocks.size,
|
blockSize: blocks.size,
|
||||||
|
havePageBlock,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ export async function setup(store: ReturnType<typeof createStore>) {
|
|||||||
performanceSetupLogger.info('setup global');
|
performanceSetupLogger.info('setup global');
|
||||||
setupGlobal();
|
setupGlobal();
|
||||||
|
|
||||||
if (window.SENTRY_RELEASE) {
|
if (window.SENTRY_RELEASE || environment.isDebug) {
|
||||||
// https://docs.sentry.io/platforms/javascript/guides/react/#configure
|
// https://docs.sentry.io/platforms/javascript/guides/react/#configure
|
||||||
Sentry.init({
|
Sentry.init({
|
||||||
dsn: process.env.SENTRY_DSN,
|
dsn: process.env.SENTRY_DSN,
|
||||||
@@ -75,8 +75,10 @@ export async function setup(store: ReturnType<typeof createStore>) {
|
|||||||
),
|
),
|
||||||
}),
|
}),
|
||||||
new Sentry.Replay(),
|
new Sentry.Replay(),
|
||||||
new Sentry.BrowserTracing(),
|
|
||||||
],
|
],
|
||||||
|
// Set tracesSampleRate to 1.0 to capture 100%
|
||||||
|
// of transactions for performance monitoring.
|
||||||
|
tracesSampleRate: 1.0,
|
||||||
});
|
});
|
||||||
Sentry.setTags({
|
Sentry.setTags({
|
||||||
appVersion: runtimeConfig.appVersion,
|
appVersion: runtimeConfig.appVersion,
|
||||||
|
|||||||
@@ -164,8 +164,7 @@ export const DetailPage = (): ReactElement => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a key to force rerender when page changed, to avoid some lifecycle issues.
|
return <DetailPageImpl />;
|
||||||
return <DetailPageImpl key={currentPageId} />;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const loader: LoaderFunction = async () => {
|
export const loader: LoaderFunction = async () => {
|
||||||
@@ -192,8 +191,9 @@ export const Component = () => {
|
|||||||
}
|
}
|
||||||
}, [params, setContentLayout, setCurrentPageId, setCurrentWorkspaceId]);
|
}, [params, setContentLayout, setCurrentPageId, setCurrentWorkspaceId]);
|
||||||
|
|
||||||
|
// Add a key to force rerender when page changed, to avoid error boundary persisting.
|
||||||
return (
|
return (
|
||||||
<AffineErrorBoundary>
|
<AffineErrorBoundary key={params.pageId}>
|
||||||
<DetailPage />
|
<DetailPage />
|
||||||
</AffineErrorBoundary>
|
</AffineErrorBoundary>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user