kibana icon indicating copy to clipboard operation
kibana copied to clipboard

[Discover] Fix Discover tab initialization

Open davismcphee opened this issue 2 weeks ago • 4 comments

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 DiscoverStateContainer instead 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 DiscoverStateContainer to check if a tab is initialized, and instead introduce a dedicated TabInitializationStatus to 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:breaking label 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.

davismcphee avatar Dec 10 '25 02:12 davismcphee

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.

see run history

kibanamachine avatar Dec 10 '25 05:12 kibanamachine

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.

see run history

kibanamachine avatar Dec 10 '25 07:12 kibanamachine

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

elasticmachine avatar Dec 10 '25 13:12 elasticmachine

:yellow_heart: Build succeeded, but was flaky

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

elasticmachine avatar Dec 10 '25 21:12 elasticmachine

Starting backport for target branches: 9.2

https://github.com/elastic/kibana/actions/runs/20116870797

kibanamachine avatar Dec 10 '25 23:12 kibanamachine

💔 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

kibanamachine avatar Dec 10 '25 23:12 kibanamachine

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

kibanamachine avatar Dec 11 '25 23:12 kibanamachine

💚 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

davismcphee avatar Dec 12 '25 03:12 davismcphee