Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 6a18b5b

Browse files
authored
fix(snow-tab): bad performance when switch with post thread (#1247)
* chore: wip * chore(deploy): bump version to v2.1.4 * fix(slow-tab): use dynamic loader to avoid slow list render * chore(deploy): bump version to v2.1.5
1 parent b10c3a8 commit 6a18b5b

File tree

13 files changed

+106
-41
lines changed

13 files changed

+106
-41
lines changed

config/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"//--- contact configs ---//": "",
6060
"EMAIL_SUPPORT": "coderplanets@outlook.com",
6161
"// GRAPHQL_ENDPOINT": "https://api.coderplanets.com/graphiql",
62-
"BUILD_VERSION": "v2.1.3",
62+
"BUILD_VERSION": "v2.1.5",
6363
"// 1000 * 60 * 10 = 10 mins": "",
6464
"SSR_CACHE_TIME": 60000
6565
}

deploy/production/web.tar.gz

867 Bytes
Binary file not shown.

src/containers/content/CommunityContent/ThreadContent.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ type TProps = {
1414
}
1515

1616
const ThreadContent: FC<TProps> = ({ thread }) => {
17-
console.log('# thread: ', thread)
18-
1917
switch (thread) {
20-
// case THREAD.REPO:
21-
// return <ReposThread />
2218
case THREAD.KANBAN: {
2319
return <WipThread title="看板" />
2420
}

src/containers/content/CommunityContent/logic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ const tabOnChange = (activeThread: TThread): void => {
3333
const subPath =
3434
activeThread !== ARTICLE_THREAD.POST ? plural(activeThread) : ''
3535

36-
store.markRoute({ mainPath, subPath })
3736
// store.setViewing({ activeThread })
3837
store.setCurThread(activeThread)
38+
store.markRoute({ mainPath, subPath })
3939
}
4040

4141
// ###############################

src/containers/thread/ArticlesThread/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const ArticlesThreadContainer: FC<TProps> = ({ articlesThread: store }) => {
6161
? MobileCardsMainWrapper
6262
: MainWrapper
6363

64-
console.log('# got pagedArticlesData: ', pagedArticlesData)
64+
log('# got pagedArticlesData: ', pagedArticlesData)
6565

6666
return (
6767
<Wrapper>

src/containers/thread/ArticlesThread/logic.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ const DataSolver = [
113113
{
114114
match: asyncRes(EVENT.ARTICLE_THREAD_CHANGE),
115115
action: () => {
116-
log('EVENT.ARTICLE_THREAD_CHANGE')
117116
// 之前如果请求过,那么 GraphQL 会被缓存,不必重复请求
118117
if (store.isEmpty) loadArticles()
119118
},
@@ -169,9 +168,10 @@ const ErrSolver = [
169168
// ###############################
170169
// init & uninit
171170
// ###############################
172-
export const useInit = (_store: TStore): void =>
171+
export const useInit = (_store: TStore): void => {
173172
useEffect(() => {
174173
store = _store
174+
store.afterInitLoading()
175175
sub$ = sr71$.data().subscribe($solver(DataSolver, ErrSolver))
176176

177177
// if (store.isEmpty) loadArticles()
@@ -183,3 +183,4 @@ export const useInit = (_store: TStore): void =>
183183
sub$.unsubscribe()
184184
}
185185
}, [_store])
186+
}

src/containers/thread/ArticlesThread/store.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const ArticlesThread = T.model('ArticlesThread', {
4242
filters: T.optional(ArticlesFilter, {}),
4343
resState: T.optional(
4444
T.enumeration('resState', values(TYPE.RES_STATE)),
45-
TYPE.RES_STATE.DONE,
45+
TYPE.RES_STATE.LOADING,
4646
),
4747
})
4848
.views((self) => ({
@@ -109,9 +109,21 @@ const ArticlesThread = T.model('ArticlesThread', {
109109
},
110110
}))
111111
.actions((self) => ({
112+
afterInitLoading(): void {
113+
const slf = self as TStore
114+
const { totalCount } = slf.pagedArticlesData
115+
116+
console.log('totalCount -> ', totalCount)
117+
118+
if (totalCount === 0) {
119+
self.resState = TYPE.RES_STATE.EMPTY
120+
} else {
121+
self.resState = TYPE.RES_STATE.DONE
122+
}
123+
},
112124
// the args pass to server when load articles
113125
getLoadArgs(page = 1): Record<string, unknown> {
114-
// self.resState = TYPE.RES_STATE.LOADING
126+
self.resState = TYPE.RES_STATE.LOADING
115127

116128
const root = getParent(self) as TRootStore
117129
return root.getPagedArticleArgs(page, self.filtersData)
@@ -121,9 +133,9 @@ const ArticlesThread = T.model('ArticlesThread', {
121133
const pagedData = values(res)[0] as TPagedArticles
122134

123135
if (pagedData.totalCount === 0) {
124-
// slf.resState = TYPE.RES_STATE.EMPTY
136+
slf.resState = TYPE.RES_STATE.EMPTY
125137
} else {
126-
// slf.resState = TYPE.RES_STATE.DONE
138+
slf.resState = TYPE.RES_STATE.DONE
127139
}
128140

129141
slf.mark(res)

src/widgets/PagedArticles/ArticleList.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ const ArticleList = (props) => {
2020
return <LavaLampLoading top={20} left={30} />
2121
}
2222

23-
if (resState === TYPE.RES_STATE.EMPTY) {
23+
// 加入 length 的判断是因为 Graphql 客户端如果有缓存的话会导致 RES_STATE 没有更新(因为没有请求)
24+
if (
25+
(resState === TYPE.RES_STATE.EMPTY && entries.length === 0) ||
26+
(resState === TYPE.RES_STATE.DONE && entries.length === 0)
27+
) {
2428
return <EmptyThread thread={thread} />
2529
}
2630

@@ -59,6 +63,7 @@ const ArticleList = (props) => {
5963

6064
default:
6165
// common post
66+
// return <h3>PostItems</h3>
6267
return (
6368
<Fragment>
6469
{entries.map((entry) => (

src/widgets/PagedArticles/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,10 @@ const PagedArticles: FC<TProps> = ({
5959
{...pagi}
6060
onChange={(page) => send(EVENT.REFRESH_ARTICLES, { page })}
6161
margin={{ bottom: '60px', top: '60px' }}
62-
>
63-
{/* <CommunityRecommends /> */}
64-
</Pagi>
62+
/>
6563
</Fragment>
6664
)
6765
}
6866

67+
/* <CommunityRecommends /> */
6968
export default memo(PagedArticles)

src/widgets/PostItem/DesktopView/Body.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { FC, Fragment } from 'react'
2+
import dynamic from 'next/dynamic'
23
import TimeAgo from 'timeago-react'
34

45
import Link from 'next/link'
@@ -9,11 +10,11 @@ import { send, changeToCommunity } from '@/utils/helper'
910

1011
import { SpaceGrow } from '@/widgets/Common'
1112
import DigestSentence from '@/widgets/DigestSentence'
12-
import CommunityCard from '@/widgets/Cards/CommunityCard'
13-
import UserCard from '@/widgets/Cards/UserCard'
13+
// import CommunityCard from '@/widgets/Cards/CommunityCard'
14+
// import UserCard from '@/widgets/Cards/UserCard'
1415
import Tooltip from '@/widgets/Tooltip'
1516

16-
import ActiveBadge from './ActiveBadge'
17+
// import ActiveBadge from './ActiveBadge'
1718

1819
import {
1920
Wrapper,
@@ -28,6 +29,18 @@ import {
2829
ViewsIcon,
2930
} from '../styles/desktop_view/body'
3031

32+
const CommunityCard = dynamic(() => import('@/widgets/Cards/CommunityCard'), {
33+
ssr: false,
34+
})
35+
36+
const UserCard = dynamic(() => import('@/widgets/Cards/UserCard'), {
37+
ssr: false,
38+
})
39+
40+
const ActiveBadge = dynamic(() => import('./ActiveBadge'), {
41+
ssr: false,
42+
})
43+
3144
type TProps = {
3245
curCommunity: TCommunity | null
3346
item: TPost

0 commit comments

Comments
 (0)