[Discover] Fix Discover tab initialization
Summary
This PR fixes the Discover tab initialization logic to prevent the following:
- State leaking between tabs when switching to another tab while the previous tab is still initializing, caused by syncing tab state with global Kibana services.
- Duplicate tab initializations when switching away from and back to a tab before initialization completes, caused by the initialization logic checking for the existence of
DiscoverStateContainerinstead of a dedicated status property.
These are the main fixes:
- Move retrieving the initial URL state to the start of tab initialization before any async work in case the current tab (and URL) changes while initializing.
- Avoid the following if the current tab changes during tab initialization:
- Syncing tab state to global services, which overrides the current tab's state.
- Calling
stateContainer.actions.initializeAndSync(), which causes the wrong tab to be synced to the URL and global services. - Calling
stateContainer.actions.fetchData(true), which results in the wrong search parameters being used during data fetching.
- Stop relying on
DiscoverStateContainerto check if a tab is initialized, and instead introduce a dedicatedTabInitializationStatusto prevent duplicate initializations when switching away from and back to a tab during initialization.
Fixes #245754.
Checklist
- [ ] Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support
- [ ] Documentation was added for features that require explanation or tutorials
- [ ] Unit or functional tests were updated or added to match the most common scenarios
- [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the docker list
- [x] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The
release_note:breakinglabel should be applied in these situations. - [x] Flaky Test Runner was used on any tests changed
- [x] The PR description includes the appropriate Release Notes section, and the correct
release_note:*label is applied per the guidelines - [x] Review the backport guidelines and apply applicable
backport:*labels.
Identify risks
- This should probably be backported to 9.2 since it's a bad bug, but there are some significant changes to the tab initialization logic. We should test thoroughly for regressions before merging, and in the 9.2 backport.
Flaky Test Runner Stats
🟠 Some tests failed. - kibana-flaky-test-suite-runner#10030
[✅] src/platform/test/functional/apps/discover/tabs/config.ts: 25/25 tests passed. [❌] src/platform/test/functional/apps/discover/tabs2/config.ts: 0/25 tests passed. [✅] src/platform/test/functional/apps/discover/tabs3/config.ts: 25/25 tests passed. [✅] src/platform/test/functional/apps/discover/tabs_disabled/config.ts: 25/25 tests passed.
Flaky Test Runner Stats
🎉 All tests passed! - kibana-flaky-test-suite-runner#10031
[✅] src/platform/test/functional/apps/discover/tabs_disabled/config.ts: 25/25 tests passed. [✅] src/platform/test/functional/apps/discover/tabs/config.ts: 25/25 tests passed. [✅] src/platform/test/functional/apps/discover/tabs2/config.ts: 25/25 tests passed. [✅] src/platform/test/functional/apps/discover/tabs3/config.ts: 25/25 tests passed.
Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)
:yellow_heart: Build succeeded, but was flaky
- Buildkite Build
- Commit: cd8eb31b4b06085fd8fe1b0e0a22d02f4dbaaf2a
Failed CI Steps
Metrics [docs]
Async chunks
Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app
| id | before | after | diff |
|---|---|---|---|
discover |
1.3MB | 1.3MB | +1.1KB |
History
- :yellow_heart: Build #370900 was flaky 23b625eda614c72d9d218c261601582d4e961a84
- :broken_heart: Build #370887 failed b8cbf5d1a459f2bb83875044b6c9c74df900be1a
cc @davismcphee
Starting backport for target branches: 9.2
https://github.com/elastic/kibana/actions/runs/20116870797
💔 All backports failed
| Status | Branch | Result |
|---|---|---|
| ❌ | 9.2 | Backport failed because of merge conflicts |
Manual backport
To create the backport manually run:
node scripts/backport --pr 245752
Questions ?
Please refer to the Backport tool documentation
Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 245752 locally
cc: @davismcphee
💚 All backports created successfully
| Status | Branch | Result |
|---|---|---|
| ✅ | 9.2 |
Note: Successful backport PRs will be merged automatically after passing CI.
Questions ?
Please refer to the Backport tool documentation