[$175] [Sentry: APP-PNP] Unhandled IndexSizeError during report text selection
Problem
Report text-selection handling throws an uncaught IndexSizeError during mouse movement on web.
Sentry
https://expensify.sentry.io/issues/APP-PNP
- Impact at investigation: 9 users, 17 events.
- First seen: 2026-11-27 07:17 UTC.
- Browser/platform: Chrome on Windows.
- Release:
[email protected], dist6. - Screen: SearchMoneyRequestReport (
/search/r/:reportID).
Error
IndexSizeError: Failed to execute 'setStart' on 'Range': There is no child at offset 13.
Investigation
getCaretRange() calls Range.setStart() before validating whether the caret node is report text. An incompatible node/offset throws outside the existing selection-update catch.
The associated FullStory session records three matching exceptions during report interaction; navigation continues afterward. Exact reproduction steps and the triggering DOM element remain unconfirmed.
Likely introduced by #107289, deployed in 9.5.54-6. Its original issue, #104594, does not track this regression. Searches of Expensify/App and Expensify/Expensify found no matching issue.
Expected behavior
Report interactions should not throw, and unsupported caret positions should be safely ignored.
Suggested fix
Validate the caret node and offset before constructing a range, or use the validated text point directly. Add regression coverage for unsupported caret positions.
Source
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022126359264714748496
- Upwork Job ID: 2126359264714748496
- Last Price Increase: 2026-11-27
Issue Owner
Current Issue Owner: @linhvovan29546
Triggered auto assignment to Contributor-plus team member for initial proposal review - @linhvovan29546 (External)
Job added to Upwork: https://www.upwork.com/jobs/~022126359264714748496
Proposal
Please re-state the problem that we are trying to solve in this issue.
On web, dragging to select report text can throw an uncaught IndexSizeError: Failed to execute 'setStart' on 'Range': There is no child at offset N.
What is the root cause of that problem?
getCaretRange() passes whatever document.caretPositionFromPoint() returns straight into range.setStart():
https://github.com/Expensify/App/blob/5e154c8997c28b79ac0f54a1f58a94c2f229a047/src/libs/rescueStuckReportTextSelection/index.ts#L33-L41
caretPositionFromPoint does not always return a text node. When the point is over a text control (the composer textarea/input) Chrome returns the element itself as offsetNode, with offset being the character index inside its value. For an element, setStart(node, offset) treats offset as a child index, so any offset larger than its child count (e.g. 13 characters typed in a textarea with 0–1 child nodes) throws IndexSizeError. The same happens for other non-text nodes whose returned offset doesn't fit their child list.
This happens during a drag because the listener is armed by a press inside the report list (shouldRescueDrag only checks where the drag starts), and onMouseMove then calls getReportTextPoint() for every pointer position, including over the composer or other non-text elements:
https://github.com/Expensify/App/blob/5e154c8997c28b79ac0f54a1f58a94c2f229a047/src/libs/rescueStuckReportTextSelection/index.ts#L90-L98
The text-node/report-list checks in getReportTextPoint() run only after the range is built, and the existing try/catch only wraps setBaseAndExtent(), so the throw escapes the handler:
https://github.com/Expensify/App/blob/5e154c8997c28b79ac0f54a1f58a94c2f229a047/src/libs/rescueStuckReportTextSelection/index.ts#L44-L60
https://github.com/Expensify/App/blob/5e154c8997c28b79ac0f54a1f58a94c2f229a047/src/libs/rescueStuckReportTextSelection/index.ts#L123-L129
onMouseDown calls the same path, so it can throw there too:
https://github.com/Expensify/App/blob/5e154c8997c28b79ac0f54a1f58a94c2f229a047/src/libs/rescueStuckReportTextSelection/index.ts#L86
What changes do you think we should make in order to solve the problem?
- Stop building a
Rangefrom the raw caret position. IngetReportTextPoint()(orgetCaretRange()), readposition.offsetNode/position.offsetdirectly and returnnullunlessoffsetNodeis a text node, it has non-empty text, it is insideREPORT_ACTIONS_LIST_SELECTOR, andoffsetis within0..textContent.length(clamp otherwise). Only then return{node, offset}. - Since no
Rangeis needed anymore,getCaretRange()can be removed (or kept only as a validated helper). - As a safety net, wrap the caret lookup in a
try/catchthat returnsnullso any other browser quirk is ignored instead of throwing out of a globalmousemovelistener. - Add unit tests mocking
caretPositionFromPointto return (a) atextareaelement with an offset larger than its child count, (b) a non-text element, (c) a text node outside the report list, and assertonMouseMove/onMouseDowndon't throw and the selection is left untouched; plus the existing happy path still extends the selection.
What alternative solutions did you explore? (Optional)
Only wrapping setStart() in try/catch. It hides the error but still builds ranges for nodes we then discard; validating the caret node and offset first is cleaner and matches the expected behavior ("unsupported caret positions should be safely ignored").
Contributor details
Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01be5d412b545fdf18
Proposal
Please re-state the problem that we are trying to solve in this issue.
On web, dragging to select report text can throw an uncaught IndexSizeError: Failed to execute 'setStart' on 'Range': There is no child at offset 13. during pointer interaction on SearchMoneyRequestReport.
What is the root cause of that problem?
In src/libs/rescueStuckReportTextSelection/index.ts, getCaretRange() creates a Range and calls range.setStart(position.offsetNode, position.offset) directly on the raw CaretPosition returned by document.caretPositionFromPoint(x, y) before any node or offset validation occurs:
https://github.com/Expensify/App/blob/5e154c8997c28b79ac0f54a1f58a94c2f229a047/src/libs/rescueStuckReportTextSelection/index.ts#L27-L42
Per the CSSOM View spec, caretPositionFromPoint() can return a non-Text node — notably an <input> or <textarea> Element as offsetNode with offset set to the character offset inside its value (e.g. 13), or another element node. Because Range.setStart() interprets offset on an Element as a child node index rather than a character index, passing an offset greater than offsetNode.childNodes.length throws IndexSizeError.
getReportTextPoint() only checks isTextNode(node) after getCaretRange() has already thrown:
https://github.com/Expensify/App/blob/5e154c8997c28b79ac0f54a1f58a94c2f229a047/src/libs/rescueStuckReportTextSelection/index.ts#L44-L60
Because getReportTextPoint() is called from both onMouseDown() and onMouseMove() outside the try/catch around selection.setBaseAndExtent(), the error escapes uncaught:
https://github.com/Expensify/App/blob/5e154c8997c28b79ac0f54a1f58a94c2f229a047/src/libs/rescueStuckReportTextSelection/index.ts#L86-L98
What changes do you think we should make in order to solve the problem?
getCaretRange() is module-private, only used by getReportTextPoint(), and the constructed Range is immediately discarded after reading startContainer and startOffset. Instead of creating a Range, validate CaretPosition directly in getReportTextPoint():
- Update
CaretPositionFromPointinsrc/libs/rescueStuckReportTextSelection/index.tssooffsetNodeis typed asNode | null. - Remove
getCaretRange()and readdocument.caretPositionFromPointdirectly insidegetReportTextPoint(), validating before returning{node, offset}:- Return
nullifcaretPositionFromPointis unavailable or returnsnull. - Verify
isTextNode(offsetNode)anddocument.contains(offsetNode). - Verify
(offsetNode.textContent ?? '').trim()is non-empty. - Verify
Number.isInteger(offset) && offset >= 0 && offset <= text.length. - Verify
offsetNode.parentElement?.closest(REPORT_ACTIONS_LIST_SELECTOR)matches.
- Return
type CaretPositionFromPoint = (x: number, y: number) => {offsetNode: Node | null; offset: number} | null;
function getReportTextPoint(x: number, y: number): TextPoint | null {
const caretPositionFromPoint = (document as Document & {caretPositionFromPoint?: CaretPositionFromPoint}).caretPositionFromPoint;
if (typeof caretPositionFromPoint !== 'function') {
return null;
}
const position = caretPositionFromPoint.call(document, x, y);
if (!position) {
return null;
}
const {offsetNode, offset} = position;
if (!isTextNode(offsetNode) || !document.contains(offsetNode)) {
return null;
}
const text = offsetNode.textContent ?? '';
if (!text.trim()) {
return null;
}
if (!Number.isInteger(offset) || offset < 0 || offset > text.length) {
return null;
}
if (!offsetNode.parentElement?.closest(REPORT_ACTIONS_LIST_SELECTOR)) {
return null;
}
return {node: offsetNode, offset};
}
What specific scenarios should we cover in automated tests?
Add unit tests in tests/unit/RescueStuckReportTextSelectionTest.ts covering:
caretPositionFromPointreturning a non-text element (<input>/<textarea>/<div>) with an offset larger than its child count (e.g.13) during bothmousedownandmousemove— does not throw and leaves selection unchanged.caretPositionFromPointreturningnull, a detachedTextnode, a whitespace-onlyTextnode, aTextnode outsideREPORT_ACTIONS_LIST_SELECTOR, or aTextnode with an out-of-bounds/negative offset (-1,text.length + 1,NaN) — safely ignored without throwing.- Valid report
Textnodes insideREPORT_ACTIONS_LISTandMONEY_REQUEST_REPORT_ACTIONS_LISTstill rescue a stuck drag selection viaselection.setBaseAndExtent().
What alternative solutions did you explore? (Optional)
Keeping getCaretRange() and validating offsetNode/offset (or wrapping range.setStart() in try/catch) before creating the Range. Since Range is never used anywhere else in this module, validating and returning the TextPoint directly is simpler, avoids unnecessary DOM Range allocations on every mousemove, and eliminates the Range.setStart() failure mode completely.
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01eb24d273a13ebc7e
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Proposal
Please re-state the problem that we are trying to solve in this issue.
On web, dragging to select report text throws an uncaught IndexSizeError: Failed to execute 'setStart' on 'Range': There is no child at offset 13. The error comes from the rescue-selection code on the Search report screen (/search/r/:reportID), first seen 27 Nov 2026 (9 users, 17 events, Chrome on Windows). Report interactions should not throw, and unsupported caret positions should be safely ignored.
What is the root cause of that problem?
In src/libs/rescueStuckReportTextSelection/index.ts, getCaretRange() calls range.setStart(position.offsetNode, position.offset) with the raw result of document.caretPositionFromPoint() — with no validation first.
caretPositionFromPoint() can return an Element node whose offset is a child index beyond its child count (the Sentry error: offset 13 with no child at that index), and Range.setStart() throws IndexSizeError for an out-of-range offset. The same applies to a Text node whose offset exceeds its length.
The existing guard does not help: getReportTextPoint() checks isTextNode(node) and trims/validates the text — but it calls getCaretRange() first, so the throw happens inside getCaretRange() before any validation runs. The throw is outside the existing selection-update catch, so it stays uncaught.
Likely trigger (per the issue): a regression from #107289, deployed in 9.5.54-6.
What changes do you think we should make in order to solve the problem?
Validate the caret position inside getCaretRange(), before setStart():
- If
offsetNodeis a Text node, clampoffsettonode.length. - If it is an Element node, clamp
offsettonode.childNodes.length. - If it is neither (or the node is detached), return
nullso the caller safely ignores the position — the same "safely ignored" behaviour the issue asks for.
No changes to the callers: getReportTextPoint() keeps its existing text/trim/report-list checks, and onMouseMove already returns early on a null caret. This keeps the rescue-drag behaviour identical for valid positions and only removes the throw for invalid ones.
Add regression coverage: unit tests for getCaretRange / getReportTextPoint with (1) an Element node + out-of-range offset, (2) a Text node + offset beyond its length — both must return null / no throw; and (3) a valid text position still returns the correct {node, offset}.
What alternative solutions did you explore? (Optional)
- Wrapping
setStart()in try/catch and returningnull: works, but it hides the invalid position instead of fixing it, and a clamped range is still usable for the caret. Validation first is the root fix. - Checking
isTextNode()beforesetStart(): not enough on its own — an Element node with a valid child index is a legitimate caret position, so the offset itself must be range-checked, not just the node type.
📣 @allex122! 📣 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>
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~017454e30347bf2c88
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
Proposal
What is the root cause of that problem?
getCaretRange() passes the raw result of document.caretPositionFromPoint() into range.setStart() before anything checks the node:
https://github.com/Expensify/App/blob/c0604399d893869f81bf3bf222be9f0222ffca60/src/libs/rescueStuckReportTextSelection/index.ts#L33-L41
The text-node and report-list checks in getReportTextPoint() run only after that call, and the only try/catch is around setBaseAndExtent():
https://github.com/Expensify/App/blob/c0604399d893869f81bf3bf222be9f0222ffca60/src/libs/rescueStuckReportTextSelection/index.ts#L44-L60
https://github.com/Expensify/App/blob/c0604399d893869f81bf3bf222be9f0222ffca60/src/libs/rescueStuckReportTextSelection/index.ts#L123-L129
Which node throws. The message "There is no child at offset 13" is the one setStart gives for an element, not for a text node. Per the CSSOM View spec, when the point is over a text field, caretPositionFromPoint returns the <input>/<textarea> element itself, and offset is the character position inside its value. An <input> has no child nodes, so any offset above 0 throws.
Which text field, on this screen. It is not the composer: on web the composer is RNMarkdownTextInput, a contenteditable div, so the caret API returns a normal text node there.
https://github.com/Expensify/App/blob/c0604399d893869f81bf3bf222be9f0222ffca60/src/components/Composer/implementation/index.tsx#L368
The trigger is the report field inputs. MoneyRequestReportUnifiedList renders MoneyRequestViewReportFields as the list header, inside the same element that carries the MONEY_REQUEST_REPORT_ACTIONS_LIST test ID:
https://github.com/Expensify/App/blob/c0604399d893869f81bf3bf222be9f0222ffca60/src/components/MoneyRequestReportView/MoneyRequestReportUnifiedList.tsx#L335-L346
https://github.com/Expensify/App/blob/c0604399d893869f81bf3bf222be9f0222ffca60/src/components/MoneyRequestReportView/MoneyRequestReportUnifiedList.tsx#L389-L395
Each text report field is a plain TextInput, which react-native-web renders as an <input> holding the field value:
https://github.com/Expensify/App/blob/c0604399d893869f81bf3bf222be9f0222ffca60/src/components/MoneyRequestReportView/ReportFieldInlineInput.tsx#L287-L304
The inline-edit cells (merchant, description, amount) are the same kind of <input> while they are being edited:
https://github.com/Expensify/App/blob/c0604399d893869f81bf3bf222be9f0222ffca60/src/components/TransactionItemRow/DataCells/MerchantCell.tsx#L86-L102
shouldRescueDrag() only skips a press that starts on an input. A press on report text below the field arms the listener, and every mousemove over the field then throws:
https://github.com/Expensify/App/blob/c0604399d893869f81bf3bf222be9f0222ffca60/src/libs/rescueStuckReportTextSelection/index.ts#L62-L98
Steps to reproduce (answers the open question in the issue). Chrome desktop. Use a workspace with a text report field. Open one of its expense reports from Reports (/search/r/:reportID). Give the field a value longer than 13 characters. Press on a comment or expense text in the report, hold the button, and drag up across the field's text. The console logs one IndexSizeError for each mouse move over the field. That matches the three exceptions in the FullStory session.
What changes do you think we should make in order to solve the problem?
Fix it where the caret position is read, in src/libs/rescueStuckReportTextSelection/index.ts. Do not build a Range at all; it is only used to read back the same node and offset.
- Replace
getCaretRange()with a helper that returns the raw caret position ({offsetNode, offset}) ornull, withoffsetNodetyped asNode | null. - In
getReportTextPoint(), returnnullunless all of these hold, in this order:offsetNodeis a text node (this alone drops text fields, because for them the browser returns the element);- its text is not blank;
- its parent is inside
REPORT_ACTIONS_LIST_SELECTOR. Then return{node, offset: clamp(offset, 0, node.length)}.
- Wrap the browser call in the helper in
try/catchand returnnullon error. These are global capture listeners ondocument, so a future browser quirk must not reach Sentry again.
Pseudo-code:
position = caretPositionFromPoint(x, y) // null if API missing or it throws
node = position?.offsetNode
if (!isTextNode(node) || !node.textContent.trim() || !node.parentElement.closest(LIST)) return null
return {node, offset: clamp(position.offset, 0, node.length)}
Valid drags keep the same behavior. When the pointer is over a text field, the move is ignored and the browser keeps its own selection. That is what the issue expects.
Unit test: new tests/unit/RescueStuckReportTextSelectionTest.ts. Import @libs/rescueStuckReportTextSelection/index.ts directly; jest-expo would otherwise resolve the empty index.native.ts. jsdom has no caretPositionFromPoint, so mock it on document.
- DOM fixture that matches the real page: a
div[data-testid=MoneyRequestReportActionsList]with a<p>of report text and an<input value="Q4 Marketing Offsite">. - Press (
mousedown, button 0) on the<p>with the caret mock returning its text node. Then sendmousemove(buttons: 1) with the mock returning{offsetNode: input, offset: 13}. - Assert through a
windowerrorlistener, notexpect(...).not.toThrow(). jsdom reports an exception thrown in an event listener as a windowerrorevent; it does not rethrow it fromdispatchEvent. With this check the test fails on main and passes after the fix. - Also cover: the same element case on
mousedown; anullcaret; a text node outside the list. All must leave the selection unchanged with no error. - Happy path: the selection anchor is on an empty element, the move is over list text, and
selection.setBaseAndExtentgets the press point and the move point.
What alternative solutions did you explore? (Optional)
- Only wrap
range.setStart()intry/catch: stops the crash, but keeps creating a throw-awayRangeon every mouse move and hides which input was hit. - Clamp the element offset to its child count and keep the
Range: the result is still an element, sogetReportTextPoint()drops it anyway. It is extra work for the same result. - Disarm the rescue as soon as the pointer enters an input: also works, but it needs a second hit test on every move. The text-node check already covers it.