fix(core): fix journal missing after refresh (#6022)
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
import { DebugLogger } from '@affine/debug';
|
import { DebugLogger } from '@affine/debug';
|
||||||
import { Slot } from '@blocksuite/global/utils';
|
import { Slot } from '@blocksuite/global/utils';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
import type { Doc } from 'yjs';
|
import type { Doc } from 'yjs';
|
||||||
|
|
||||||
import { createIdentifier } from '../../../di';
|
import { createIdentifier } from '../../../di';
|
||||||
|
import { LiveData } from '../../../livedata';
|
||||||
import { SharedPriorityTarget } from '../../../utils/async-queue';
|
import { SharedPriorityTarget } from '../../../utils/async-queue';
|
||||||
import { MANUALLY_STOP, throwIfAborted } from '../../../utils/throw-if-aborted';
|
import { MANUALLY_STOP, throwIfAborted } from '../../../utils/throw-if-aborted';
|
||||||
import { SyncEngineStep, SyncPeerStep } from './consts';
|
import { SyncEngineStep, SyncPeerStep } from './consts';
|
||||||
@@ -65,6 +67,21 @@ export class SyncEngine {
|
|||||||
this._status = s;
|
this._status = s;
|
||||||
this.onStatusChange.emit(s);
|
this.onStatusChange.emit(s);
|
||||||
}
|
}
|
||||||
|
isRootDocLoaded = LiveData.from(
|
||||||
|
new Observable(observer => {
|
||||||
|
observer.next(
|
||||||
|
this.status.local
|
||||||
|
? this.status.local.step > SyncPeerStep.LoadingRootDoc
|
||||||
|
: false
|
||||||
|
);
|
||||||
|
this.onStatusChange.on(status => {
|
||||||
|
observer.next(
|
||||||
|
status.local ? status.local.step > SyncPeerStep.LoadingRootDoc : false
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
priorityTarget = new SharedPriorityTarget();
|
priorityTarget = new SharedPriorityTarget();
|
||||||
|
|
||||||
|
|||||||
@@ -10,13 +10,7 @@ import {
|
|||||||
useServiceOptional,
|
useServiceOptional,
|
||||||
} from '@toeverything/infra/di';
|
} from '@toeverything/infra/di';
|
||||||
import { useLiveData } from '@toeverything/infra/livedata';
|
import { useLiveData } from '@toeverything/infra/livedata';
|
||||||
import {
|
import { type ReactElement, Suspense, useEffect, useMemo } from 'react';
|
||||||
type ReactElement,
|
|
||||||
Suspense,
|
|
||||||
useEffect,
|
|
||||||
useMemo,
|
|
||||||
useState,
|
|
||||||
} from 'react';
|
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
|
|
||||||
import { AffineErrorBoundary } from '../../components/affine/affine-error-boundary';
|
import { AffineErrorBoundary } from '../../components/affine/affine-error-boundary';
|
||||||
@@ -80,34 +74,15 @@ export const Component = (): ReactElement => {
|
|||||||
|
|
||||||
const currentWorkspace = useServiceOptional(Workspace);
|
const currentWorkspace = useServiceOptional(Workspace);
|
||||||
|
|
||||||
const [workspaceIsLoading, setWorkspaceIsLoading] = useState(true);
|
// avoid doing operation, before workspace is loaded
|
||||||
|
const isRootDocLoaded = useLiveData(workspace?.engine.sync.isRootDocLoaded);
|
||||||
// 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]);
|
|
||||||
|
|
||||||
// if listLoading is false, we can show 404 page, otherwise we should show loading page.
|
// if listLoading is false, we can show 404 page, otherwise we should show loading page.
|
||||||
if (listLoading === false && meta === undefined) {
|
if (listLoading === false && meta === undefined) {
|
||||||
return <PageNotFound />;
|
return <PageNotFound />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!currentWorkspace || workspaceIsLoading) {
|
if (!currentWorkspace || !isRootDocLoaded) {
|
||||||
return <WorkspaceFallback key="workspaceLoading" />;
|
return <WorkspaceFallback key="workspaceLoading" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user