mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-15 05:37:32 +00:00
fix(core): loadDoc tracking events not tracking correctly (#11960)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Improved the reliability and clarity of loading state and error tracking in the editor, resulting in more accurate feedback during document loading. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
fontStyleOptions,
|
fontStyleOptions,
|
||||||
} from '@affine/core/modules/editor-setting';
|
} from '@affine/core/modules/editor-setting';
|
||||||
import { FeatureFlagService } from '@affine/core/modules/feature-flag';
|
import { FeatureFlagService } from '@affine/core/modules/feature-flag';
|
||||||
|
import { WorkspaceService } from '@affine/core/modules/workspace';
|
||||||
import track from '@affine/track';
|
import track from '@affine/track';
|
||||||
import { appendParagraphCommand } from '@blocksuite/affine/blocks/paragraph';
|
import { appendParagraphCommand } from '@blocksuite/affine/blocks/paragraph';
|
||||||
import type { DocTitle } from '@blocksuite/affine/fragments/doc-title';
|
import type { DocTitle } from '@blocksuite/affine/fragments/doc-title';
|
||||||
@@ -272,6 +273,7 @@ export const BlockSuiteEditor = (props: EditorProps) => {
|
|||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [longerLoading, setLongerLoading] = useState(false);
|
const [longerLoading, setLongerLoading] = useState(false);
|
||||||
const [loadStartTime] = useState(Date.now());
|
const [loadStartTime] = useState(Date.now());
|
||||||
|
const workspaceService = useService(WorkspaceService);
|
||||||
|
|
||||||
const editorSetting = useService(EditorSettingService).editorSetting;
|
const editorSetting = useService(EditorSettingService).editorSetting;
|
||||||
const settings = useLiveData(
|
const settings = useLiveData(
|
||||||
@@ -300,38 +302,60 @@ export const BlockSuiteEditor = (props: EditorProps) => {
|
|||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const disposable = props.page.slots.rootAdded.subscribe(() => {
|
||||||
|
disposable.unsubscribe();
|
||||||
|
setIsLoading(false);
|
||||||
|
setLongerLoading(false);
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
disposable.unsubscribe();
|
||||||
|
};
|
||||||
|
}, [loadStartTime, props.page]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
setLongerLoading(true);
|
if (isLoading) {
|
||||||
|
setLongerLoading(true);
|
||||||
|
}
|
||||||
}, 20 * 1000);
|
}, 20 * 1000);
|
||||||
const reportErrorTimer = setTimeout(() => {
|
const reportErrorTimer = setTimeout(() => {
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
track.doc.$.$.loadDoc({
|
track.doc.$.$.loadDoc({
|
||||||
workspaceId: props.page.workspace.id,
|
workspaceId: props.page.workspace.id,
|
||||||
docId: props.page.id,
|
docId: props.page.id,
|
||||||
// time cost in ms
|
|
||||||
time: Date.now() - loadStartTime,
|
time: Date.now() - loadStartTime,
|
||||||
success: false,
|
success: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, 60 * 1000);
|
}, 60 * 1000);
|
||||||
const disposable = props.page.slots.rootAdded.subscribe(() => {
|
|
||||||
disposable.unsubscribe();
|
|
||||||
track.doc.$.$.loadDoc({
|
|
||||||
workspaceId: props.page.workspace.id,
|
|
||||||
docId: props.page.id,
|
|
||||||
time: Date.now() - loadStartTime,
|
|
||||||
success: true,
|
|
||||||
});
|
|
||||||
setIsLoading(false);
|
|
||||||
setLongerLoading(false);
|
|
||||||
});
|
|
||||||
return () => {
|
return () => {
|
||||||
disposable.unsubscribe();
|
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
clearTimeout(reportErrorTimer);
|
clearTimeout(reportErrorTimer);
|
||||||
};
|
};
|
||||||
}, [isLoading, loadStartTime, props.page]);
|
}, [isLoading, loadStartTime, props.page]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
workspaceService.workspace.engine.doc
|
||||||
|
.waitForDocLoaded(props.page.id)
|
||||||
|
.then(() => {
|
||||||
|
track.doc.$.$.loadDoc({
|
||||||
|
workspaceId: props.page.workspace.id,
|
||||||
|
docId: props.page.id,
|
||||||
|
time: Date.now() - loadStartTime,
|
||||||
|
success: true,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
track.doc.$.$.loadDoc({
|
||||||
|
workspaceId: props.page.workspace.id,
|
||||||
|
docId: props.page.id,
|
||||||
|
time: Date.now() - loadStartTime,
|
||||||
|
success: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, [loadStartTime, props.page, workspaceService]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slot style={{ '--affine-font-family': fontFamily } as CSSProperties}>
|
<Slot style={{ '--affine-font-family': fontFamily } as CSSProperties}>
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
|
|||||||
Reference in New Issue
Block a user