[Discover][APM] Check for undefined data from useFetcher in TraceWaterfallEmbeddable#240843
Conversation
…erfallContextProvider
|
Pinging @elastic/obs-ux-infra_services-team (Team:obs-ux-infra_services) |
| const { duration, traceWaterfall, maxDepth, rootItem, legends, colorBy, traceState } = | ||
| useTraceWaterfall({ | ||
| traceItems, | ||
| traceItems: traceItems || [], |
There was a problem hiding this comment.
Wouldn't it be better if we could investigate why the API is returning undefined and fix it there?
There was a problem hiding this comment.
Specially as you mentioned that TS is not expecting it to be undefined.
There was a problem hiding this comment.
Hey @cauemarcondes, thanks for the feedback!
Looking at this from a different angle, I realized where the critical point was.
It’s not that TS didn’t expect undefined, but that we were bypassing it in TraceWaterfallEmbeddable with traceItems={data?.traceItems!}, assuming data (and traceItems) would always be there.
When I checked FocusedWaterfallEmbeddable, I saw it does a proper check for data before rendering, so I added the same here to keep things consistent.
We need this because useFetcher can return undefined for data.
Was it an API problem on our side?
No, it wasn’t.
Looking at the code, we show <Loading /> if the useFetcher status is isPending (loading or not_initiated). But if the status is failure, the code just continues running, which can result in data being undefined according to how useFetcher works.
…-of-undefined-reading-map
💛 Build succeeded, but was flaky
Failed CI Steps
Test Failures
Metrics [docs]Async chunks
History
cc @iblancof |
|
Starting backport for target branches: 8.19, 9.1, 9.2 https://github.com/elastic/kibana/actions/runs/18902197083 |
…fall (elastic#240843) ## Summary Closes elastic#238405 Since we upgraded the error handling strategy to catch Fatal React Errors, we’ve started seeing `TypeError: Cannot read properties of undefined (reading 'map')` in versions 8.19.x and 9.1.x. <img width="809" height="121" alt="Screenshot 2025-10-27 at 16 03 48" src="https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8" /> After reviewing the error stack, we found that this occurs because `traceItems` is occasionally arrive as `undefined`. Although TS enforces that it should always be defined, a potential API malfunction may cause this scenario. To prevent users from encountering an uncontrolled error, this PR adds a check for `undefined` for `data` coming from the `useFetcher` (more details in [this comment](elastic#240843 (comment))). This ensures that the UI behaves safely even if `traceItems` is unexpectedly `undefined`. |Before|After| |-|-| ||<img width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04" src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064" />| I also took the chance to update the UI, so the error message is more visible: |Before|After| |-|-| |<img width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04" src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064" />|<img width="1405" height="966" alt="Screenshot 2025-10-28 at 14 24 51" src="https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20" />| The same error has been now added to the `TraceWaterfallEmbeddable`: <img width="1387" height="135" alt="Screenshot 2025-10-28 at 14 27 31" src="https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf" /> (cherry picked from commit 7d2975b)
💔 Some backports could not be created
Note: Successful backport PRs will be merged automatically after passing CI. Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…fall (elastic#240843) ## Summary Closes elastic#238405 Since we upgraded the error handling strategy to catch Fatal React Errors, we’ve started seeing `TypeError: Cannot read properties of undefined (reading 'map')` in versions 8.19.x and 9.1.x. <img width="809" height="121" alt="Screenshot 2025-10-27 at 16 03 48" src="https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8" /> After reviewing the error stack, we found that this occurs because `traceItems` is occasionally arrive as `undefined`. Although TS enforces that it should always be defined, a potential API malfunction may cause this scenario. To prevent users from encountering an uncontrolled error, this PR adds a check for `undefined` for `data` coming from the `useFetcher` (more details in [this comment](elastic#240843 (comment))). This ensures that the UI behaves safely even if `traceItems` is unexpectedly `undefined`. |Before|After| |-|-| ||<img width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04" src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064" />| I also took the chance to update the UI, so the error message is more visible: |Before|After| |-|-| |<img width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04" src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064" />|<img width="1405" height="966" alt="Screenshot 2025-10-28 at 14 24 51" src="https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20" />| The same error has been now added to the `TraceWaterfallEmbeddable`: <img width="1387" height="135" alt="Screenshot 2025-10-28 at 14 27 31" src="https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf" /> (cherry picked from commit 7d2975b) # Conflicts: # x-pack/solutions/observability/plugins/apm/public/embeddable/trace_waterfall/trace_waterfall_embeddable.tsx
…eWaterfall (#240843) (#241079) # Backport This will backport the following commits from `main` to `9.2`: - [[Discover][APM] Add fallback to traceItems when calling useTraceWaterfall (#240843)](#240843) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Irene Blanco","email":"irene.blanco@elastic.co"},"sourceCommit":{"committedDate":"2025-10-29T08:51:15Z","message":"[Discover][APM] Add fallback to traceItems when calling useTraceWaterfall (#240843)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/238405\n\nSince we upgraded the error handling strategy to catch Fatal React\nErrors, we’ve started seeing `TypeError: Cannot read properties of\nundefined (reading 'map')` in versions 8.19.x and 9.1.x.\n\n<img width=\"809\" height=\"121\" alt=\"Screenshot 2025-10-27 at 16 03 48\"\nsrc=\"https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8\"\n/>\n\nAfter reviewing the error stack, we found that this occurs because\n`traceItems` is occasionally arrive as `undefined`. Although TS enforces\nthat it should always be defined, a potential API malfunction may cause\nthis scenario.\n\nTo prevent users from encountering an uncontrolled error, this PR adds a\ncheck for `undefined` for `data` coming from the `useFetcher` (more\ndetails in [this\ncomment](https://github.com/elastic/kibana/pull/240843#discussion_r2469707226)).\n\nThis ensures that the UI behaves safely even if `traceItems` is\nunexpectedly `undefined`.\n\n|Before|After|\n|-|-|\n||<img\nwidth=\"1405\" height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26 04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|\n\nI also took the chance to update the UI, so the error message is more\nvisible:\n|Before|After|\n|-|-|\n|<img width=\"1405\" height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26 04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|<img width=\"1405\" height=\"966\" alt=\"Screenshot 2025-10-28 at 14 24\n51\"\nsrc=\"https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20\"\n/>|\n\nThe same error has been now added to the `TraceWaterfallEmbeddable`:\n<img width=\"1387\" height=\"135\" alt=\"Screenshot 2025-10-28 at 14 27 31\"\nsrc=\"https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf\"\n/>","sha":"7d2975b2ece67ff9b1c99be7d98bb422099065e1","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:obs-ux-infra_services","backport:version","v9.3.0","v8.19.7","v9.1.7","v9.2.1"],"title":"[Discover][APM] Add fallback to traceItems when calling useTraceWaterfall ","number":240843,"url":"https://github.com/elastic/kibana/pull/240843","mergeCommit":{"message":"[Discover][APM] Add fallback to traceItems when calling useTraceWaterfall (#240843)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/238405\n\nSince we upgraded the error handling strategy to catch Fatal React\nErrors, we’ve started seeing `TypeError: Cannot read properties of\nundefined (reading 'map')` in versions 8.19.x and 9.1.x.\n\n<img width=\"809\" height=\"121\" alt=\"Screenshot 2025-10-27 at 16 03 48\"\nsrc=\"https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8\"\n/>\n\nAfter reviewing the error stack, we found that this occurs because\n`traceItems` is occasionally arrive as `undefined`. Although TS enforces\nthat it should always be defined, a potential API malfunction may cause\nthis scenario.\n\nTo prevent users from encountering an uncontrolled error, this PR adds a\ncheck for `undefined` for `data` coming from the `useFetcher` (more\ndetails in [this\ncomment](https://github.com/elastic/kibana/pull/240843#discussion_r2469707226)).\n\nThis ensures that the UI behaves safely even if `traceItems` is\nunexpectedly `undefined`.\n\n|Before|After|\n|-|-|\n||<img\nwidth=\"1405\" height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26 04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|\n\nI also took the chance to update the UI, so the error message is more\nvisible:\n|Before|After|\n|-|-|\n|<img width=\"1405\" height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26 04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|<img width=\"1405\" height=\"966\" alt=\"Screenshot 2025-10-28 at 14 24\n51\"\nsrc=\"https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20\"\n/>|\n\nThe same error has been now added to the `TraceWaterfallEmbeddable`:\n<img width=\"1387\" height=\"135\" alt=\"Screenshot 2025-10-28 at 14 27 31\"\nsrc=\"https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf\"\n/>","sha":"7d2975b2ece67ff9b1c99be7d98bb422099065e1"}},"sourceBranch":"main","suggestedTargetBranches":["8.19","9.1","9.2"],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/240843","number":240843,"mergeCommit":{"message":"[Discover][APM] Add fallback to traceItems when calling useTraceWaterfall (#240843)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/238405\n\nSince we upgraded the error handling strategy to catch Fatal React\nErrors, we’ve started seeing `TypeError: Cannot read properties of\nundefined (reading 'map')` in versions 8.19.x and 9.1.x.\n\n<img width=\"809\" height=\"121\" alt=\"Screenshot 2025-10-27 at 16 03 48\"\nsrc=\"https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8\"\n/>\n\nAfter reviewing the error stack, we found that this occurs because\n`traceItems` is occasionally arrive as `undefined`. Although TS enforces\nthat it should always be defined, a potential API malfunction may cause\nthis scenario.\n\nTo prevent users from encountering an uncontrolled error, this PR adds a\ncheck for `undefined` for `data` coming from the `useFetcher` (more\ndetails in [this\ncomment](https://github.com/elastic/kibana/pull/240843#discussion_r2469707226)).\n\nThis ensures that the UI behaves safely even if `traceItems` is\nunexpectedly `undefined`.\n\n|Before|After|\n|-|-|\n||<img\nwidth=\"1405\" height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26 04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|\n\nI also took the chance to update the UI, so the error message is more\nvisible:\n|Before|After|\n|-|-|\n|<img width=\"1405\" height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26 04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|<img width=\"1405\" height=\"966\" alt=\"Screenshot 2025-10-28 at 14 24\n51\"\nsrc=\"https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20\"\n/>|\n\nThe same error has been now added to the `TraceWaterfallEmbeddable`:\n<img width=\"1387\" height=\"135\" alt=\"Screenshot 2025-10-28 at 14 27 31\"\nsrc=\"https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf\"\n/>","sha":"7d2975b2ece67ff9b1c99be7d98bb422099065e1"}},{"branch":"8.19","label":"v8.19.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.1","label":"v9.1.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.2","label":"v9.2.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Irene Blanco <irene.blanco@elastic.co>
…fall (elastic#240843) ## Summary Closes elastic#238405 Since we upgraded the error handling strategy to catch Fatal React Errors, we’ve started seeing `TypeError: Cannot read properties of undefined (reading 'map')` in versions 8.19.x and 9.1.x. <img width="809" height="121" alt="Screenshot 2025-10-27 at 16 03 48" src="https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8" /> After reviewing the error stack, we found that this occurs because `traceItems` is occasionally arrive as `undefined`. Although TS enforces that it should always be defined, a potential API malfunction may cause this scenario. To prevent users from encountering an uncontrolled error, this PR adds a check for `undefined` for `data` coming from the `useFetcher` (more details in [this comment](elastic#240843 (comment))). This ensures that the UI behaves safely even if `traceItems` is unexpectedly `undefined`. |Before|After| |-|-| ||<img width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04" src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064" />| I also took the chance to update the UI, so the error message is more visible: |Before|After| |-|-| |<img width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04" src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064" />|<img width="1405" height="966" alt="Screenshot 2025-10-28 at 14 24 51" src="https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20" />| The same error has been now added to the `TraceWaterfallEmbeddable`: <img width="1387" height="135" alt="Screenshot 2025-10-28 at 14 27 31" src="https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf" />
…ceWaterfallEmbeddable (#240843) (#241095) # Backport This will backport the following commits from `main` to `9.1`: - [[Discover][APM] Add fallback to traceItems when calling useTraceWaterfall (#240843)](#240843) <!--- Backport version: 10.1.0 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Irene Blanco","email":"irene.blanco@elastic.co"},"sourceCommit":{"committedDate":"2025-10-29T08:51:15Z","message":"[Discover][APM] Add fallback to traceItems when calling useTraceWaterfall (#240843)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/238405\n\nSince we upgraded the error handling strategy to catch Fatal React\nErrors, we’ve started seeing `TypeError: Cannot read properties of\nundefined (reading 'map')` in versions 8.19.x and 9.1.x.\n\n<img width=\"809\" height=\"121\" alt=\"Screenshot 2025-10-27 at 16 03 48\"\nsrc=\"https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8\"\n/>\n\nAfter reviewing the error stack, we found that this occurs because\n`traceItems` is occasionally arrive as `undefined`. Although TS enforces\nthat it should always be defined, a potential API malfunction may cause\nthis scenario.\n\nTo prevent users from encountering an uncontrolled error, this PR adds a\ncheck for `undefined` for `data` coming from the `useFetcher` (more\ndetails in [this\ncomment](https://github.com/elastic/kibana/pull/240843#discussion_r2469707226)).\n\nThis ensures that the UI behaves safely even if `traceItems` is\nunexpectedly `undefined`.\n\n|Before|After|\n|-|-|\n||<img\nwidth=\"1405\" height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26 04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|\n\nI also took the chance to update the UI, so the error message is more\nvisible:\n|Before|After|\n|-|-|\n|<img width=\"1405\" height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26 04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|<img width=\"1405\" height=\"966\" alt=\"Screenshot 2025-10-28 at 14 24\n51\"\nsrc=\"https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20\"\n/>|\n\nThe same error has been now added to the `TraceWaterfallEmbeddable`:\n<img width=\"1387\" height=\"135\" alt=\"Screenshot 2025-10-28 at 14 27 31\"\nsrc=\"https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf\"\n/>","sha":"7d2975b2ece67ff9b1c99be7d98bb422099065e1","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:obs-ux-infra_services","backport:version","v9.3.0","v8.19.7","v9.1.7","v9.2.1"],"title":"[Discover][APM] Add fallback to traceItems when calling useTraceWaterfall ","number":240843,"url":"https://github.com/elastic/kibana/pull/240843","mergeCommit":{"message":"[Discover][APM] Add fallback to traceItems when calling useTraceWaterfall (#240843)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/238405\n\nSince we upgraded the error handling strategy to catch Fatal React\nErrors, we’ve started seeing `TypeError: Cannot read properties of\nundefined (reading 'map')` in versions 8.19.x and 9.1.x.\n\n<img width=\"809\" height=\"121\" alt=\"Screenshot 2025-10-27 at 16 03 48\"\nsrc=\"https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8\"\n/>\n\nAfter reviewing the error stack, we found that this occurs because\n`traceItems` is occasionally arrive as `undefined`. Although TS enforces\nthat it should always be defined, a potential API malfunction may cause\nthis scenario.\n\nTo prevent users from encountering an uncontrolled error, this PR adds a\ncheck for `undefined` for `data` coming from the `useFetcher` (more\ndetails in [this\ncomment](https://github.com/elastic/kibana/pull/240843#discussion_r2469707226)).\n\nThis ensures that the UI behaves safely even if `traceItems` is\nunexpectedly `undefined`.\n\n|Before|After|\n|-|-|\n||<img\nwidth=\"1405\" height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26 04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|\n\nI also took the chance to update the UI, so the error message is more\nvisible:\n|Before|After|\n|-|-|\n|<img width=\"1405\" height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26 04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|<img width=\"1405\" height=\"966\" alt=\"Screenshot 2025-10-28 at 14 24\n51\"\nsrc=\"https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20\"\n/>|\n\nThe same error has been now added to the `TraceWaterfallEmbeddable`:\n<img width=\"1387\" height=\"135\" alt=\"Screenshot 2025-10-28 at 14 27 31\"\nsrc=\"https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf\"\n/>","sha":"7d2975b2ece67ff9b1c99be7d98bb422099065e1"}},"sourceBranch":"main","suggestedTargetBranches":["8.19","9.1"],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/240843","number":240843,"mergeCommit":{"message":"[Discover][APM] Add fallback to traceItems when calling useTraceWaterfall (#240843)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/238405\n\nSince we upgraded the error handling strategy to catch Fatal React\nErrors, we’ve started seeing `TypeError: Cannot read properties of\nundefined (reading 'map')` in versions 8.19.x and 9.1.x.\n\n<img width=\"809\" height=\"121\" alt=\"Screenshot 2025-10-27 at 16 03 48\"\nsrc=\"https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8\"\n/>\n\nAfter reviewing the error stack, we found that this occurs because\n`traceItems` is occasionally arrive as `undefined`. Although TS enforces\nthat it should always be defined, a potential API malfunction may cause\nthis scenario.\n\nTo prevent users from encountering an uncontrolled error, this PR adds a\ncheck for `undefined` for `data` coming from the `useFetcher` (more\ndetails in [this\ncomment](https://github.com/elastic/kibana/pull/240843#discussion_r2469707226)).\n\nThis ensures that the UI behaves safely even if `traceItems` is\nunexpectedly `undefined`.\n\n|Before|After|\n|-|-|\n||<img\nwidth=\"1405\" height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26 04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|\n\nI also took the chance to update the UI, so the error message is more\nvisible:\n|Before|After|\n|-|-|\n|<img width=\"1405\" height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26 04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|<img width=\"1405\" height=\"966\" alt=\"Screenshot 2025-10-28 at 14 24\n51\"\nsrc=\"https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20\"\n/>|\n\nThe same error has been now added to the `TraceWaterfallEmbeddable`:\n<img width=\"1387\" height=\"135\" alt=\"Screenshot 2025-10-28 at 14 27 31\"\nsrc=\"https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf\"\n/>","sha":"7d2975b2ece67ff9b1c99be7d98bb422099065e1"}},{"branch":"8.19","label":"v8.19.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.1","label":"v9.1.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.2","label":"v9.2.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/241079","number":241079,"state":"OPEN"}]}] BACKPORT-->
…aceWaterfallEmbeddable (#240843) (#241099) # Backport This will backport the following commits from `main` to `8.19`: - [[Discover][APM] Add fallback to traceItems when calling useTraceWaterfall (#240843)](#240843) <!--- Backport version: 10.1.0 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Irene Blanco","email":"irene.blanco@elastic.co"},"sourceCommit":{"committedDate":"2025-10-29T08:51:15Z","message":"[Discover][APM] Add fallback to traceItems when calling useTraceWaterfall (#240843)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/238405\n\nSince we upgraded the error handling strategy to catch Fatal React\nErrors, we’ve started seeing `TypeError: Cannot read properties of\nundefined (reading 'map')` in versions 8.19.x and 9.1.x.\n\n<img width=\"809\" height=\"121\" alt=\"Screenshot 2025-10-27 at 16 03 48\"\nsrc=\"https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8\"\n/>\n\nAfter reviewing the error stack, we found that this occurs because\n`traceItems` is occasionally arrive as `undefined`. Although TS enforces\nthat it should always be defined, a potential API malfunction may cause\nthis scenario.\n\nTo prevent users from encountering an uncontrolled error, this PR adds a\ncheck for `undefined` for `data` coming from the `useFetcher` (more\ndetails in [this\ncomment](https://github.com/elastic/kibana/pull/240843#discussion_r2469707226)).\n\nThis ensures that the UI behaves safely even if `traceItems` is\nunexpectedly `undefined`.\n\n|Before|After|\n|-|-|\n||<img\nwidth=\"1405\" height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26 04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|\n\nI also took the chance to update the UI, so the error message is more\nvisible:\n|Before|After|\n|-|-|\n|<img width=\"1405\" height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26 04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|<img width=\"1405\" height=\"966\" alt=\"Screenshot 2025-10-28 at 14 24\n51\"\nsrc=\"https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20\"\n/>|\n\nThe same error has been now added to the `TraceWaterfallEmbeddable`:\n<img width=\"1387\" height=\"135\" alt=\"Screenshot 2025-10-28 at 14 27 31\"\nsrc=\"https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf\"\n/>","sha":"7d2975b2ece67ff9b1c99be7d98bb422099065e1","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:obs-ux-infra_services","backport:version","v9.3.0","v8.19.7","v9.1.7","v9.2.1"],"title":"[Discover][APM] Add fallback to traceItems when calling useTraceWaterfall ","number":240843,"url":"https://github.com/elastic/kibana/pull/240843","mergeCommit":{"message":"[Discover][APM] Add fallback to traceItems when calling useTraceWaterfall (#240843)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/238405\n\nSince we upgraded the error handling strategy to catch Fatal React\nErrors, we’ve started seeing `TypeError: Cannot read properties of\nundefined (reading 'map')` in versions 8.19.x and 9.1.x.\n\n<img width=\"809\" height=\"121\" alt=\"Screenshot 2025-10-27 at 16 03 48\"\nsrc=\"https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8\"\n/>\n\nAfter reviewing the error stack, we found that this occurs because\n`traceItems` is occasionally arrive as `undefined`. Although TS enforces\nthat it should always be defined, a potential API malfunction may cause\nthis scenario.\n\nTo prevent users from encountering an uncontrolled error, this PR adds a\ncheck for `undefined` for `data` coming from the `useFetcher` (more\ndetails in [this\ncomment](https://github.com/elastic/kibana/pull/240843#discussion_r2469707226)).\n\nThis ensures that the UI behaves safely even if `traceItems` is\nunexpectedly `undefined`.\n\n|Before|After|\n|-|-|\n||<img\nwidth=\"1405\" height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26 04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|\n\nI also took the chance to update the UI, so the error message is more\nvisible:\n|Before|After|\n|-|-|\n|<img width=\"1405\" height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26 04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|<img width=\"1405\" height=\"966\" alt=\"Screenshot 2025-10-28 at 14 24\n51\"\nsrc=\"https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20\"\n/>|\n\nThe same error has been now added to the `TraceWaterfallEmbeddable`:\n<img width=\"1387\" height=\"135\" alt=\"Screenshot 2025-10-28 at 14 27 31\"\nsrc=\"https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf\"\n/>","sha":"7d2975b2ece67ff9b1c99be7d98bb422099065e1"}},"sourceBranch":"main","suggestedTargetBranches":["8.19","9.1"],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/240843","number":240843,"mergeCommit":{"message":"[Discover][APM] Add fallback to traceItems when calling useTraceWaterfall (#240843)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/238405\n\nSince we upgraded the error handling strategy to catch Fatal React\nErrors, we’ve started seeing `TypeError: Cannot read properties of\nundefined (reading 'map')` in versions 8.19.x and 9.1.x.\n\n<img width=\"809\" height=\"121\" alt=\"Screenshot 2025-10-27 at 16 03 48\"\nsrc=\"https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8\"\n/>\n\nAfter reviewing the error stack, we found that this occurs because\n`traceItems` is occasionally arrive as `undefined`. Although TS enforces\nthat it should always be defined, a potential API malfunction may cause\nthis scenario.\n\nTo prevent users from encountering an uncontrolled error, this PR adds a\ncheck for `undefined` for `data` coming from the `useFetcher` (more\ndetails in [this\ncomment](https://github.com/elastic/kibana/pull/240843#discussion_r2469707226)).\n\nThis ensures that the UI behaves safely even if `traceItems` is\nunexpectedly `undefined`.\n\n|Before|After|\n|-|-|\n||<img\nwidth=\"1405\" height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26 04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|\n\nI also took the chance to update the UI, so the error message is more\nvisible:\n|Before|After|\n|-|-|\n|<img width=\"1405\" height=\"968\" alt=\"Screenshot 2025-10-28 at 14 26 04\"\nsrc=\"https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064\"\n/>|<img width=\"1405\" height=\"966\" alt=\"Screenshot 2025-10-28 at 14 24\n51\"\nsrc=\"https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20\"\n/>|\n\nThe same error has been now added to the `TraceWaterfallEmbeddable`:\n<img width=\"1387\" height=\"135\" alt=\"Screenshot 2025-10-28 at 14 27 31\"\nsrc=\"https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf\"\n/>","sha":"7d2975b2ece67ff9b1c99be7d98bb422099065e1"}},{"branch":"8.19","label":"v8.19.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.1","label":"v9.1.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.2","label":"v9.2.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/241079","number":241079,"state":"OPEN"}]}] BACKPORT-->
…fall (elastic#240843) ## Summary Closes elastic#238405 Since we upgraded the error handling strategy to catch Fatal React Errors, we’ve started seeing `TypeError: Cannot read properties of undefined (reading 'map')` in versions 8.19.x and 9.1.x. <img width="809" height="121" alt="Screenshot 2025-10-27 at 16 03 48" src="https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8" /> After reviewing the error stack, we found that this occurs because `traceItems` is occasionally arrive as `undefined`. Although TS enforces that it should always be defined, a potential API malfunction may cause this scenario. To prevent users from encountering an uncontrolled error, this PR adds a check for `undefined` for `data` coming from the `useFetcher` (more details in [this comment](elastic#240843 (comment))). This ensures that the UI behaves safely even if `traceItems` is unexpectedly `undefined`. |Before|After| |-|-| ||<img width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04" src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064" />| I also took the chance to update the UI, so the error message is more visible: |Before|After| |-|-| |<img width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04" src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064" />|<img width="1405" height="966" alt="Screenshot 2025-10-28 at 14 24 51" src="https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20" />| The same error has been now added to the `TraceWaterfallEmbeddable`: <img width="1387" height="135" alt="Screenshot 2025-10-28 at 14 27 31" src="https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf" />
…fall (elastic#240843) ## Summary Closes elastic#238405 Since we upgraded the error handling strategy to catch Fatal React Errors, we’ve started seeing `TypeError: Cannot read properties of undefined (reading 'map')` in versions 8.19.x and 9.1.x. <img width="809" height="121" alt="Screenshot 2025-10-27 at 16 03 48" src="https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8" /> After reviewing the error stack, we found that this occurs because `traceItems` is occasionally arrive as `undefined`. Although TS enforces that it should always be defined, a potential API malfunction may cause this scenario. To prevent users from encountering an uncontrolled error, this PR adds a check for `undefined` for `data` coming from the `useFetcher` (more details in [this comment](elastic#240843 (comment))). This ensures that the UI behaves safely even if `traceItems` is unexpectedly `undefined`. |Before|After| |-|-| ||<img width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04" src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064" />| I also took the chance to update the UI, so the error message is more visible: |Before|After| |-|-| |<img width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04" src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064" />|<img width="1405" height="966" alt="Screenshot 2025-10-28 at 14 24 51" src="https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20" />| The same error has been now added to the `TraceWaterfallEmbeddable`: <img width="1387" height="135" alt="Screenshot 2025-10-28 at 14 27 31" src="https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf" />
…fall (elastic#240843) ## Summary Closes elastic#238405 Since we upgraded the error handling strategy to catch Fatal React Errors, we’ve started seeing `TypeError: Cannot read properties of undefined (reading 'map')` in versions 8.19.x and 9.1.x. <img width="809" height="121" alt="Screenshot 2025-10-27 at 16 03 48" src="https://github.com/user-attachments/assets/042a4118-8294-4701-8d0b-590321a2bde8" /> After reviewing the error stack, we found that this occurs because `traceItems` is occasionally arrive as `undefined`. Although TS enforces that it should always be defined, a potential API malfunction may cause this scenario. To prevent users from encountering an uncontrolled error, this PR adds a check for `undefined` for `data` coming from the `useFetcher` (more details in [this comment](elastic#240843 (comment))). This ensures that the UI behaves safely even if `traceItems` is unexpectedly `undefined`. |Before|After| |-|-| ||<img width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04" src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064" />| I also took the chance to update the UI, so the error message is more visible: |Before|After| |-|-| |<img width="1405" height="968" alt="Screenshot 2025-10-28 at 14 26 04" src="https://github.com/user-attachments/assets/1d4453df-25b5-4573-b29f-0da76f42b064" />|<img width="1405" height="966" alt="Screenshot 2025-10-28 at 14 24 51" src="https://github.com/user-attachments/assets/3426defd-58fc-4ea8-950c-1163bb11cb20" />| The same error has been now added to the `TraceWaterfallEmbeddable`: <img width="1387" height="135" alt="Screenshot 2025-10-28 at 14 27 31" src="https://github.com/user-attachments/assets/3bd01cb3-b716-4216-82de-ec02d7f01bdf" />
Summary
Closes #238405
Since we upgraded the error handling strategy to catch Fatal React Errors, we’ve started seeing
TypeError: Cannot read properties of undefined (reading 'map')in versions 8.19.x and 9.1.x.After reviewing the error stack, we found that this occurs because
traceItemsis occasionally arrive asundefined. Although TS enforces that it should always be defined, a potential API malfunction may cause this scenario.To prevent users from encountering an uncontrolled error, this PR adds a check for
undefinedfordatacoming from theuseFetcher(more details in this comment).This ensures that the UI behaves safely even if
traceItemsis unexpectedlyundefined.I also took the chance to update the UI, so the error message is more visible:
The same error has been now added to the

TraceWaterfallEmbeddable: