Repository navigation
Description
Sentry
- https://expensify.sentry.io/issues/APP-FR5 —
TypeError: this.errorCb is not a function
Impact (snapshot at filing, 2026-09-10)
| Sentry ID | Users (last 14d) | Users (total since first seen) | Events | First seen |
|---|---|---|---|---|
| APP-FR5 | 13 | 57 | 80 | 2026-06-19 |
- Last seen: 2026-09-09 (ongoing)
- Platform: web (
standalone), seen on Edge and Chrome on Windows - App version(s): present across 9.4.62-4 through 9.4.73-3 — not a recent regression
- Affected route(s):
/create/submit/start/1/:transactionID/distance-new/distance-map - Affected view(s):
distance-map - Mechanism:
auto.browser.global_handlers.onunhandledrejection, levelerror - Roughly 1.4 events per affected user, so it fires once per exposure rather than in a loop
Error
TypeError: this.errorCb is not a function
Stack trace (top frames)
All frames are inside the bundled mapbox-gl distribution. There are no App frames.
node_modules/mapbox-gl/dist/mapbox-gl.js:19:10999
... skuToken:this.skuToken,userId:this.anonId},e=>{e?this.errorCb(e):o&&(this.success[o]=!0);},i));}
remove(){this.errorCb=null;}
node_modules/mapbox-gl/dist/mapbox-gl.js:19:8868 (this.pendingRequest)
this.pendingRequest=e.p(l,e=>{this.pendingRequest=null,o(e),this.saveEventData(),this.processRequests(r);});
node_modules/mapbox-gl/dist/mapbox-gl.js:11:24316
Suspected cause
This is a teardown race inside mapbox-gl's telemetry and turnstile event code, not in App logic.
The relevant object registers an error callback and fires a postEvent request. Its remove() method sets this.errorCb = null. When the map is removed while a telemetry request is still in flight, the request settles afterwards and the completion handler calls this.errorCb(e) on the now-null field, which throws. The throw happens inside a promise handler with no catch, so it surfaces as an unhandled rejection and Sentry records it as an unhandled error.
The trigger in App is leaving the distance map before the Mapbox telemetry request completes — for example tapping back or completing the step quickly on a slow connection. That matches the once-per-user event pattern.
Because the whole stack is third-party, the fix is not in App code. Options in order of preference:
- Bump
mapbox-glif a release since our pinned version fixes the null callback path. Check the upstream changelog and open issues forerrorCb. - If no upstream fix exists, delay
map.remove()until in-flight telemetry settles, or disable Mapbox telemetry on this screen so the request is never issued. - As a last resort, add a
patch-packagepatch guarding the callback invocation.
Confirm the currently pinned mapbox-gl version before choosing.
Reproduction
- Open a new expense and choose Distance to reach
/create/submit/start/1/:transactionID/distance-new/distance-map. - Throttle the network in devtools so the Mapbox telemetry request stays in flight.
- Navigate away from the distance map immediately after it renders.
- Verify an unhandled
this.errorCb is not a functionrejection appears in the JS console.
Related
- Parent tracker: [Tracking] Top Sentry crashes monthly check-in #91302
Issue Owner
Current Issue Owner: @mallenexpensifyMetadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
melvin-bot commentedon Sep 10, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @Pujan92 (
External)melvin-bot commentedon Sep 10, 2026
Unable to auto-create job on Upwork. The BZ team member should create it manually for this issue.
MelvinBot commentedon Sep 10, 2026
Proposal
What is the root cause of that problem?
A use-after-teardown race in mapbox-gl's telemetry, triggered by our map unmounting while its
map.loadtelemetry POST is still in flight.MapLoadEvent.remove()nullsthis.errorCbbut does not cancel the pending request. When that request later fails, the completion handler callsthis.errorCb(err)onnull→TypeError. The throw happens inside afetch().catch()with nothing downstream, so it surfaces as an unhandled rejection.The failure half is not a slow connection —
events.mapbox.comis on common ad/privacy blocklists, so the POST reliably fails for a subset of users (upstream issue mapbox/mapbox-gl-js#13226, open since 2024). Blocked user + any map unmount = guaranteed throw. That explains the steady ~1.4 events per user rather than a rare race.Most important detail for prioritising: mapbox-gl calls
postMapLoadEvent(..., () => {})— theerrorCbthat fails to fire is an empty no-op. Nothing functional is lost. This is pure third-party noise with zero user-visible impact.Evidence and full data flow
App side — we never touch mapbox-gl at runtime. Only
MapViewImpl.web.tsx:3imports its CSS.react-map-gl's<Map>atMapViewImpl.web.tsx:282owns the instance, and@vis.gl/react-mapboxcallsmap.remove()in its unmount cleanup.Three distinct unmount triggers on this screen:
Navigation.goBack) — the Sentry route.MapView.web.tsx:51andMapViewImpl.web.tsx:277gate on!isOffline, so going offline unmounts the map — and the same blip fails the in-flight POST. A correlated double-trigger.ONYXKEYS.MAPBOX_ACCESS_TOKEN(25-min refresh) emptiesaccessToken→ unmount.Upstream source (v3.30.0
src/util/mapbox.ts):Why it's an unhandled rejection: in 3.24.0's ajax layer the
TypeErrorthrown in.then()is caught by the sibling.catch(), which invokes the same broken callback a second time — and that throw has no handler left.Amplifier:
mapLoadEventandmapSessionAPIare module-level singletons shared by everyMap. Unmounting any one map nullserrorCbglobally, so one map's teardown can break another live map's in-flight request.Not reported upstream. Zero PRs and zero issues on
mapbox/mapbox-gl-jsmentionerrorCbas a defect (the three search hits are all about missing access tokens). No CHANGELOG entry from 3.25.0 through 3.31.0-rc.1 mentions telemetry,errorCb, or teardown.react-error-boundarycannot catch this — an unhandled promise rejection is not a React render error, so the boundary atMapView.web.tsx:33is irrelevant here.What changes do you think we should make in order to solve the problem?
this.errorCb is not a functiontoignoreErrorsinsrc/setup/telemetry/setupSentry.ts:60-67. The array already carries exactly this kind of entry. Since the callback it fails to invoke is an empty no-op, suppression loses no signal.patch-packagepatch guarding the two call sites —if (this.errorCb) this.errorCb(err)inMapLoadEvent.processRequestsandMapSessionAPI.processRequests. Our patch infra is already in place (patches/,postinstall); there is nopatches/mapbox-gl/today. This keeps telemetry intact, so it does not touch the ToS-fenced code.Step 1 alone closes the Sentry issue. Steps 2–3 fix the actual throw.
What alternative solutions did you explore? (Optional)
Three rejected options, with why
mapbox-glpast 3.24.0 — does not work. Unfixed in every release through 3.30.0 and onmain; 3.30.0 makes cancellation impossible.mapboxgl.config.EVENTS_URL = null— does not work. In 3.24.0EVENTS_URLis a getter-only accessor derived fromAPI_URL: the assignment is a silent no-op in sloppy mode and throws under ESM strict mode. There is nosetTelemetryEnabled, no telemetry option on<Map>, and no env flag anywhere in the bundle. The only lever,API_URL, would break all tile and style requests.Object.definePropertyover the getter would technically work, but the telemetry call site is explicitly fenced with "REMOVAL OR MODIFICATION OF THE PRECEDING CODE VIOLATES THE MAPBOX TERMS OF SERVICE" — a contract question, not a code one.reuseMapsprop on<Map>— technically effective (unmount takesrecycle()instead ofdestroy(), somap.remove()never runs anderrorCbis never nulled), but it changes map-instance lifetime semantics across mounts. I did not verify that waypoint markers and direction layers re-attach cleanly or that zoom/bounds reset correctly. Too much behavioural risk for a no-op-callback noise bug.map.remove()until telemetry settles (option 2 in the issue body) — not reachable from App code; the teardown lives inside@vis.gl/react-mapbox's unmount effect, and blocking unmount on a third-party POST that ad blockers hang is worse than the bug.Related issues: I scanned open
Expensify/Appissues forerrorCb/ mapbox-gl distance-map crashes and found no duplicates or related reports.Confidence: high — every claim above is read from mapbox-gl's own source (installed 3.24.0, published v3.30.0, and
main) plus the App call chain. Not reproduced live: triggering it needsevents.mapbox.comblocked or failing at the moment of unmount, which is not reliably stageable in a test harness.Next Steps for Contributor+ team:
To accept:
@MelvinBot implement [this](https://github.com/Expensify/App/issues/100845#issuecomment-5619616094)to create a draft PR.To refine:
@MelvinBot <your feedback>To reject: Explain why you are rejecting Melvin's proposal. · view recording
mountiny commentedon Sep 11, 2026
@Pujan92 can you please review the proposal from Melvin and open it to the community if not good enough? Thanks
Pujan92 commentedon Sep 15, 2026
I think better to fix this upstream to check the truthiness of this.errorCb here.
I will look into it and open the issue in Mapbox. If they don't consider fixing it, then we can consider using patch-package.
mountiny commentedon Sep 17, 2026
Thanks, that would be great @Pujan92
melvin-bot commentedon Sep 18, 2026
@Pujan92 Whoops! This issue is 2 days overdue. Let's get this updated quick!
35 remaining items
melvin-bot commentedon Nov 11, 2026
@Pujan92
The solution for this issue has been 🚀 deployed to production 🚀 in version 9.5.35-3 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:
If no regressions arise, payment will be issued on 2026-11-18. 🎊
The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the Contributor+ Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]. If no checklist is needed for this issue, you can click: [no checklist button]
expensify-chore-bot commentedon Nov 17, 2026
Triggered auto assignment to @mallenexpensify (
Awaiting Payment)expensify-chore-bot commentedon Nov 17, 2026
Payment Summary
Resolving PRs:
Patch mapbox-gl to guard the telemetry error callback after map removal #106319
Reviewer: @Pujan92 owed $175 via NewDot
BugZero Checklist (@mallenexpensify)
Pujan92 commentedon Nov 19, 2026
No Checklist Needed
This was an upstream fix in the mapbox lib.
mallenexpensify commentedon Nov 19, 2026
Claude posting on behalf of Matt:
Ready. Job price: $250 (Pujan92 assigned 2026-09-10).
Pujan92 wrote the PR. Melvin's summary lists Pujan92 as Reviewer, which is wrong.
Pujan92 posted No Checklist Needed: comment. No deploy blockers.
Next: pay. No Caps+Y.
Evidence
PAYPREP v1mallenexpensify commentedon Nov 20, 2026
Payment Summary
Contributor+: @Pujan92 due $250 via NewDot
twisterdotcom commentedon Nov 20, 2026
$250 approved for @Pujan92 in Report ID: R005IRJ2va14.
Zapier Logs
Run ID: 00040eee-f94e-aab2-ee81-8cc46d658d34SO: https://stackoverflowteams.com/c/expensify/questions/7582