Skip to content

Commit ecb4234

Browse files
authored
fix: rendering research updates on navigation (#4054)
1 parent 2b8004e commit ecb4234

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/pages/Research/Content/ResearchArticle.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from 'react'
1+
import { useEffect, useMemo, useState } from 'react'
22
import { Link, useLocation } from '@remix-run/react'
33
import { observer } from 'mobx-react'
44
import {
@@ -39,7 +39,6 @@ type ResearchArticleProps = {
3939

4040
const ResearchArticle = observer(
4141
({ research, publicUpdates }: ResearchArticleProps) => {
42-
const [updates, setUpdates] = useState(publicUpdates)
4342
const location = useLocation()
4443
const researchStore = useResearchStore()
4544
const { aggregationsStore } = useCommonStores().stores
@@ -53,22 +52,18 @@ const ResearchArticle = observer(
5352
research.votedUsefulBy?.length || 0,
5453
)
5554

56-
useEffect(() => {
55+
const updates = useMemo(() => {
5756
// Only public updates (non draft) are server-side rendered.
5857
// But we still need to display the draft updates when the currentUser is the author/contributor.
5958
// Since the current user is only loaded client-side, we need to check and re-set the updates.
6059
if (!researchStore.activeUser) {
61-
return
60+
return publicUpdates
6261
}
6362

64-
const authorUpdates = research.updates?.filter((update) =>
63+
return research.updates?.filter((update) =>
6564
researchUpdateStatusFilter(research, update, researchStore.activeUser),
6665
)
67-
68-
if (authorUpdates.length !== updates.length) {
69-
setUpdates(authorUpdates)
70-
}
71-
}, [researchStore.activeUser])
66+
}, [researchStore.activeUser, publicUpdates, research.updates])
7267

7368
useEffect(() => {
7469
// This could be improved if we can load the user profile server-side

0 commit comments

Comments
 (0)