refactor: remove next/dynamic (#1901)

This commit is contained in:
Himself65 2023-04-12 11:08:50 -05:00 committed by GitHub
parent d9c4fc3a9e
commit 8bcef957fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 43 additions and 52 deletions

View File

@ -3,10 +3,9 @@ import type { Page } from '@blocksuite/store';
import { assertExists } from '@blocksuite/store';
import { useBlockSuiteWorkspacePageTitle } from '@toeverything/hooks/use-blocksuite-workspace-page-title';
import { useAtomValue, useSetAtom } from 'jotai';
import dynamic from 'next/dynamic';
import Head from 'next/head';
import type React from 'react';
import { useCallback } from 'react';
import { lazy, useCallback } from 'react';
import { currentEditorAtom, workspacePreferredModeAtom } from '../atoms';
import { usePageMeta } from '../hooks/use-page-meta';
@ -24,12 +23,10 @@ export type PageDetailEditorProps = {
header?: React.ReactNode;
};
const Editor = dynamic(
async () =>
(await import('./blocksuite/block-suite-editor')).BlockSuiteEditor,
{
ssr: false,
}
const Editor = lazy(() =>
import('./blocksuite/block-suite-editor').then(module => ({
default: module.BlockSuiteEditor,
}))
);
export const PageDetailEditor: React.FC<PageDetailEditorProps> = ({

View File

@ -2,8 +2,7 @@ import { MuiFade, Tooltip } from '@affine/component';
import { config } from '@affine/env';
import { useTranslation } from '@affine/i18n';
import { CloseIcon, NewIcon } from '@blocksuite/icons';
import dynamic from 'next/dynamic';
import { useState } from 'react';
import { lazy, useState } from 'react';
import { ShortcutsModal } from '../shortcuts-modal';
import { ContactIcon, HelpIcon, KeyboardIcon } from './Icons';
@ -13,14 +12,11 @@ import {
StyledIsland,
StyledTriggerWrapper,
} from './style';
const ContactModal = dynamic(
() =>
import('@affine/component/contact-modal').then(({ ContactModal }) => ({
default: ContactModal,
})),
{
ssr: true,
}
const ContactModal = lazy(() =>
import('@affine/component/contact-modal').then(({ ContactModal }) => ({
default: ContactModal,
}))
);
export type IslandItemNames = 'whatNew' | 'contact' | 'shortcuts';

View File

@ -7,11 +7,10 @@ import { WorkspaceFlavour } from '@affine/workspace/type';
import { assertExists, nanoid } from '@blocksuite/store';
import { NoSsr } from '@mui/material';
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
import dynamic from 'next/dynamic';
import Head from 'next/head';
import { useRouter } from 'next/router';
import type { FC, PropsWithChildren } from 'react';
import { Suspense, useCallback, useEffect } from 'react';
import { lazy, Suspense, useCallback, useEffect } from 'react';
import {
currentWorkspaceIdAtom,
@ -57,8 +56,10 @@ declare global {
var currentWorkspace: AllWorkspace;
}
const QuickSearchModal = dynamic(
() => import('../components/pure/quick-search-modal')
const QuickSearchModal = lazy(() =>
import('../components/pure/quick-search-modal').then(module => ({
default: module.QuickSearchModal,
}))
);
export const PublicQuickSearch: FC = () => {

View File

@ -1,11 +1,10 @@
import { ListSkeleton } from '@affine/component';
import { useAtomValue } from 'jotai';
import { useAtom } from 'jotai';
import dynamic from 'next/dynamic';
import Head from 'next/head';
import { useRouter } from 'next/router';
import type React from 'react';
import { Suspense } from 'react';
import { lazy, Suspense } from 'react';
import { openQuickSearchModalAtom } from '../atoms';
import {
@ -16,8 +15,10 @@ import { StyledTableContainer } from '../components/blocksuite/block-suite-page-
import { useRouterTitle } from '../hooks/use-router-title';
import { MainContainer, StyledPage } from './styles';
const QuickSearchModal = dynamic(
() => import('../components/pure/quick-search-modal')
const QuickSearchModal = lazy(() =>
import('../components/pure/quick-search-modal').then(module => ({
default: module.QuickSearchModal,
}))
);
export const PublicQuickSearch: React.FC = () => {

View File

@ -1,16 +1,15 @@
import { NoSsr } from '@mui/material';
import dynamic from 'next/dynamic';
import { useRouter } from 'next/router';
import { lazy } from 'react';
import { StyledPage, StyledWrapper } from '../../layouts/styles';
import type { NextPageWithLayout } from '../../shared';
import { initPage } from '../../utils/blocksuite';
const Editor = dynamic(
() => import('../../components/__debug__/client/Editor'),
{
ssr: false,
}
const Editor = lazy(() =>
import('../../components/__debug__/client/Editor').then(module => ({
default: module.default,
}))
);
const InitPagePage: NextPageWithLayout = () => {

View File

@ -11,14 +11,12 @@ import {
} from '@affine/workspace/affine/login';
import { useAtom } from 'jotai';
import type { NextPage } from 'next';
import dynamic from 'next/dynamic';
import { useMemo } from 'react';
import { lazy, useMemo } from 'react';
import { toast } from '../../utils';
const Viewer = dynamic(
() => import('@rich-data/viewer').then(m => ({ default: m.JsonViewer })),
{ ssr: false }
const Viewer = lazy(() =>
import('@rich-data/viewer').then(m => ({ default: m.JsonViewer }))
);
import { useTheme } from 'next-themes';

View File

@ -3,10 +3,9 @@ import { SearchIcon } from '@blocksuite/icons';
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-blocksuite-workspace-avatar-url';
import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-blocksuite-workspace-name';
import { useAtomValue, useSetAtom } from 'jotai';
import dynamic from 'next/dynamic';
import { useRouter } from 'next/router';
import type React from 'react';
import { Suspense, useCallback, useEffect } from 'react';
import { lazy, Suspense, useCallback, useEffect } from 'react';
import { currentWorkspaceIdAtom, openQuickSearchModalAtom } from '../../atoms';
import {
@ -21,10 +20,10 @@ import { PublicWorkspaceLayout } from '../../layouts/public-workspace-layout';
import type { NextPageWithLayout } from '../../shared';
import { NavContainer, StyledBreadcrumbs } from './[workspaceId]/[pageId]';
const BlockSuitePublicPageList = dynamic(
async () =>
(await import('../../components/blocksuite/block-suite-page-list'))
.BlockSuitePublicPageList
const BlockSuitePublicPageList = lazy(() =>
import('../../components/blocksuite/block-suite-page-list').then(module => ({
default: module.BlockSuitePublicPageList,
}))
);
const ListPageInner: React.FC<{

View File

@ -1,10 +1,9 @@
import { jotaiWorkspacesAtom } from '@affine/workspace/atom';
import { arrayMove } from '@dnd-kit/sortable';
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
import dynamic from 'next/dynamic';
import { useRouter } from 'next/router';
import type React from 'react';
import { useCallback, useTransition } from 'react';
import { lazy, useCallback, useTransition } from 'react';
import {
currentWorkspaceIdAtom,
@ -19,14 +18,15 @@ import { useRouterHelper } from '../hooks/use-router-helper';
import { useWorkspaces, useWorkspacesHelper } from '../hooks/use-workspaces';
import { WorkspaceSubPath } from '../shared';
const WorkspaceListModal = dynamic(
async () =>
(await import('../components/pure/workspace-list-modal')).WorkspaceListModal
const WorkspaceListModal = lazy(() =>
import('../components/pure/workspace-list-modal').then(module => ({
default: module.WorkspaceListModal,
}))
);
const CreateWorkspaceModal = dynamic(
async () =>
(await import('../components/pure/create-workspace-modal'))
.CreateWorkspaceModal
const CreateWorkspaceModal = lazy(() =>
import('../components/pure/create-workspace-modal').then(module => ({
default: module.CreateWorkspaceModal,
}))
);
export function Modals() {