App icon indicating copy to clipboard operation
App copied to clipboard

[$175] [Sentry: APP-JKQ] Web: BaseGenericTooltip loops into "Maximum update depth exceeded" in Search expense report rows

Open mountiny opened this issue 4 weeks ago • 37 comments

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

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @gijoe0295

mountiny avatar Nov 03 '26 04:11 mountiny

Triggered auto assignment to Contributor-plus team member for initial proposal review - @eh2077 (External)

melvin-bot[bot] avatar Nov 03 '26 04:11 melvin-bot[bot]

Job added to Upwork: https://www.upwork.com/jobs/~022117475152829769829

melvin-bot[bot] avatar Nov 03 '26 04:11 melvin-bot[bot]

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:

  1. Hovering a cell in the row sets isRendered = true in GenericTooltip. Hiding the tooltip never sets it back to false, so the hidden tooltip stays mounted (GenericTooltip.tsx:95-97, 164-177).
  2. The tooltip's key includes text (GenericTooltip.tsx:194-212). FlashList reuses row components for other items and keeps their state, so a reused row gets new text while isRendered is still true. The tooltip then remounts in that same commit and its mount effect calls setState again.
  3. 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's setState is the one that throws.

What changes do you think we should make in order to solve the problem?

  1. In GenericTooltip, stop keeping a hidden tooltip mounted when its key changes. Compute the key once. If it changes while isVisible is false, set isRendered back to false during render. This stops reused rows from remounting tooltips, and it removes BaseGenericTooltip from the loop.
  2. 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/:reportID with 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 BaseGenericTooltip effect (for example, skip the update when values are equal). Rejected: every fresh mount starts at undefined, so a guard never skips anything.
  • Reset isRendered when the hide animation ends. This works too, but it's blunter. Every hover would remount the tooltip.
  • Render BaseGenericTooltip only while isVisible is true. Rejected: it cuts off the hide animation.
Investigation details
  • Rows that render tooltips: TextWithTooltip in the date, text, total, and workspace cells, and the StatusBadge tooltip (ExpenseReportListItemRowWide.tsx:78-200). All of them appear only on hover. None shows on mount, so the tooltip mounts only after a hover.
  • AvatarTooltipsProvider only provides context. It has no state or effects, so it's ruled out (AvatarTooltipContext.tsx:15-17).
  • BoundsObserver also calls setState during commit when its callback identity changes. Those calls run in class lifecycles, not commitHookEffectListMount, 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.


view run

MelvinBot avatar Nov 03 '26 04:11 MelvinBot

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:

  1. The affected row is repeatedly reassigned to different items during the failing commits.
  2. Those assignments repeatedly change the tooltip key.
  3. 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:

  1. 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.

  2. 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.

  3. updates visible tooltip content without stale measurements
    Change short content to wrapping content while visible. Assert correct dimensions, positioning, and eventual update stability.

  4. 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

camesenin avatar Nov 03 '26 05:11 camesenin

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 03 '26 05:11 melvin-bot[bot]

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:

  1. Persistent isRendered in GenericTooltip: In src/components/Tooltip/GenericTooltip.tsx:95-97, hovering a cell calls showTooltip, which sets setIsRendered(true) and setIsVisible(true). When the tooltip is hidden in hideTooltip (GenericTooltip.tsx:146-158), setIsVisible(false) is set, but isRendered is never reset to false. It remains permanently true.

  2. Aggressive Key-Based Remounting on Recycled Rows: In GenericTooltip.tsx:175-194:

    {shouldRender && isRendered && (
        <BaseGenericTooltip
            ...
            key={[text, ...renderTooltipContentKey, preferredLocale].join('-')}
        />
    )}
    

    Because isRendered remains true indefinitely on once-hovered rows, when the user scrolls the Search list and FlashList recycles rows, the row's text or data changes. The dynamic key immediately unmounts and remounts BaseGenericTooltip for hidden tooltips.

  3. Synchronous useLayoutEffect State Cascades: On every mount, BaseGenericTooltip (src/components/Tooltip/BaseGenericTooltip/index.tsx:69-83) executes useLayoutEffect:

    useLayoutEffect(() => {
        setContentMeasuredWidth(contentRef.current?.getBoundingClientRect().width);
        setWrapperMeasuredHeight(rootWrapper.current?.getBoundingClientRect().height);
    }, []);
    

    Calling setContentMeasuredWidth and setWrapperMeasuredHeight synchronously schedules immediate re-renders during the commit phase. Across recycled rows in ExpenseReportListItemRowWide and AvatarTooltipsProvider, 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 throws Error: Maximum update depth exceeded.

