Skip to content

Commit 495f991

Browse files
MelvinBotPujan92
andcommitted
Fix: use usePrevious for empty-to-value transition instead of reportLastReadTime dependency
Reverts the reportLastReadTime dependency array change that caused a regression (unread marker not showing for new messages). Now uses usePrevious to detect only the empty-to-non-empty transition of reportLastReadTime, preserving the original reportID-only dependency for the main effect. Co-authored-by: Pujan Shah <Pujan92@users.noreply.github.com>
1 parent d1d655e commit 495f991

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
@@ -248,6 +248,7 @@ function ReportActionsList({
248248
const prevSortedVisibleReportActionsObjects = usePrevious(sortedVisibleReportActionsObjects);
249249

250250
const reportLastReadTime = report.lastReadTime ?? '';
251+
const prevReportLastReadTime = usePrevious(reportLastReadTime);
251252

252253
/**
253254
* The timestamp for the unread marker.
@@ -259,15 +260,19 @@ function ReportActionsList({
259260
*/
260261
const [unreadMarkerTime, setUnreadMarkerTime] = useState(reportLastReadTime);
261262
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-
}
267263
setUnreadMarkerTime(reportLastReadTime);
268264

269265
// eslint-disable-next-line react-hooks/exhaustive-deps
270-
}, [report.reportID, reportLastReadTime]);
266+
}, [report.reportID]);
267+
268+
useEffect(() => {
269+
// Only update when lastReadTime transitions from empty to a real value
270+
// (e.g. after sign-in when report data loads for the first time).
271+
if (prevReportLastReadTime !== '' || reportLastReadTime === '') {
272+
return;
273+
}
274+
setUnreadMarkerTime(reportLastReadTime);
275+
}, [prevReportLastReadTime, reportLastReadTime]);
271276

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

0 commit comments

Comments
 (0)