@@ -18,7 +18,7 @@ import type {Report} from '@src/types/onyx';
1818import { defaultWideRHPActionsContextValue , defaultWideRHPStateContextValue } from './default' ;
1919import getIsRHPDisplayedBelow from './getIsRHPDisplayedBelow' ;
2020import getVisibleRHPKeys from './getVisibleRHPRouteKeys' ;
21- import type { WideRHPActionsContextType , WideRHPStateContextType } from './types' ;
21+ import type { RHPWidth , RHPWidthHint , WideRHPActionsContextType , WideRHPStateContextType } from './types' ;
2222import useShouldRenderOverlay from './useShouldRenderOverlay' ;
2323
2424// 0 is folded/hidden, 1 is expanded/shown
@@ -74,7 +74,7 @@ function showWideRHPRoute(route: NavigationRoute, setAllRHPRouteKeys: React.Disp
7474// Function to remove a Wide/Super Wide RHP route key to the array including wide/super wide RHP route keys
7575function removeWideRHPRoute ( route : NavigationRoute , setAllRHPRouteKeys : React . Dispatch < React . SetStateAction < string [ ] > > ) {
7676 if ( ! route . key ) {
77- console . error ( `The route passed to removeWideRHPRouteKey should have the "key" property defined.` ) ;
77+ console . error ( `The route passed to removeWideRHPRoute should have the "key" property defined.` ) ;
7878 return ;
7979 }
8080
@@ -106,9 +106,8 @@ function WideRHPContextProvider({children}: React.PropsWithChildren) {
106106 const [ allSuperWideRHPRouteKeys , setAllSuperWideRHPRouteKeys ] = useState < string [ ] > ( [ ] ) ;
107107 const [ superWideRHPRouteKeys , setSuperWideRHPRouteKeys ] = useState < string [ ] > ( [ ] ) ;
108108
109- // Report IDs that should be displayed in Wide/Super Wide RHP
110- const [ expenseReportIDs , setExpenseReportIDs ] = useState < Set < string > > ( new Set ( ) ) ;
111- const [ multiTransactionExpenseReportIDs , setMultiTransactionExpenseReportIDs ] = useState < Set < string > > ( new Set ( ) ) ;
109+ // A reportID maps to at most one hint, making "wide vs super-wide" structurally mutually exclusive.
110+ const [ reportRHPWidthHints , setReportRHPWidthHints ] = useState < Map < string , RHPWidthHint > > ( ( ) => new Map ( ) ) ;
112111
113112 const [ allReports ] = useOnyx ( ONYXKEYS . COLLECTION . REPORT , { selector : expenseReportSelector } ) ;
114113
@@ -186,96 +185,77 @@ function WideRHPContextProvider({children}: React.PropsWithChildren) {
186185 const shouldRenderTertiaryOverlay = useShouldRenderOverlay ( isRHPFocused && isWideRHPBelow && isSuperWideRHPBelow , thirdOverlayProgress ) ;
187186
188187 /**
189- * Removes a route from the super wide RHP route keys list, disabling wide RHP display for that route .
188+ * Removes the route from both wide and super- wide sets. Used on screen unmount .
190189 */
191- const removeSuperWideRHPRouteKey = ( route : NavigationRoute ) => removeWideRHPRoute ( route , setAllSuperWideRHPRouteKeys ) ;
192-
193- /**
194- * Removes a route from the wide RHP route keys list, disabling wide RHP display for that route.
195- */
196- const removeWideRHPRouteKey = ( route : NavigationRoute ) => removeWideRHPRoute ( route , setAllWideRHPRouteKeys ) ;
197-
198- /**
199- * Adds a route to the wide RHP route keys list, enabling wide RHP display for that route.
200- */
201- const showWideRHPVersion = ( route : NavigationRoute ) => {
202- removeSuperWideRHPRouteKey ( route ) ;
203- showWideRHPRoute ( route , setAllWideRHPRouteKeys ) ;
190+ const removeRHPRouteKey = ( route : NavigationRoute ) => {
191+ removeWideRHPRoute ( route , setAllSuperWideRHPRouteKeys ) ;
192+ removeWideRHPRoute ( route , setAllWideRHPRouteKeys ) ;
204193 } ;
205194
206195 /**
207- * Adds a route to the super wide RHP route keys list, enabling super wide RHP display for that route.
196+ * Single entry point for setting a route's RHP width. Registrations are mutually exclusive — the
197+ * route lives in at most one of {wide, super-wide} sets at any time (or neither, for 'narrow').
208198 */
209- const showSuperWideRHPVersion = ( route : NavigationRoute ) => {
210- removeWideRHPRouteKey ( route ) ;
211- showWideRHPRoute ( route , setAllSuperWideRHPRouteKeys ) ;
212- } ;
213-
214- /**
215- * Marks a report ID as an expense report, adding it to the expense reports set.
216- * This enables optimistic wide RHP display for expense reports.
217- * It helps us open expense as wide, before it fully loads.
218- */
219- const markReportIDAsExpense = ( reportID ?: string ) => {
220- if ( ! reportID ) {
199+ const setRHPWidth = ( route : NavigationRoute , width : RHPWidth ) => {
200+ if ( width === 'super-wide' ) {
201+ removeWideRHPRoute ( route , setAllWideRHPRouteKeys ) ;
202+ showWideRHPRoute ( route , setAllSuperWideRHPRouteKeys ) ;
221203 return ;
222204 }
223- const report = allReports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ reportID } ` ] ;
224- const isInvoice = report ?. type === CONST . REPORT . TYPE . INVOICE ;
225- const isTask = report ?. type === CONST . REPORT . TYPE . TASK ;
226- if ( isInvoice || isTask ) {
205+ if ( width === 'wide' ) {
206+ removeWideRHPRoute ( route , setAllSuperWideRHPRouteKeys ) ;
207+ showWideRHPRoute ( route , setAllWideRHPRouteKeys ) ;
227208 return ;
228209 }
229- setExpenseReportIDs ( ( prev ) => {
230- const newSet = new Set ( prev ) ;
231- newSet . add ( reportID ) ;
232- return newSet ;
233- } ) ;
210+ removeWideRHPRoute ( route , setAllSuperWideRHPRouteKeys ) ;
211+ removeWideRHPRoute ( route , setAllWideRHPRouteKeys ) ;
234212 } ;
235213
236214 /**
237- * Checks if a report ID is marked as an expense report.
238- * Used to determine if wide RHP should be displayed optimistically .
239- * It helps us open expense as wide, before it fully loads.
215+ * Sets an optimistic width hint for a reportID before its screen renders, so the right width is
216+ * registered on first paint. Invoices and tasks are excluded from the 'wide' hint .
217+ * It helps us open expense as wide / super wide , before it fully loads.
240218 */
241- const isReportIDMarkedAsExpense = ( reportID : string ) => {
242- return expenseReportIDs . has ( reportID ) ;
243- } ;
244-
245- /**
246- * Marks a report ID as a multi-transaction expense report, adding it to the expense reports set.
247- * This enables optimistic super wide RHP display for expense reports.
248- * It helps us open expense as super wide, before it fully loads.
249- */
250- const markReportIDAsMultiTransactionExpense = ( reportID : string ) => {
251- setMultiTransactionExpenseReportIDs ( ( prev ) => {
252- const newSet = new Set ( prev ) ;
253- newSet . add ( reportID ) ;
254- return newSet ;
219+ const markReportRHPWidth = ( reportID : string | undefined , width : RHPWidthHint ) => {
220+ if ( ! reportID ) {
221+ return ;
222+ }
223+ if ( width === 'wide' ) {
224+ const report = allReports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ reportID } ` ] ;
225+ if ( report ?. type === CONST . REPORT . TYPE . INVOICE || report ?. type === CONST . REPORT . TYPE . TASK ) {
226+ return ;
227+ }
228+ }
229+ setReportRHPWidthHints ( ( prev ) => {
230+ if ( prev . get ( reportID ) === width ) {
231+ return prev ;
232+ }
233+ const next = new Map ( prev ) ;
234+ next . set ( reportID , width ) ;
235+ return next ;
255236 } ) ;
256237 } ;
257238
258239 /**
259- * Removes a report ID from the multi-transaction expense reports set.
260- * This disables optimistic super wide RHP display for that specific report
261- * (e.g., when transactions are deleted or report no longer qualifies as multi-transaction)
240+ * Clears the optimistic width hint for a reportID. Pass `width` to clear only when it matches the
241+ * current hint; omit to clear unconditionally. Called when a report no longer qualifies for a hint.
262242 */
263- const unmarkReportIDAsMultiTransactionExpense = ( reportID : string ) => {
264- setMultiTransactionExpenseReportIDs ( ( prev ) => {
265- const newSet = new Set ( prev ) ;
266- newSet . delete ( reportID ) ;
267- return newSet ;
243+ const unmarkReportRHPWidth = ( reportID : string , width ?: RHPWidthHint ) => {
244+ setReportRHPWidthHints ( ( prev ) => {
245+ const current = prev . get ( reportID ) ;
246+ if ( current === undefined ) {
247+ return prev ;
248+ }
249+ if ( width !== undefined && current !== width ) {
250+ return prev ;
251+ }
252+ const next = new Map ( prev ) ;
253+ next . delete ( reportID ) ;
254+ return next ;
268255 } ) ;
269256 } ;
270257
271- /**
272- * Checks if a report ID is marked as a multi-transaction expense report.
273- * Used to determine if super wide RHP should be displayed optimistically.
274- * It helps us open expense as super wide, before it fully loads.
275- */
276- const isReportIDMarkedAsMultiTransactionExpense = ( reportID : string ) => {
277- return multiTransactionExpenseReportIDs . has ( reportID ) ;
278- } ;
258+ const getReportRHPWidthHint = ( reportID : string ) : RHPWidthHint | undefined => reportRHPWidthHints . get ( reportID ) ;
279259
280260 /**
281261 * Effect that handles responsive RHP width calculation when window dimensions change.
@@ -319,16 +299,12 @@ function WideRHPContextProvider({children}: React.PropsWithChildren) {
319299
320300 // Because of the React Compiler we don't need to memoize it manually
321301 // eslint-disable-next-line react/jsx-no-constructed-context-values
322- const actionsValue = {
323- showWideRHPVersion,
324- showSuperWideRHPVersion,
325- removeWideRHPRouteKey,
326- removeSuperWideRHPRouteKey,
327- markReportIDAsExpense,
328- markReportIDAsMultiTransactionExpense,
329- unmarkReportIDAsMultiTransactionExpense,
330- isReportIDMarkedAsExpense,
331- isReportIDMarkedAsMultiTransactionExpense,
302+ const actionsValue : WideRHPActionsContextType = {
303+ setRHPWidth,
304+ removeRHPRouteKey,
305+ markReportRHPWidth,
306+ unmarkReportRHPWidth,
307+ getReportRHPWidthHint,
332308 syncRHPKeys,
333309 clearWideRHPKeys,
334310 setIsWideRHPClosing,
@@ -366,3 +342,4 @@ export {
366342 useWideRHPState ,
367343 useWideRHPActions ,
368344} ;
345+ export type { RHPWidth } from './types' ;
0 commit comments