From 5b87d90ffe44a99dc25115013f463b72c5afb0bd Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Wed, 12 Jul 2023 18:43:52 +0800 Subject: [PATCH] fix: first page id conflict (#3192) --- apps/web/src/adapters/local/index.tsx | 4 ++-- apps/web/src/components/page-detail-editor.tsx | 9 ++------- apps/web/src/layouts/workspace-layout.tsx | 11 +++++++---- packages/env/src/constant.ts | 3 +-- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/apps/web/src/adapters/local/index.tsx b/apps/web/src/adapters/local/index.tsx index d42d6125c2..e84cfc4758 100644 --- a/apps/web/src/adapters/local/index.tsx +++ b/apps/web/src/adapters/local/index.tsx @@ -1,7 +1,7 @@ import { DebugLogger } from '@affine/debug'; import { initEmptyPage, initPageWithPreloading } from '@affine/env/blocksuite'; import { - DEFAULT_HELLO_WORLD_PAGE_ID, + DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX, DEFAULT_WORKSPACE_NAME, PageNotFoundError, } from '@affine/env/constant'; @@ -42,7 +42,7 @@ export const LocalAdapter: WorkspaceAdapter = { ); blockSuiteWorkspace.meta.setName(DEFAULT_WORKSPACE_NAME); const page = blockSuiteWorkspace.createPage({ - id: DEFAULT_HELLO_WORLD_PAGE_ID, + id: `${blockSuiteWorkspace.id}-${DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX}`, }); if (runtimeConfig.enablePreloading) { initPageWithPreloading(page).catch(err => { diff --git a/apps/web/src/components/page-detail-editor.tsx b/apps/web/src/components/page-detail-editor.tsx index 773b39fc96..eaf6d44b76 100644 --- a/apps/web/src/components/page-detail-editor.tsx +++ b/apps/web/src/components/page-detail-editor.tsx @@ -1,9 +1,6 @@ import './page-detail-editor.css'; -import { - DEFAULT_HELLO_WORLD_PAGE_ID, - PageNotFoundError, -} from '@affine/env/constant'; +import { PageNotFoundError } from '@affine/env/constant'; import { rootBlockHubAtom } from '@affine/workspace/atom'; import type { EditorContainer } from '@blocksuite/editor'; import { assertExists } from '@blocksuite/global/utils'; @@ -61,9 +58,7 @@ const EditorWrapper = memo(function EditorWrapper({ ); const pageSettingAtom = pageSettingFamily(pageId); const pageSetting = useAtomValue(pageSettingAtom); - const currentMode = - pageSetting?.mode ?? - (DEFAULT_HELLO_WORLD_PAGE_ID === pageId ? 'edgeless' : 'page'); + const currentMode = pageSetting?.mode ?? 'page'; const setBlockHub = useSetAtom(rootBlockHubAtom); const [appSettings] = useAppSetting(); diff --git a/apps/web/src/layouts/workspace-layout.tsx b/apps/web/src/layouts/workspace-layout.tsx index ee6f7abb9b..52e00dba88 100644 --- a/apps/web/src/layouts/workspace-layout.tsx +++ b/apps/web/src/layouts/workspace-layout.tsx @@ -11,7 +11,10 @@ import { WorkspaceFallback, } from '@affine/component/workspace'; import { initEmptyPage, initPageWithPreloading } from '@affine/env/blocksuite'; -import { DEFAULT_HELLO_WORLD_PAGE_ID, isDesktop } from '@affine/env/constant'; +import { + DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX, + isDesktop, +} from '@affine/env/constant'; import { useAFFiNEI18N } from '@affine/i18n/hooks'; import { rootBlockHubAtom, @@ -188,7 +191,7 @@ export const WorkspaceLayoutInner: FC = ({ children }) => { // @ts-expect-error if (currentWorkspace.blockSuiteWorkspace.meta._proxy.isEmpty !== true) { // this is a new workspace, so we should redirect to the new page - const pageId = DEFAULT_HELLO_WORLD_PAGE_ID; + const pageId = `${currentWorkspace.blockSuiteWorkspace.id}-${DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX}`; if (currentWorkspace.blockSuiteWorkspace.getPage(pageId) === null) { const page = currentWorkspace.blockSuiteWorkspace.createPage({ id: pageId, @@ -218,11 +221,11 @@ export const WorkspaceLayoutInner: FC = ({ children }) => { useEffect(() => { const page = currentWorkspace.blockSuiteWorkspace.getPage( - DEFAULT_HELLO_WORLD_PAGE_ID + `${currentWorkspace.blockSuiteWorkspace.id}-${DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX}` ); if (page && page.meta.jumpOnce) { currentWorkspace.blockSuiteWorkspace.meta.setPageMeta( - DEFAULT_HELLO_WORLD_PAGE_ID, + `${currentWorkspace.blockSuiteWorkspace.id}-${DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX}`, { jumpOnce: false, } diff --git a/packages/env/src/constant.ts b/packages/env/src/constant.ts index 113cf72a96..cd1671e95e 100644 --- a/packages/env/src/constant.ts +++ b/packages/env/src/constant.ts @@ -14,10 +14,9 @@ export const isBrowser = typeof window !== 'undefined'; export const isServer = !isBrowser && typeof navigator === 'undefined'; export const isDesktop = isBrowser && !!window.appInfo?.electron; //#endregion -export const AFFINE_STORAGE_KEY = 'affine-local-storage-v2'; export const DEFAULT_WORKSPACE_NAME = 'Demo Workspace'; export const UNTITLED_WORKSPACE_NAME = 'Untitled'; -export const DEFAULT_HELLO_WORLD_PAGE_ID = 'hello-world'; +export const DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX = 'hello-world'; export const DEFAULT_SORT_KEY = 'updatedDate'; export const MessageCode = {