11import type { OnyxEntry } from 'react-native-onyx' ;
2+ import type { TupleToUnion } from 'type-fest' ;
23import type { Report } from '@src/types/onyx' ;
34
5+ type ValidReportKeys < T extends ReadonlyArray < keyof Report > > = T ;
6+
47/**
5- * Stable `Report` projection for the `ReportActionItem` subtree.
6- *
7- * `last*` heartbeat fields are deliberately excluded: they update on routine activity
8+ * Fields deliberately stripped from the projection. They update on routine activity
89 * (incoming/outgoing messages, read receipts) and would invalidate the projection on every
910 * chat heartbeat even though no item-subtree consumer reads them.
10- *
11+ */
12+ type ExcludedFields = ValidReportKeys <
13+ [
14+ 'lastMessageText' ,
15+ 'lastVisibleActionCreated' ,
16+ 'lastReadTime' ,
17+ 'lastReadSequenceNumber' ,
18+ 'lastMentionedTime' ,
19+ 'lastVisibleActionLastModified' ,
20+ 'lastMessageHtml' ,
21+ 'lastActorAccountID' ,
22+ 'lastActionType' ,
23+ ]
24+ > ;
25+
26+ /**
27+ * Stable `Report` projection for the `ReportActionItem` subtree.
1128 */
1229function stableReportSelector ( report : OnyxEntry < Report > ) {
1330 if ( ! report ?. reportID ) {
@@ -24,11 +41,6 @@ function stableReportSelector(report: OnyxEntry<Report>) {
2441 hasOutstandingChildTask : report . hasOutstandingChildTask ,
2542 isOwnPolicyExpenseChat : report . isOwnPolicyExpenseChat ,
2643 isPinned : report . isPinned ,
27- // lastMessageText: report.lastMessageText,
28- // lastVisibleActionCreated: report.lastVisibleActionCreated,
29- // lastReadTime: report.lastReadTime,
30- // lastReadSequenceNumber: report.lastReadSequenceNumber,
31- // lastMentionedTime: report.lastMentionedTime,
3244 policyAvatar : report . policyAvatar ,
3345 policyName : report . policyName ,
3446 oldPolicyName : report . oldPolicyName ,
@@ -52,10 +64,6 @@ function stableReportSelector(report: OnyxEntry<Report>) {
5264 // `undefined` keeps the projection stable through that reconciliation.
5365 // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
5466 managerID : report . managerID || undefined ,
55- // lastVisibleActionLastModified: report.lastVisibleActionLastModified,
56- // lastMessageHtml: report.lastMessageHtml,
57- // lastActorAccountID: report.lastActorAccountID,
58- // lastActionType: report.lastActionType,
5967 ownerAccountID : report . ownerAccountID ,
6068 participants : report . participants ,
6169 total : report . total ,
@@ -81,7 +89,7 @@ function stableReportSelector(report: OnyxEntry<Report>) {
8189 nextStep : report . nextStep ,
8290 pendingAction : report . pendingAction ,
8391 pendingFields : report . pendingFields ,
84- } ;
92+ } satisfies Omit < Report , TupleToUnion < ExcludedFields > > ;
8593}
8694
8795export default stableReportSelector ;
0 commit comments