Skip to content

Commit 92f35fb

Browse files
MelvinBotPujan92
andcommitted
Fix: split unread marker effect to avoid clearing marker on readNewestAction
The single effect with reportLastReadTime in the dependency array caused unreadMarkerTime to update whenever readNewestAction marked messages as read, immediately clearing the unread indicator. Split into two effects: one for report switches (original behavior) and one that only fires when reportLastReadTime transitions from empty to a real value (sign-in case). Co-authored-by: Pujan Shah <Pujan92@users.noreply.github.com>
1 parent d1d655e commit 92f35fb

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/pages/inbox/report/ReportActionsList.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,20 @@ function ReportActionsList({
259259
*/
260260
const [unreadMarkerTime, setUnreadMarkerTime] = useState(reportLastReadTime);
261261
useEffect(() => {
262-
// When lastReadTime is empty (e.g. data hasn't loaded yet after sign-in),
263-
// skip the update so we don't place the marker at the wrong position.
264-
if (reportLastReadTime === '') {
265-
return;
266-
}
267262
setUnreadMarkerTime(reportLastReadTime);
268263

269264
// eslint-disable-next-line react-hooks/exhaustive-deps
270-
}, [report.reportID, reportLastReadTime]);
265+
}, [report.reportID]);
266+
267+
// When lastReadTime transitions from empty to a real value (e.g., data hasn't
268+
// loaded yet after sign-in), update the marker so it uses the fresh value
269+
// instead of the empty string from initial mount.
270+
useEffect(() => {
271+
if (reportLastReadTime !== '' && unreadMarkerTime === '') {
272+
setUnreadMarkerTime(reportLastReadTime);
273+
}
274+
// eslint-disable-next-line react-hooks/exhaustive-deps
275+
}, [reportLastReadTime]);
271276

272277
const prevUnreadMarkerReportActionID = useRef<string | null>(null);
273278

0 commit comments

Comments
 (0)