Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.x] [Embeddable] Avoid rerendering loop due to search context reload (
#203150) (#203818) # Backport This will backport the following commits from `main` to `8.x`: - [[Embeddable] Avoid rerendering loop due to search context reload (#203150)](#203150) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Marco Liberati","email":"dej611@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-12-11T15:03:36Z","message":"[Embeddable] Avoid rerendering loop due to search context reload (#203150)\n\n## Summary\r\n\r\nFixes #202266\r\n\r\nThis PR fixes the underline rerendering issue at the `useSearchApi` hook\r\nlevel, so any embeddable component who uses this hook would benefit from\r\nthe fix.\r\n\r\nIdeally the props passed to the Lens component should be memoized, but\r\nthis assumption would break many integrations as the previous embeddable\r\ncomponent did take care of filtering duplicates.\r\nTo test this:\r\n* Go to `Observability > Alerts > Manage rules` and `Add Rule`, pick the\r\n`Custom threshold` option and verify the infinite reload does not happen\r\n\r\nOnce fixed this, another problem bubbled up with the brushing use case:\r\nwhen brushing a chart the chart was always one time range step behind.\r\nThe other bug was due to the `fetch$(api)` function propagating a stale\r\n`data` search context who the Lens embeddable was relying on.\r\nTo solve this other problem the following changes have been applied:\r\n* read the `searchSessionId` from the `api` directly (used for\r\n`autoRefresh`)\r\n* make sure to test the `Refresh` feature with both relative and\r\nabsolute time ranges\r\n* read the `search context` from the `parentApi` directly if implements\r\nthe `unifiedSearch` API\r\n* to test this, brush and check that the final time range matches the\r\ncorrect time range\r\n\r\n**Note**: the fundamental issue for the latter is `fetch# Backport This will backport the following commits from `main` to `8.x`: - [[Embeddable] Avoid rerendering loop due to search context reload (#203150)](#203150) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT not emitting\r\nthe up-to-date `data` when the parentApi search context updates. The\r\nretrieved `data` is stale and one step behind, so it is not reliable. cc\r\n@elastic/kibana-presentation\r\n\r\nAs @ThomThomson noticed in his test failure investigation another issue\r\nwas found in this PR due to the wrong handling of the searchSessionId\r\nwithin the Observability page (for more details see [his\r\nanalysis](https://github.com/elastic/kibana/pull/203150#issuecomment-2524080129)).\r\n@markov00 and @crespocarlos helped risolve this problem with some\r\nadditional changes on the Observability side of things: this will lead\r\nto some extra searchSessionId to be created, which will be eventually\r\nsolved by Observability team [shortly moving away from the\r\n`searchSessionId`\r\nmechanism](https://github.com/elastic/kibana/issues/203412)\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Marco Vettorello <marco.vettorello@elastic.co>\r\nCo-authored-by: Carlos Crespo <crespocarlos@users.noreply.github.com>","sha":"d4194ba5eb5a72960dad00cf956d9ea6e31219e0","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Presentation","v9.0.0","backport:prev-minor","Feature:Embeddables","ci:project-deploy-observability","Team:obs-ux-management"],"title":"[Embeddable] Avoid rerendering loop due to search context reload","number":203150,"url":"https://github.com/elastic/kibana/pull/203150","mergeCommit":{"message":"[Embeddable] Avoid rerendering loop due to search context reload (#203150)\n\n## Summary\r\n\r\nFixes #202266\r\n\r\nThis PR fixes the underline rerendering issue at the `useSearchApi` hook\r\nlevel, so any embeddable component who uses this hook would benefit from\r\nthe fix.\r\n\r\nIdeally the props passed to the Lens component should be memoized, but\r\nthis assumption would break many integrations as the previous embeddable\r\ncomponent did take care of filtering duplicates.\r\nTo test this:\r\n* Go to `Observability > Alerts > Manage rules` and `Add Rule`, pick the\r\n`Custom threshold` option and verify the infinite reload does not happen\r\n\r\nOnce fixed this, another problem bubbled up with the brushing use case:\r\nwhen brushing a chart the chart was always one time range step behind.\r\nThe other bug was due to the `fetch$(api)` function propagating a stale\r\n`data` search context who the Lens embeddable was relying on.\r\nTo solve this other problem the following changes have been applied:\r\n* read the `searchSessionId` from the `api` directly (used for\r\n`autoRefresh`)\r\n* make sure to test the `Refresh` feature with both relative and\r\nabsolute time ranges\r\n* read the `search context` from the `parentApi` directly if implements\r\nthe `unifiedSearch` API\r\n* to test this, brush and check that the final time range matches the\r\ncorrect time range\r\n\r\n**Note**: the fundamental issue for the latter is `fetch# Backport This will backport the following commits from `main` to `8.x`: - [[Embeddable] Avoid rerendering loop due to search context reload (#203150)](#203150) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT not emitting\r\nthe up-to-date `data` when the parentApi search context updates. The\r\nretrieved `data` is stale and one step behind, so it is not reliable. cc\r\n@elastic/kibana-presentation\r\n\r\nAs @ThomThomson noticed in his test failure investigation another issue\r\nwas found in this PR due to the wrong handling of the searchSessionId\r\nwithin the Observability page (for more details see [his\r\nanalysis](https://github.com/elastic/kibana/pull/203150#issuecomment-2524080129)).\r\n@markov00 and @crespocarlos helped risolve this problem with some\r\nadditional changes on the Observability side of things: this will lead\r\nto some extra searchSessionId to be created, which will be eventually\r\nsolved by Observability team [shortly moving away from the\r\n`searchSessionId`\r\nmechanism](https://github.com/elastic/kibana/issues/203412)\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Marco Vettorello <marco.vettorello@elastic.co>\r\nCo-authored-by: Carlos Crespo <crespocarlos@users.noreply.github.com>","sha":"d4194ba5eb5a72960dad00cf956d9ea6e31219e0"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/203150","number":203150,"mergeCommit":{"message":"[Embeddable] Avoid rerendering loop due to search context reload (#203150)\n\n## Summary\r\n\r\nFixes #202266\r\n\r\nThis PR fixes the underline rerendering issue at the `useSearchApi` hook\r\nlevel, so any embeddable component who uses this hook would benefit from\r\nthe fix.\r\n\r\nIdeally the props passed to the Lens component should be memoized, but\r\nthis assumption would break many integrations as the previous embeddable\r\ncomponent did take care of filtering duplicates.\r\nTo test this:\r\n* Go to `Observability > Alerts > Manage rules` and `Add Rule`, pick the\r\n`Custom threshold` option and verify the infinite reload does not happen\r\n\r\nOnce fixed this, another problem bubbled up with the brushing use case:\r\nwhen brushing a chart the chart was always one time range step behind.\r\nThe other bug was due to the `fetch$(api)` function propagating a stale\r\n`data` search context who the Lens embeddable was relying on.\r\nTo solve this other problem the following changes have been applied:\r\n* read the `searchSessionId` from the `api` directly (used for\r\n`autoRefresh`)\r\n* make sure to test the `Refresh` feature with both relative and\r\nabsolute time ranges\r\n* read the `search context` from the `parentApi` directly if implements\r\nthe `unifiedSearch` API\r\n* to test this, brush and check that the final time range matches the\r\ncorrect time range\r\n\r\n**Note**: the fundamental issue for the latter is `fetch# Backport This will backport the following commits from `main` to `8.x`: - [[Embeddable] Avoid rerendering loop due to search context reload (#203150)](#203150) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT not emitting\r\nthe up-to-date `data` when the parentApi search context updates. The\r\nretrieved `data` is stale and one step behind, so it is not reliable. cc\r\n@elastic/kibana-presentation\r\n\r\nAs @ThomThomson noticed in his test failure investigation another issue\r\nwas found in this PR due to the wrong handling of the searchSessionId\r\nwithin the Observability page (for more details see [his\r\nanalysis](https://github.com/elastic/kibana/pull/203150#issuecomment-2524080129)).\r\n@markov00 and @crespocarlos helped risolve this problem with some\r\nadditional changes on the Observability side of things: this will lead\r\nto some extra searchSessionId to be created, which will be eventually\r\nsolved by Observability team [shortly moving away from the\r\n`searchSessionId`\r\nmechanism](https://github.com/elastic/kibana/issues/203412)\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Marco Vettorello <marco.vettorello@elastic.co>\r\nCo-authored-by: Carlos Crespo <crespocarlos@users.noreply.github.com>","sha":"d4194ba5eb5a72960dad00cf956d9ea6e31219e0"}}]}] BACKPORT--> Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
- Loading branch information