What changes do you think we should make in order to solve the problem?

  1. Unmount Inactive Hidden Tooltips in GenericTooltip.tsx: In src/components/Tooltip/GenericTooltip.tsx:

    • Reset setIsRendered(false) once the hide animation completes (or immediately in hideTooltip if animations are bypassed).
    • Only render BaseGenericTooltip while the tooltip is visible or animating:
      {shouldRender && isRendered && isVisible && (
          <BaseGenericTooltip ... />
      )}
      

    This ensures that recycled FlashList rows do not mount hidden BaseGenericTooltip instances or execute measurement layout effects when the user is simply scrolling.

  2. Add Equality Guards to Layout State Updates in BaseGenericTooltip/index.tsx: In src/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 useLayoutEffect to useEffect: While moving state updates to useEffect avoids the synchronous depth crash, it causes noticeable visual layout flicker because tooltips render at 0/default bounds before repainting at their measured size. Resetting isRendered on hidden tooltips is the proper architectural solution.
  • Removing the dynamic key on BaseGenericTooltip: 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:

  1. Hidden Tooltip Unmount Test: Verify that calling hideTooltip() unmounts BaseGenericTooltip so that subsequent prop/text changes on the parent row do not trigger useLayoutEffect or measurement state updates.
  2. Measurement Depth Stress Test: Simulate rapid text prop updates on a mounted GenericTooltip container 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

kevinjosh10 avatar Nov 03 '26 08:11 kevinjosh10

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:

  1. Stale isRendered on hidden tooltips: In src/components/Tooltip/GenericTooltip.tsx:95-97, showTooltip sets setIsRendered(true) and setIsVisible(true). When the mouse leaves the cell, hideTooltip (lines 146-158) sets setIsVisible(false) and scales the tooltip to 0, but isRendered permanently remains true.
  2. FlashList row recycling triggers hidden tooltip remounting: In GenericTooltip.tsx:203:
    key={[text, ...renderTooltipContentKey, preferredLocale].join('-')}
    
    When the user scrolls the Search list, FlashList recycles row components and updates row data (text prop). Because isRendered is still true, the changed key forces React to completely unmount and remount BaseGenericTooltip for hidden (closed) tooltips.
  3. Synchronous layout cascade in BaseGenericTooltip: On every remount of BaseGenericTooltip (src/components/Tooltip/BaseGenericTooltip/index.tsx:69-83), useLayoutEffect runs synchronously:
    setContentMeasuredWidth(contentRef.current?.getBoundingClientRect().width);
    setWrapperMeasuredHeight(rootWrapper.current?.getBoundingClientRect().height);
    
    Calling setState unconditionally inside useLayoutEffect triggers 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, isVisible is true, so this effect does nothing.
  • When the tooltip is closed and FlashList reuses the row for a different item, isRendered becomes false. BaseGenericTooltip is cleanly unmounted, completely eliminating hidden tooltip measurement and layout effects during list scrolling.
  • When the user subsequently hovers over the cell, showTooltip() sets setIsRendered(true) and setIsVisible(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)

  1. Conditionally rendering BaseGenericTooltip only while isVisible is 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. Resetting isRendered only when !isVisible AND content changes (prevText !== text) allows the exit animation to complete smoothly while guaranteeing that recycled rows never measure inactive tooltips.
  2. Switching useLayoutEffect to useEffect in BaseGenericTooltip: Rejected because moving initial measurement to useEffect introduces 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:

  1. Recycled Row Test: Render GenericTooltip with initial text "Item A". Call showTooltip() and then hideTooltip(). Change the text prop to "Item B" while isVisible is false. Verify that BaseGenericTooltip is not mounted.
  2. Re-hover Test: Following the test above, call showTooltip(). Verify that BaseGenericTooltip mounts and renders with "Item B".

Contributor details

Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0105126232377c4c5c

ayolyn avatar Nov 03 '26 21:11 ayolyn

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 03 '26 21:11 melvin-bot[bot]

Triggered auto assignment to Contributor-plus team member for initial proposal review - @thesahindia (External)

melvin-bot[bot] avatar Nov 04 '26 00:11 melvin-bot[bot]

@thesahindia plz take over as C+, @eh2077 is outta office for a weekish. Thx

