11import type { AxiosError } from 'axios'
22import dayjs from 'dayjs'
33import type { NextPage } from 'next'
4- import dynamic from 'next/dynamic'
54import { useRouter } from 'next/router'
6- import React , { createElement , memo , useEffect , useMemo , useRef } from 'react'
5+ import React , {
6+ createElement ,
7+ lazy ,
8+ memo ,
9+ useEffect ,
10+ useMemo ,
11+ useRef ,
12+ } from 'react'
713import { message } from 'react-message-popup'
814import useUpdate from 'react-use/lib/useUpdate'
915
@@ -13,6 +19,7 @@ import { RequestError } from '@mx-space/api-client'
1319import { noteCollection , useNoteCollection } from '~/atoms/collections/note'
1420import type { ModelWithDeleted } from '~/atoms/collections/utils/base'
1521import { useIsLogged , useUserStore } from '~/atoms/user'
22+ import { Suspense } from '~/components/app/Suspense'
1623import { wrapperNextPage } from '~/components/app/WrapperNextPage'
1724import { NoteFooterNavigationBarForMobile } from '~/components/in-page/Note/NoteFooterNavigation'
1825import { NoteMarkdownRender } from '~/components/in-page/Note/NoteMarkdownRender'
@@ -44,26 +51,28 @@ import { noop } from '~/utils/utils'
4451import { Seo } from '../../components/app/Seo'
4552import { isDev } from '../../utils/env'
4653
47- const NoteTopic = dynamic ( ( ) =>
48- import ( '~/components/in-page/Note/NoteTopic' ) . then ( ( mo ) => mo . NoteTopic ) ,
54+ const NoteTopic = lazy ( ( ) =>
55+ import ( '~/components/in-page/Note/NoteTopic' ) . then ( ( mo ) => ( {
56+ default : mo . NoteTopic ,
57+ } ) ) ,
4958)
5059
51- const CommentLazy = dynamic ( ( ) =>
52- import ( '~/components/widgets/Comment' ) . then ( ( mo ) => mo . CommentLazy ) ,
60+ const CommentLazy = lazy ( ( ) =>
61+ import ( '~/components/widgets/Comment' ) . then ( ( mo ) => ( {
62+ default : mo . CommentLazy ,
63+ } ) ) ,
5364)
5465
55- const ArticleLayout = dynamic ( ( ) =>
56- import ( '~/components/layouts/ArticleLayout' ) . then ( ( mo ) => mo . ArticleLayout ) ,
66+ const ArticleLayout = lazy ( ( ) =>
67+ import ( '~/components/layouts/ArticleLayout' ) . then ( ( mo ) => ( {
68+ default : mo . ArticleLayout ,
69+ } ) ) ,
5770)
5871
59- const NoteFooterActionBar = dynamic (
60- ( ) =>
61- import ( '~/components/in-page/Note/NoteActionBar' ) . then (
62- ( mo ) => mo . NoteFooterActionBar ,
63- ) ,
64- {
65- ssr : false ,
66- } ,
72+ const NoteFooterActionBar = lazy ( ( ) =>
73+ import ( '~/components/in-page/Note/NoteActionBar' ) . then ( ( mo ) => ( {
74+ default : mo . NoteFooterActionBar ,
75+ } ) ) ,
6776)
6877
6978const useUpdateNote = ( note : ModelWithDeleted < NoteModel > ) => {
@@ -245,25 +254,36 @@ const NoteView: React.FC<{ id: string }> = memo((props) => {
245254 </ ImageSizeMetaContext . Provider >
246255 ) }
247256 < div className = "pb-8" />
248- { note . topic && < NoteTopic noteId = { props . id } topic = { note . topic } /> }
257+ { note . topic && (
258+ < Suspense >
259+ < NoteTopic noteId = { props . id } topic = { note . topic } />
260+ </ Suspense >
261+ ) }
249262
250263 < NoteFooterNavigationBarForMobile id = { props . id } />
251264 < div className = "pb-4" />
252265 < SubscribeBell defaultType = "note_c" />
253266 < XLogInfoForNote id = { props . id } />
254- < NoteFooterActionBar id = { props . id } />
267+ < Suspense >
268+ < NoteFooterActionBar id = { props . id } />
269+ </ Suspense >
255270 </ NoteLayout >
271+
256272 { ! isSecret && (
257- < ArticleLayout
258- className = "!min-h-[unset] !pt-0"
259- key = { `comments-${ props . id } ` }
260- >
261- < CommentLazy
262- id = { id }
263- key = { id }
264- allowComment = { note . allowComment ?? true }
265- />
266- </ ArticleLayout >
273+ < Suspense >
274+ < ArticleLayout
275+ className = "!min-h-[unset] !pt-0"
276+ key = { `comments-${ props . id } ` }
277+ >
278+ < Suspense >
279+ < CommentLazy
280+ id = { id }
281+ key = { id }
282+ allowComment = { note . allowComment ?? true }
283+ />
284+ </ Suspense >
285+ </ ArticleLayout >
286+ </ Suspense >
267287 ) }
268288
269289 < SearchFAB />
0 commit comments