fix(core): fix journal missing after refresh (#6022)

This commit is contained in:
EYHN
2024-03-05 11:42:09 +00:00
parent c1afdb9bd6
commit 5d8dea084c
2 changed files with 21 additions and 29 deletions

View File

@@ -10,13 +10,7 @@ import {
useServiceOptional,
} from '@toeverything/infra/di';
import { useLiveData } from '@toeverything/infra/livedata';
import {
type ReactElement,
Suspense,
useEffect,
useMemo,
useState,
} from 'react';
import { type ReactElement, Suspense, useEffect, useMemo } from 'react';
import { useParams } from 'react-router-dom';
import { AffineErrorBoundary } from '../../components/affine/affine-error-boundary';
@@ -80,34 +74,15 @@ export const Component = (): ReactElement => {
const currentWorkspace = useServiceOptional(Workspace);
const [workspaceIsLoading, setWorkspaceIsLoading] = useState(true);
// hotfix: avoid doing operation, before workspace is loaded
useEffect(() => {
if (!workspace) {
setWorkspaceIsLoading(true);
return;
}
const metaYMap = workspace.blockSuiteWorkspace.doc.getMap('meta');
const handleYMapChanged = () => {
setWorkspaceIsLoading(metaYMap.size === 0);
};
handleYMapChanged();
metaYMap.observe(handleYMapChanged);
return () => {
metaYMap.unobserve(handleYMapChanged);
};
}, [workspace]);
// avoid doing operation, before workspace is loaded
const isRootDocLoaded = useLiveData(workspace?.engine.sync.isRootDocLoaded);
// if listLoading is false, we can show 404 page, otherwise we should show loading page.
if (listLoading === false && meta === undefined) {
return <PageNotFound />;
}
if (!currentWorkspace || workspaceIsLoading) {
if (!currentWorkspace || !isRootDocLoaded) {
return <WorkspaceFallback key="workspaceLoading" />;
}