mallenexpensify avatar Nov 04 '26 00:11 mallenexpensify

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:

  1. In src/components/Tooltip/GenericTooltip.tsx (lines 95–97), hovering a tooltip target calls showTooltip, which sets setIsRendered(true) and setIsVisible(true). When the pointer leaves (hideTooltip, lines 146–158), setIsVisible(false) is called, but isRendered is never reset to false, keeping <BaseGenericTooltip> mounted even after the tooltip is hidden.
  2. In src/components/Tooltip/BaseGenericTooltip/index.tsx (lines 69–83), useLayoutEffect measures contentRef.current and rootWrapper.current and unconditionally calls setContentMeasuredWidth(...) and setWrapperMeasuredHeight(...).
  3. When a mounted BaseGenericTooltip inside ExpenseReportListItemRowWide (or AvatarTooltipsProvider) is repeatedly remounted on each parent commit (or when layout measurement triggers a parent layout/portal update that remounts BaseGenericTooltip), its mount useLayoutEffect synchronously dispatches setContentMeasuredWidth and setWrapperMeasuredHeight on every commit until React throws Maximum update depth exceeded (React #185).

What changes do you think we should make in order to solve the problem?

  1. In src/components/Tooltip/BaseGenericTooltip/index.tsx (lines 69–83), guard the state setters inside useLayoutEffect so setContentMeasuredWidth and setWrapperMeasuredHeight only update state when the newly measured width/height differs from the previous value (e.g. setContentMeasuredWidth((prev) => (prev === width ? prev : width))).
  2. In src/components/Tooltip/GenericTooltip.tsx, unmount <BaseGenericTooltip> (setIsRendered(false)) once the hide animation completes (or when isVisible is false and the tooltip finishes hiding), and ensure ExpenseReportListItemRowWide uses 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 avatar Nov 07 '26 01:11 jeffrey-graham

📣 @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:

  1. Make sure you've read and understood the contributing guidelines.
  2. 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.
  3. 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.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details. Screen Shot 2022-11-16 at 4 42 54 PM Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

melvin-bot[bot] avatar Nov 07 '26 01:11 melvin-bot[bot]

I won't be able to get to it soon, so reassigning.

thesahindia avatar Nov 07 '26 17:11 thesahindia

Current assignee @thesahindia is eligible for the External assigner, not assigning anyone new.

melvin-bot[bot] avatar Nov 07 '26 17:11 melvin-bot[bot]

Triggered auto assignment to Contributor-plus team member for initial proposal review - @gijoe0295 (External)

melvin-bot[bot] avatar Nov 07 '26 17:11 melvin-bot[bot]

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:

  1. When target components trigger tooltip measurements in onLayout or hover events, updateTargetBounds calls setTargetBounds(newBounds) on every layout pass.
  2. In search expense tables with dynamic cell widths and responsive containers, updating state triggers a parent row re-layout, which invokes onLayout again 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?

  1. In BaseGenericTooltip/index.tsx:
    • Add a shallow equality check comparing previous bounds (x, y, width, height) before updating targetBounds state. If coordinates are identical within a sub-pixel threshold, do not invoke setTargetBounds.
    • Wrap layout recalculation callbacks in useCallback and debounce measurement calls during rapid hover transitions.

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.

TassioSales avatar Nov 08 '26 00:11 TassioSales

@gijoe0295 can you please review the proposals?

mountiny avatar Nov 08 '26 02:11 mountiny

Yes

gijoe0295 avatar Nov 08 '26 16:11 gijoe0295

@gijoe0295 Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

melvin-bot[bot] avatar Nov 11 '26 21:11 melvin-bot[bot]

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?

  1. In src/components/Tooltip/types.ts and src/components/Tooltip/BaseTooltip/index.tsx:
    • Add shouldRender to SharedTooltipProps / TooltipProps and pass it down to <GenericTooltip shouldRender={shouldRender} {...props}>.
    • Update src/components/Tooltip/index.tsx to always render <BaseTooltip shouldRender={shouldRender} {...props}>{children}</BaseTooltip> rather than unmounting the wrapper tree when shouldRender is false. GenericTooltip already handles shouldRender natively 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.
  2. In src/components/TextWithTooltip/index.tsx:
    • In onLayout, guard the state setter with an identity check: only call setShowTooltip when 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.

What alternative solutions did you explore? (Optional)

  • Adding key resets in GenericTooltip: this causes remounting of tooltips rather than preventing the layout feedback oscillation.
  • Using useEffect instead of useLayoutEffect in BaseGenericTooltip: 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

TassioSales avatar Nov 12 '26 13:11 TassioSales