[$175] [Sentry: APP-JKQ] Web: BaseGenericTooltip loops into "Maximum update depth exceeded" in Search expense report rows
Sentry
https://expensify.sentry.io/issues/APP-JKQ
Impact (snapshot at filing)
- Users (total since first seen): 34
- Events: 39
- Users (last 14d, production 9.5.25 to 9.5.27): 17 (9.5.25: 7, 9.5.26: 7, 9.5.27: 3)
- First seen: 2026-07-30
- Last seen: 2026-11-03 (ongoing)
- Platform: web (standalone)
- App version(s): 9.5.25 to 9.5.27 in the scan window
- Affected route(s) (parameterized):
/r/:reportID, with the Search expense report list mounted - Mechanism: generic (React error boundary), level fatal, app blocking
Stack trace (top frames, first-party only)
Error: Maximum update depth exceeded (React #185)
react-dom commitHookEffectListMount -> layout effect create() -> dispatchSetState
Component stack, innermost first:
BaseGenericTooltip src/components/Tooltip/BaseGenericTooltip/index.tsx
Tooltip_GenericTooltip
ExpenseReportListItemRowWide
ExpenseReportListItemRow
AvatarTooltipsProvider
ExpenseReportListItem
SearchList_BaseSearchList
Search_ExpenseReportSearchView
Sentry shows UpdateRequiredView/index.tsx:78 as the most relevant frame. That frame looks like a source map mismatch, so the component stack above is the reliable signal.
Suspected cause
BaseGenericTooltip measures its content in a mount useLayoutEffect and then calls setContentMeasuredWidth and setWrapperMeasuredHeight (src/components/Tooltip/BaseGenericTooltip/index.tsx:69 on main). The effect has empty dependencies, so the loop means the tooltip remounts on each update inside the Search expense report rows. Needs investigation, starting with what remounts the tooltip in ExpenseReportListItemRowWide.
Reproduction
Unknown. See the Sentry events linked from the Sentry issue. The crash happens while the Search expense report list renders a row tooltip.
Related
- Sibling Sentry IDs: none confirmed
- Other "Maximum update depth exceeded" trackers have different throw sites: APP-DQ2 FlashList commitLayout, APP-JVF useSidebarOrderedReports, APP-N98 setSelection
- Prior GH issues: none found
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022117475152829769829
- Upwork Job ID: 2117475152829769829
- Last Price Increase: 2026-11-03
Issue Owner
Current Issue Owner: @gijoe0295
Triggered auto assignment to Contributor-plus team member for initial proposal review - @eh2077 (External)
Job added to Upwork: https://www.upwork.com/jobs/~022117475152829769829
Proposal
Confidence: medium on why the tooltip gets blamed. Low on what drives the loop: I couldn't open the Sentry events (the Sentry connection failed), and I don't have a reproduction yet.
What is the root cause of that problem?
BaseGenericTooltip is where React throws, but it isn't what causes the loop. Its layout effect has empty dependencies and runs once per mount (BaseGenericTooltip/index.tsx:69-83), so it can't loop by itself. It shows up in the stack because it remounts on every commit of a loop that something else starts:
- Hovering a cell in the row sets
isRendered = trueinGenericTooltip. Hiding the tooltip never sets it back to false, so the hidden tooltip stays mounted (GenericTooltip.tsx:95-97,164-177). - The tooltip's
keyincludestext(GenericTooltip.tsx:194-212). FlashList reuses row components for other items and keeps their state, so a reused row gets newtextwhileisRenderedis still true. The tooltip then remounts in that same commit and its mount effect callssetStateagain. - Something keeps re-laying out the Search list in sync layout effects. My best guess is FlashList's web layout loop, which the repo has already patched twice for React #185 (
patches/@shopify/flash-list/details.md). Each pass reassigns rows, so the tooltip remounts each time. Child layout effects run first, so when the nested update count passes 50, the tooltip'ssetStateis the one that throws.
What changes do you think we should make in order to solve the problem?
- In
GenericTooltip, stop keeping a hidden tooltip mounted when its key changes. Compute the key once. If it changes whileisVisibleis false, setisRenderedback to false during render. This stops reused rows from remounting tooltips, and it removesBaseGenericTooltipfrom the loop. - Before you merge, reproduce the case and check whether the crash just moves to a new top frame, such as FlashList
setRenderId. To reproduce: open/r/:reportIDwith the Search expense report list next to the RHP, use classic (non-overlay) scrollbars, hover a cell, then resize the RHP or window. If the crash moves, the FlashList measurement loop needs its own fix. Check whether the recently merged Fix report table header is larger than rest of the table (FlashList patch 017) already covers it.
What alternative solutions did you explore? (Optional)
- Add guards to the
BaseGenericTooltipeffect (for example, skip the update when values are equal). Rejected: every fresh mount starts atundefined, so a guard never skips anything. - Reset
isRenderedwhen the hide animation ends. This works too, but it's blunter. Every hover would remount the tooltip. - Render
BaseGenericTooltiponly whileisVisibleis true. Rejected: it cuts off the hide animation.
Investigation details
- Rows that render tooltips:
TextWithTooltipin the date, text, total, and workspace cells, and theStatusBadgetooltip (ExpenseReportListItemRowWide.tsx:78-200). All of them appear only on hover. None shows on mount, so the tooltip mounts only after a hover. AvatarTooltipsProvideronly provides context. It has no state or effects, so it's ruled out (AvatarTooltipContext.tsx:15-17).BoundsObserveralso callssetStateduring commit when its callback identity changes. Those calls run in class lifecycles, notcommitHookEffectListMount, so it isn't the reported frame.- No single regressing PR is confirmed. The crash group has been seen at low volume since 2026-07-30.
- Useful Sentry data to confirm the driver: other #185 events with the same component stack but a FlashList top frame, breadcrumbs (hover, then RHP resize or scroll), and OS tags (Windows or Linux means classic scrollbars).
- Possibly the same underlying loop: [$175] [Sentry: APP-DQ2] Web: FlashList commitLayout loops into "Maximum update depth exceeded" on Add existing expenses.
Next Steps for Contributor+ team:
To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/105707) to create a draft PR.
To refine: @MelvinBot <your feedback>
To reject: Explain why you are rejecting Melvin's proposal.
Proposal
Please re-state the problem that we are trying to solve in this issue.
Search expense report rows encounter React’s “Maximum update depth exceeded” error, with BaseGenericTooltip in the reported component stack. The required fix must stop the update cycle while preserving tooltip measurement, positioning, and visibility behavior.
What is the root cause of that problem?
The root cause is not established. MelvinBot’s proposal does not yet meet the evidence threshold for acceptance.
The supplied src/components/Tooltip/BaseGenericTooltip/index.tsx excerpt shows a layout effect with empty dependencies calling two measurement setters. The proposal identifies this as lines 69–83, but I could not independently retrieve the pinned revision to verify those line numbers.
This pattern does not establish an infinite loop. React’s own tooltip example measures layout and updates state inside useLayoutEffect(..., []). Strict Mode can also replay effects during development, so “exactly once per mount” requires qualification. React documentation
MelvinBot’s causal chain contains three unverified steps:
- The affected row is repeatedly reassigned to different items during the failing commits.
- Those assignments repeatedly change the tooltip key.
- Tooltip measurement updates cause another ancestor layout or reassignment update.
A child’s local state update does not inherently rerender its parent or reassign a FlashList row. The missing feedback edge is essential. A hidden tooltip remount after one text change demonstrates additional work; it does not demonstrate an unbounded cycle.
The supplied stack identifies where React detected excessive nested updates. It does not prove remounting, FlashList involvement, or a source-map mismatch.
What changes do you think we should make in order to solve the problem?
No production TypeScript diff is justified by the available evidence. Providing exact replacement lines would imply verification that has not occurred.
Before choosing the smallest fix, capture a failing trace containing:
- Tooltip instance identity, mount/unmount events, key, text, and visibility.
- Row identity and assigned report ID.
- Measurement values and the callbacks scheduling subsequent updates.
- The repeating sequence that connects measurement back to another mount or update.
Then patch the first demonstrated feedback edge and require the same reproduction to pass. If disabling hidden tooltip remounts merely moves the exception to FlashList, the proposed change has not fixed this issue.
Sentry and the pinned source were inaccessible during this review. No patch, reproduction, or passing test is claimed.
What alternative solutions did you explore? (Optional)
MelvinBot’s hidden-key reset: potentially useful as an optimization, but currently unsupported as the crash fix. Its proposed condition excludes visible tooltips, so it cannot cover a reproduction where key churn occurs while isVisible remains true. It also needs explicit handling of custom-content keys and text changing to empty and back.
Removing the tooltip key: risks stale dimensions because the supplied measurement effect does not rerun when content changes.
Adding equality guards: cannot prevent the initial measurement update on each fresh mount when state starts as undefined.
Replacing useLayoutEffect with useEffect: changes measurement timing and can introduce visible positioning flicker without eliminating the feedback mechanism.
Unmounting immediately on hide: changes tooltip lifecycle behavior and needs animation coverage.
None is demonstrated to be the safe fix. The relationship to APP-DQ2 and patch 017 remains unconfirmed.
What automated tests can you add to prevent this from re-occurring?
Add these cases to the repository’s verified tooltip test suite; the test path and existing mocks must be inspected before supplying executable Jest code:
-
measures a mounted tooltip without repeatedly mounting it
Use nonzero DOM measurements. Show the tooltip, rerender with unchanged props, and assert that updates settle without additional mounts after any Strict Mode replay. -
shows updated content after a hidden tooltip changes identity
Show and hide content A, update to B, then show again. Assert B is displayed with current measurements. Cover custom-content key changes and empty-text transitions. -
updates visible tooltip content without stale measurements
Change short content to wrapping content while visible. Assert correct dimensions, positioning, and eventual update stability. -
does not enter nested updates during the reproduced Search row transition
Exercise the actual failing sequence with the real list integration. Require this test to fail on the original revision and pass with the patch. A test that mocks away FlashList cannot validate a FlashList feedback hypothesis.
These are proposed tests, not executed evidence. JSDOM measurements alone cannot validate a browser scrollbar or resize loop; that hypothesis also requires a browser reproduction.
Contributor details
Your Expensify account email: [email protected]
Upwork Profile Link: https://www.upwork.com/freelancers/~01b60d704ba377be83
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Proposal
What is the root cause of that problem?
The crash is caused by a cyclic remount-and-measure loop between GenericTooltip, BaseGenericTooltip, and FlashList row recycling:
-
Persistent
isRenderedinGenericTooltip: Insrc/components/Tooltip/GenericTooltip.tsx:95-97, hovering a cell callsshowTooltip, which setssetIsRendered(true)andsetIsVisible(true). When the tooltip is hidden inhideTooltip(GenericTooltip.tsx:146-158),setIsVisible(false)is set, butisRenderedis never reset tofalse. It remains permanentlytrue. -
Aggressive Key-Based Remounting on Recycled Rows: In
GenericTooltip.tsx:175-194:{shouldRender && isRendered && ( <BaseGenericTooltip ... key={[text, ...renderTooltipContentKey, preferredLocale].join('-')} /> )}Because
isRenderedremainstrueindefinitely on once-hovered rows, when the user scrolls the Search list and FlashList recycles rows, the row'stextor data changes. The dynamickeyimmediately unmounts and remountsBaseGenericTooltipfor hidden tooltips. -
Synchronous
useLayoutEffectState Cascades: On every mount,BaseGenericTooltip(src/components/Tooltip/BaseGenericTooltip/index.tsx:69-83) executesuseLayoutEffect:useLayoutEffect(() => { setContentMeasuredWidth(contentRef.current?.getBoundingClientRect().width); setWrapperMeasuredHeight(rootWrapper.current?.getBoundingClientRect().height); }, []);Calling
setContentMeasuredWidthandsetWrapperMeasuredHeightsynchronously schedules immediate re-renders during the commit phase. Across recycled rows inExpenseReportListItemRowWideandAvatarTooltipsProvider, these synchronous layout updates cause parent list containers to re-measure, triggering further cell updates and immediate remounts. React detects over 50 nested commits within the same cycle and throwsError: Maximum update depth exceeded.
What changes do you think we should make in order to solve the problem?
-
Unmount Inactive Hidden Tooltips in
GenericTooltip.tsx: Insrc/components/Tooltip/GenericTooltip.tsx:- Reset
setIsRendered(false)once the hide animation completes (or immediately inhideTooltipif animations are bypassed). - Only render
BaseGenericTooltipwhile the tooltip is visible or animating:{shouldRender && isRendered && isVisible && ( <BaseGenericTooltip ... /> )}
This ensures that recycled FlashList rows do not mount hidden
BaseGenericTooltipinstances or execute measurement layout effects when the user is simply scrolling. - Reset
-
Add Equality Guards to Layout State Updates in
BaseGenericTooltip/index.tsx: Insrc/components/Tooltip/BaseGenericTooltip/index.tsx:78-79, prevent unnecessary state dispatch if measurements haven't changed:const measuredWidth = contentRef.current?.getBoundingClientRect().width; const measuredHeight = rootWrapper.current?.getBoundingClientRect().height; setContentMeasuredWidth((prev) => (prev === measuredWidth ? prev : measuredWidth)); setWrapperMeasuredHeight((prev) => (prev === measuredHeight ? prev : measuredHeight));
What alternative solutions did you explore? (Optional)
- Switching
useLayoutEffecttouseEffect: While moving state updates touseEffectavoids the synchronous depth crash, it causes noticeable visual layout flicker because tooltips render at 0/default bounds before repainting at their measured size. ResettingisRenderedon hidden tooltips is the proper architectural solution. - Removing the dynamic
keyonBaseGenericTooltip: Removing the key avoids full component unmounts, but risks retaining stale content measurements when text length changes significantly. Unmounting hidden tooltips and equality-guarding measurement updates provides both safety and measurement accuracy.
What automated tests can you add to prevent this from re-occurring?
In tests/unit/GenericTooltipTest.tsx:
- Hidden Tooltip Unmount Test:
Verify that calling
hideTooltip()unmountsBaseGenericTooltipso that subsequent prop/text changes on the parent row do not triggeruseLayoutEffector measurement state updates. - Measurement Depth Stress Test:
Simulate rapid
textprop updates on a mountedGenericTooltipcontainer and assert that state transitions settle cleanly without exceeding React's maximum update depth.
Contributor details
Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0131dae36abcf59374
Proposal
Please re-state the problem that we are trying to solve in this issue.
On web, scrolling or interacting with Search expense report rows (or list views rendering tooltips in recycled rows) crashes the app with a fatal React error:
Error: Maximum update depth exceeded (React #185) originating from BaseGenericTooltip's useLayoutEffect measurement updates.
What is the root cause of that problem?
The issue stems from a combination of retained lazy-render state in GenericTooltip, key-based unmounting/remounting on recycled list rows, and synchronous state updates in useLayoutEffect:
- Stale
isRenderedon hidden tooltips: Insrc/components/Tooltip/GenericTooltip.tsx:95-97,showTooltipsetssetIsRendered(true)andsetIsVisible(true). When the mouse leaves the cell,hideTooltip(lines 146-158) setssetIsVisible(false)and scales the tooltip to 0, butisRenderedpermanently remainstrue. - FlashList row recycling triggers hidden tooltip remounting:
In
GenericTooltip.tsx:203:
When the user scrolls the Search list, FlashList recycles row components and updates row data (key={[text, ...renderTooltipContentKey, preferredLocale].join('-')}textprop). BecauseisRenderedis stilltrue, the changed key forces React to completely unmount and remountBaseGenericTooltipfor hidden (closed) tooltips. - Synchronous layout cascade in
BaseGenericTooltip: On every remount ofBaseGenericTooltip(src/components/Tooltip/BaseGenericTooltip/index.tsx:69-83),useLayoutEffectruns synchronously:
CallingsetContentMeasuredWidth(contentRef.current?.getBoundingClientRect().width); setWrapperMeasuredHeight(rootWrapper.current?.getBoundingClientRect().height);setStateunconditionally insideuseLayoutEffecttriggers an immediate commit and re-render during layout phase. When FlashList recycles multiple rows during scrolling or container resize, mounting and measuring dozens of hidden tooltips in synchronous layout effects causes cascading re-renders that exceed React's 50-update nested depth limit, crashing the app into the error boundary.
What changes do you think we should make in order to solve the problem?
1. Unmount hidden tooltips on content/key change in src/components/Tooltip/GenericTooltip.tsx:
When isVisible is false (the tooltip is closed/hidden) and the row is recycled or its text changes (prevText !== text), reset isRendered to false:
useEffect(() => {
if (!isVisible && isRendered && prevText !== undefined && prevText !== text) {
setIsRendered(false);
}
}, [isVisible, isRendered, prevText, text]);
- While the tooltip is open or animating,
isVisibleistrue, so this effect does nothing. - When the tooltip is closed and FlashList reuses the row for a different item,
isRenderedbecomesfalse.BaseGenericTooltipis cleanly unmounted, completely eliminating hidden tooltip measurement and layout effects during list scrolling. - When the user subsequently hovers over the cell,
showTooltip()setssetIsRendered(true)andsetIsVisible(true), mounting and measuring fresh dimensions accurately.
2. Add equality guards to measurement updates in src/components/Tooltip/BaseGenericTooltip/index.tsx:
In useLayoutEffect (src/components/Tooltip/BaseGenericTooltip/index.tsx:78-79), ensure state is only dispatched if the measured dimensions actually differ from current state:
const measuredWidth = contentRef.current?.getBoundingClientRect().width;
const measuredHeight = rootWrapper.current?.getBoundingClientRect().height;
setContentMeasuredWidth((prev) => (prev === measuredWidth ? prev : measuredWidth));
setWrapperMeasuredHeight((prev) => (prev === measuredHeight ? prev : measuredHeight));
What alternative solutions did you explore? (Optional)
- Conditionally rendering
BaseGenericTooltiponly whileisVisibleis true ({shouldRender && isRendered && isVisible && <BaseGenericTooltip />}): Explored, but rejected because this immediately unmounts the component on mouse leave, abruptly cutting off the fade-out/scale-down animation and causing visual flickering. ResettingisRenderedonly when!isVisibleAND content changes (prevText !== text) allows the exit animation to complete smoothly while guaranteeing that recycled rows never measure inactive tooltips. - Switching
useLayoutEffecttouseEffectinBaseGenericTooltip: Rejected because moving initial measurement touseEffectintroduces visible layout shift/flickering as tooltips render with undefined dimensions on the initial paint before snapping into place.
What automated tests can you add to prevent this from re-occurring?
In tests/unit/GenericTooltipTest.tsx:
- Recycled Row Test: Render
GenericTooltipwith initial text"Item A". CallshowTooltip()and thenhideTooltip(). Change thetextprop to"Item B"whileisVisibleisfalse. Verify thatBaseGenericTooltipis not mounted. - Re-hover Test: Following the test above, call
showTooltip(). Verify thatBaseGenericTooltipmounts and renders with"Item B".
Contributor details
Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0105126232377c4c5c
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Triggered auto assignment to Contributor-plus team member for initial proposal review - @thesahindia (External)
@thesahindia plz take over as C+, @eh2077 is outta office for a weekish. Thx
Proposal
Please re-state the problem that we are trying to solve in this issue.
On Web when viewing /r/:reportID with the Search expense report list mounted (ExpenseReportSearchView -> ExpenseReportListItem -> ExpenseReportListItemRowWide), the app crashes with a fatal React error boundary exception: Error: Maximum update depth exceeded (React #185) inside BaseGenericTooltip (src/components/Tooltip/BaseGenericTooltip/index.tsx).
What is the root cause of that problem?
The infinite update loop comes from the interaction between GenericTooltip.tsx, BaseGenericTooltip/index.tsx, and row re-rendering/remounting inside ExpenseReportListItemRowWide:
- In
src/components/Tooltip/GenericTooltip.tsx(lines 95–97), hovering a tooltip target callsshowTooltip, which setssetIsRendered(true)andsetIsVisible(true). When the pointer leaves (hideTooltip, lines 146–158),setIsVisible(false)is called, butisRenderedis never reset tofalse, keeping<BaseGenericTooltip>mounted even after the tooltip is hidden. - In
src/components/Tooltip/BaseGenericTooltip/index.tsx(lines 69–83),useLayoutEffectmeasurescontentRef.currentandrootWrapper.currentand unconditionally callssetContentMeasuredWidth(...)andsetWrapperMeasuredHeight(...). - When a mounted
BaseGenericTooltipinsideExpenseReportListItemRowWide(orAvatarTooltipsProvider) is repeatedly remounted on each parent commit (or when layout measurement triggers a parent layout/portal update that remountsBaseGenericTooltip), its mountuseLayoutEffectsynchronously dispatchessetContentMeasuredWidthandsetWrapperMeasuredHeighton every commit until React throwsMaximum update depth exceeded (React #185).
What changes do you think we should make in order to solve the problem?
- In
src/components/Tooltip/BaseGenericTooltip/index.tsx(lines 69–83), guard the state setters insideuseLayoutEffectsosetContentMeasuredWidthandsetWrapperMeasuredHeightonly update state when the newly measured width/height differs from the previous value (e.g.setContentMeasuredWidth((prev) => (prev === width ? prev : width))). - In
src/components/Tooltip/GenericTooltip.tsx, unmount<BaseGenericTooltip>(setIsRendered(false)) once the hide animation completes (or whenisVisibleisfalseand the tooltip finishes hiding), and ensureExpenseReportListItemRowWideuses stable keys/wrappers so child tooltips do not remount on every render commit.
What alternative solutions did you explore? (Optional)
We considered replacing useLayoutEffect with useEffect in BaseGenericTooltip/index.tsx, but useLayoutEffect is intentionally used to measure tooltip dimensions before browser repaint to prevent a visual flicker on first hover. Stabilizing the row mounts, unmounting hidden BaseGenericTooltip instances after hide, and guarding the measurement state updates stops the React #185 loop without introducing tooltip flicker.
📣 @jeffrey-graham! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:
- Make sure you've read and understood the contributing guidelines.
- Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
- Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
- Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>
I won't be able to get to it soon, so reassigning.
Current assignee @thesahindia is eligible for the External assigner, not assigning anyone new.
Triggered auto assignment to Contributor-plus team member for initial proposal review - @gijoe0295 (External)
Proposal
Please re-state the problem that we are trying to solve in this issue.
In Search expense report rows, hover interactions and tooltip layout calculations cause an infinite render loop, crashing the web app with Error: Maximum update depth exceeded in BaseGenericTooltip.
What is the root cause of that problem?
In BaseGenericTooltip/index.tsx:
- When target components trigger tooltip measurements in
onLayoutor hover events,updateTargetBoundscallssetTargetBounds(newBounds)on every layout pass. - In search expense tables with dynamic cell widths and responsive containers, updating state triggers a parent row re-layout, which invokes
onLayoutagain with newly generated object references (even when coordinates have not changed), creating an infinite setState loop.
What changes do you think we should make in order to solve the problem?
- In
BaseGenericTooltip/index.tsx:- Add a shallow equality check comparing previous bounds (
x,y,width,height) before updatingtargetBoundsstate. If coordinates are identical within a sub-pixel threshold, do not invokesetTargetBounds. - Wrap layout recalculation callbacks in
useCallbackand debounce measurement calls during rapid hover transitions.
- Add a shallow equality check comparing previous bounds (
What alternative solutions did you explore? (Optional)
Using CSS-only tooltips for search rows, but maintaining BaseGenericTooltip preserves accessibility attributes and consistent tooltip styling across all platforms.
@gijoe0295 can you please review the proposals?
Yes
@gijoe0295 Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
Proposal
Please re-state the problem that we are trying to solve in this issue.
In the Search expense report view (ExpenseReportListItemRowWide), rendering cells with tooltips (DateCell, TotalCell, etc.) can enter an infinite React render/layout loop throwing Error: Maximum update depth exceeded (React #185) in BaseGenericTooltip.
What is the root cause of that problem?
In TextWithTooltip/index.tsx, text truncation is measured in onLayout by checking whether scrollWidth > offsetWidth or scrollHeight > offsetHeight, which conditionally triggers setShowTooltip(true).
When showTooltip becomes true, Tooltip/index.tsx conditionally switches from returning children directly to wrapping them in <BaseTooltip {...props}>{children}</BaseTooltip>. <BaseTooltip> wraps children inside <BoundsObserver> and <Hoverable> (a View container).
This change in DOM/parent hierarchy alters the bounding box and flex styling around the inner <Text>, which immediately dispatches another onLayout event. In table rows where column widths sit right at the boundary threshold, the wrapped layout evaluates scrollWidth <= offsetWidth, causing setShowTooltip(false).
When showTooltip becomes false, Tooltip/index.tsx unmounts <BaseTooltip>, removing the wrapper and returning children directly. This unmounting triggers yet another onLayout event on <Text>, re-evaluating scrollWidth > offsetWidth and calling setShowTooltip(true) again.
Each remount of BaseGenericTooltip runs useLayoutEffect, which calls setContentMeasuredWidth and setWrapperMeasuredHeight synchronously during the commit phase. Because this mount/unmount cycle repeats on every layout event without settling, React rapidly hits its recursive update threshold and crashes with Maximum update depth exceeded.
What changes do you think we should make in order to solve the problem?
- In
src/components/Tooltip/types.tsandsrc/components/Tooltip/BaseTooltip/index.tsx:- Add
shouldRendertoSharedTooltipProps/TooltipPropsand pass it down to<GenericTooltip shouldRender={shouldRender} {...props}>. - Update
src/components/Tooltip/index.tsxto always render<BaseTooltip shouldRender={shouldRender} {...props}>{children}</BaseTooltip>rather than unmounting the wrapper tree whenshouldRenderis false.GenericTooltipalready handlesshouldRendernatively to determine whether the tooltip bubble/overlay should be rendered (hasTooltipContent && shouldRender && isRendered), allowing the child element's DOM wrapper hierarchy to remain completely stable across truncation checks.
- Add
- In
src/components/TextWithTooltip/index.tsx:- In
onLayout, guard the state setter with an identity check: only callsetShowTooltipwhen the computed truncation state differs from previous state:setShowTooltip((prev) => (prev !== isTruncated ? isTruncated : prev)). - Include a 1px threshold (
scrollWidth - offsetWidth > 1) to eliminate subpixel rounding jitter on browser fractional zooms and responsive resize.
- In
What alternative solutions did you explore? (Optional)
- Adding
keyresets inGenericTooltip: this causes remounting of tooltips rather than preventing the layout feedback oscillation. - Using
useEffectinstead ofuseLayoutEffectinBaseGenericTooltip: this causes visible positioning flicker on web when the tooltip first appears.
What automated tests can you add to prevent this from re-occurring?
In tests/unit/components/TooltipStableRenderTest.tsx, add a unit test that renders Tooltip with a monitored child component, toggles shouldRender between false and true multiple times, and verifies that the child component maintains a stable mount count of 1 without remounting or causing recursive update cycles.
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0179cdc82689f205c7