Skip to content

[Discover] Fix default app state handling when detecting unsaved changes#246664

Merged
davismcphee merged 6 commits intoelastic:mainfrom
davismcphee:fix-unsaved-changes-default-values
Dec 18, 2025
Merged

[Discover] Fix default app state handling when detecting unsaved changes#246664
davismcphee merged 6 commits intoelastic:mainfrom
davismcphee:fix-unsaved-changes-default-values

Conversation

@davismcphee
Copy link
Contributor

@davismcphee davismcphee commented Dec 17, 2025

Summary

This PR fixes an issue in Discover where default app state could trigger unsaved changes in saved Discover sessions, such as default columns applied via the defaultColumns advanced setting.

It was mostly extracted from the changes in #244686 (with a few additions I noticed while moving the code) so that it can be backported. Unfortunately it required more changes than expected in order for getInitialAppState to be useable within selectHasUnsavedChanges, since we don't have access to SavedSearch for persisted tabs when comparing.

Fixes #246798.

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
  • 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.
  • Flaky Test Runner was used on any tests changed
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines
  • Review the backport guidelines and apply applicable backport:* labels.

Identify risks

The PR has more changes than I'd generally like for a fix with backports, but the actual changes to logic are fairly minimal. Most of the changes come from switching to DiscoverSessionTab in getInitialAppState and updating tests.

@davismcphee davismcphee self-assigned this Dec 17, 2025
@davismcphee davismcphee added release_note:fix Team:DataDiscovery Discover, search (data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. t// backport:version Backport to applied version labels v9.3.0 v9.2.3 labels Dec 17, 2025
@davismcphee davismcphee force-pushed the fix-unsaved-changes-default-values branch from 5d69c06 to 6ea1677 Compare December 17, 2025 23:43
Comment on lines +368 to +377
container.savedSearchState.set(
updateSavedSearch({
savedSearch: finalSavedSearch,
dataView,
initialInternalState: undefined,
appState: currentTab.appState,
globalState: currentTab.globalState,
services,
})
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling updateSavedSearch now because some useUnsavedChanges tests were breaking after updating getInitialAppState, since savedSearchState was technically out of sync when using getDiscoverStateMock.

Wasn't necessary in the other PR because the tests were updated to use getDiscoverInternalStateMock there.

const dataViewCreateSpy = jest.spyOn(services.dataViews, 'create');
const dataViewsClearCacheSpy = jest.spyOn(services.dataViews, 'clearInstanceCache');
const savedSearch = { ...savedSearchMock, timeRestore: false };
savedSearch.searchSource.setField('filter', []);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was added because calling updateSavedSearch in getDiscoverStateMock causes filter to default to [], which breaks tests in this file that use savedSearch for comparisons.

Won't be an issue when these tests are migrated to use getDiscoverInternalStateMock which properly initializes state in the same way the app does.

Comment on lines +218 to +221
// If changing tabs, stop syncing the current tab before updating any URL state
if (selectedTabHasChanged) {
currentTabStateContainer?.actions.stopSyncing();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If tabsStorageManager.pushSelectedTabIdToUrl() triggered a change to appState before we stopped syncing the previous tab, it could technically leak state.

This was not actually causing issues during runtime afaict, but was technically incorrect, and did cause a Jest test to fail when state was out of sync due to getDiscoverStateMock. Probably best to fix it regardless.

@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

🎉 All tests passed! - kibana-flaky-test-suite-runner#10150

[✅] src/platform/test/functional/apps/discover/tabs2/config.ts: 25/25 tests passed.

see run history

@davismcphee davismcphee marked this pull request as ready for review December 18, 2025 03:03
@davismcphee davismcphee requested review from a team as code owners December 18, 2025 03:03
@elasticmachine
Copy link
Contributor

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

Copy link
Contributor

@jughosta jughosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! 👍

@elasticmachine
Copy link
Contributor

elasticmachine commented Dec 18, 2025

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #40 / discover/esql Index editor allows to save an edition without closing the flyout
  • [job] [logs] FTR Configs #130 / Endpoint plugin @ess @serverless @skipInServerlessMKI test metadata apis list endpoints GET route "before all" hook for "should return one entry for each host with default paging"
  • [job] [logs] Jest Tests #12 / ES deprecations table pagination allows the number of viewable rows to change
  • [job] [logs] Jest Tests #12 / ES deprecations table pagination allows the number of viewable rows to change
  • [job] [logs] Jest Tests #12 / ES deprecations table pagination maintains correct row state across pagination
  • [job] [logs] Jest Tests #12 / ES deprecations table pagination shows the correct number of pages and deprecations per page
  • [job] [logs] Jest Tests #12 / ES deprecations table pagination updates pagination on search
  • [job] [logs] Jest Tests #12 / ES deprecations table pagination updates pagination when filters change
  • [job] [logs] FTR Configs #116 / Ingest pipelines app Ingest Pipelines Pipelines list Pipelines tree Clicking on tree nodes open details panel for selected pipeline
  • [job] [logs] Jest Tests #12 / saveDiscoverSession should call saveDiscoverSession with the expected params
  • [job] [logs] Jest Tests #12 / saveDiscoverSession should call saveDiscoverSession with the expected params

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
discover 1954 1953 -1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
apm 2.8MB 2.8MB +21.0B
discover 1.3MB 1.3MB +614.0B
fleet 2.1MB 2.1MB +21.0B
infra 1.1MB 1.1MB +21.0B
logsShared 201.0KB 201.0KB +21.0B
total +698.0B

History

cc @davismcphee

@davismcphee davismcphee merged commit 34abb2d into elastic:main Dec 18, 2025
13 checks passed
@davismcphee davismcphee deleted the fix-unsaved-changes-default-values branch December 18, 2025 21:12
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 9.2, 9.3

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

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
9.2 Backport failed because of merge conflicts
9.3 Backport failed because of merge conflicts

You might need to backport the following PRs to 9.3:
- [Obs AI] Custom attachment icons and labels (#246780)
- [o11y ai] get_hosts tool: Automatically detect schema (ecs/semconv) (#246756)
- chore(slo): Create slo shared plugin (#246928)
- feat(slo): introduce SLO templates API (#246778)
- chore(slo): slo definition repository cleanup (#246445)
- [Metrics][Discover] ESQL Results Based Metrics Grid (#245011)

Manual backport

To create the backport manually run:

node scripts/backport --pr 246664

Questions ?

Please refer to the Backport tool documentation

davismcphee added a commit to davismcphee/kibana that referenced this pull request Dec 18, 2025
…ges (elastic#246664)

## Summary

This PR fixes an issue in Discover where default app state could trigger
unsaved changes in saved Discover sessions, such as default columns
applied via the `defaultColumns` advanced setting.

It was mostly extracted from the changes in elastic#244686 (with a few
additions I noticed while moving the code) so that it can be backported.
Unfortunately it required more changes than expected in order for
`getInitialAppState` to be useable within `selectHasUnsavedChanges`,
since we don't have access to `SavedSearch` for persisted tabs when
comparing.

Fixes elastic#246798.

### Checklist

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
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](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [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](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) 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](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
- [x] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.

### Identify risks

The PR has more changes than I'd generally like for a fix with
backports, but the actual changes to logic are fairly minimal. Most of
the changes come from switching to `DiscoverSessionTab` in
`getInitialAppState` and updating tests.

(cherry picked from commit 34abb2d)

# Conflicts:
#	src/platform/plugins/shared/discover/public/application/main/state_management/utils/get_state_defaults.ts
@davismcphee
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
9.3
9.2

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

davismcphee added a commit to davismcphee/kibana that referenced this pull request Dec 19, 2025
…ges (elastic#246664)

## Summary

This PR fixes an issue in Discover where default app state could trigger
unsaved changes in saved Discover sessions, such as default columns
applied via the `defaultColumns` advanced setting.

It was mostly extracted from the changes in elastic#244686 (with a few
additions I noticed while moving the code) so that it can be backported.
Unfortunately it required more changes than expected in order for
`getInitialAppState` to be useable within `selectHasUnsavedChanges`,
since we don't have access to `SavedSearch` for persisted tabs when
comparing.

Fixes elastic#246798.

### Checklist

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
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](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [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](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) 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](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
- [x] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.

### Identify risks

The PR has more changes than I'd generally like for a fix with
backports, but the actual changes to logic are fairly minimal. Most of
the changes come from switching to `DiscoverSessionTab` in
`getInitialAppState` and updating tests.

(cherry picked from commit 34abb2d)

# Conflicts:
#	src/platform/plugins/shared/discover/public/__mocks__/discover_state.mock.ts
#	src/platform/plugins/shared/discover/public/application/main/state_management/discover_state.test.ts
#	src/platform/plugins/shared/discover/public/application/main/state_management/redux/actions/reset_discover_session.ts
#	src/platform/plugins/shared/discover/public/application/main/state_management/redux/utils.test.ts
#	src/platform/plugins/shared/discover/public/application/main/state_management/utils/get_initial_app_state.test.ts
#	src/platform/plugins/shared/discover/public/application/main/state_management/utils/get_initial_app_state.ts
#	src/platform/plugins/shared/discover/public/application/main/state_management/utils/get_state_defaults.ts
#	src/platform/plugins/shared/discover/public/customizations/customization_provider.ts
davismcphee added a commit that referenced this pull request Dec 19, 2025
…d changes (#246664) (#246982)

# Backport

This will backport the following commits from `main` to `9.3`:
- [[Discover] Fix default app state handling when detecting unsaved
changes (#246664)](#246664)

<!--- Backport version: 10.2.0 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Davis
McPhee","email":"davis.mcphee@elastic.co"},"sourceCommit":{"committedDate":"2025-12-18T21:12:10Z","message":"[Discover]
Fix default app state handling when detecting unsaved changes
(#246664)\n\n## Summary\n\nThis PR fixes an issue in Discover where
default app state could trigger\nunsaved changes in saved Discover
sessions, such as default columns\napplied via the `defaultColumns`
advanced setting.\n\nIt was mostly extracted from the changes in #244686
(with a few\nadditions I noticed while moving the code) so that it can
be backported.\nUnfortunately it required more changes than expected in
order for\n`getInitialAppState` to be useable within
`selectHasUnsavedChanges`,\nsince we don't have access to `SavedSearch`
for persisted tabs when\ncomparing.\n\nFixes #246798.\n\n###
Checklist\n\n- [ ] Any text added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[
]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [ ] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n-
[x] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.\n- [x] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed\n- [x] The PR description includes the
appropriate Release Notes section,\nand the correct `release_note:*`
label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n-
[x] Review the
[backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand
apply applicable `backport:*` labels.\n\n### Identify risks\n\nThe PR
has more changes than I'd generally like for a fix with\nbackports, but
the actual changes to logic are fairly minimal. Most of\nthe changes
come from switching to `DiscoverSessionTab` in\n`getInitialAppState` and
updating
tests.","sha":"34abb2d23e012ddbefc4655414727bc1096729f1","branchLabelMapping":{"^v9.4.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:DataDiscovery","backport:version","v9.3.0","v9.4.0","v9.2.3"],"title":"[Discover]
Fix default app state handling when detecting unsaved
changes","number":246664,"url":"https://github.com/elastic/kibana/pull/246664","mergeCommit":{"message":"[Discover]
Fix default app state handling when detecting unsaved changes
(#246664)\n\n## Summary\n\nThis PR fixes an issue in Discover where
default app state could trigger\nunsaved changes in saved Discover
sessions, such as default columns\napplied via the `defaultColumns`
advanced setting.\n\nIt was mostly extracted from the changes in #244686
(with a few\nadditions I noticed while moving the code) so that it can
be backported.\nUnfortunately it required more changes than expected in
order for\n`getInitialAppState` to be useable within
`selectHasUnsavedChanges`,\nsince we don't have access to `SavedSearch`
for persisted tabs when\ncomparing.\n\nFixes #246798.\n\n###
Checklist\n\n- [ ] Any text added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[
]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [ ] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n-
[x] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.\n- [x] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed\n- [x] The PR description includes the
appropriate Release Notes section,\nand the correct `release_note:*`
label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n-
[x] Review the
[backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand
apply applicable `backport:*` labels.\n\n### Identify risks\n\nThe PR
has more changes than I'd generally like for a fix with\nbackports, but
the actual changes to logic are fairly minimal. Most of\nthe changes
come from switching to `DiscoverSessionTab` in\n`getInitialAppState` and
updating
tests.","sha":"34abb2d23e012ddbefc4655414727bc1096729f1"}},"sourceBranch":"main","suggestedTargetBranches":["9.3","9.2"],"targetPullRequestStates":[{"branch":"9.3","label":"v9.3.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.4.0","branchLabelMappingKey":"^v9.4.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/246664","number":246664,"mergeCommit":{"message":"[Discover]
Fix default app state handling when detecting unsaved changes
(#246664)\n\n## Summary\n\nThis PR fixes an issue in Discover where
default app state could trigger\nunsaved changes in saved Discover
sessions, such as default columns\napplied via the `defaultColumns`
advanced setting.\n\nIt was mostly extracted from the changes in #244686
(with a few\nadditions I noticed while moving the code) so that it can
be backported.\nUnfortunately it required more changes than expected in
order for\n`getInitialAppState` to be useable within
`selectHasUnsavedChanges`,\nsince we don't have access to `SavedSearch`
for persisted tabs when\ncomparing.\n\nFixes #246798.\n\n###
Checklist\n\n- [ ] Any text added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[
]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [ ] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n-
[x] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.\n- [x] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed\n- [x] The PR description includes the
appropriate Release Notes section,\nand the correct `release_note:*`
label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n-
[x] Review the
[backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand
apply applicable `backport:*` labels.\n\n### Identify risks\n\nThe PR
has more changes than I'd generally like for a fix with\nbackports, but
the actual changes to logic are fairly minimal. Most of\nthe changes
come from switching to `DiscoverSessionTab` in\n`getInitialAppState` and
updating
tests.","sha":"34abb2d23e012ddbefc4655414727bc1096729f1"}},{"branch":"9.2","label":"v9.2.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Dec 19, 2025
@kibanamachine
Copy link
Contributor

Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync.
cc: @davismcphee

1 similar comment
@kibanamachine
Copy link
Contributor

Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync.
cc: @davismcphee

davismcphee added a commit that referenced this pull request Dec 23, 2025
…d changes (#246664) (#246988)

# Backport

This will backport the following commits from `main` to `9.2`:
- [[Discover] Fix default app state handling when detecting unsaved
changes (#246664)](#246664)

<!--- Backport version: 10.2.0 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Davis
McPhee","email":"davis.mcphee@elastic.co"},"sourceCommit":{"committedDate":"2025-12-18T21:12:10Z","message":"[Discover]
Fix default app state handling when detecting unsaved changes
(#246664)\n\n## Summary\n\nThis PR fixes an issue in Discover where
default app state could trigger\nunsaved changes in saved Discover
sessions, such as default columns\napplied via the `defaultColumns`
advanced setting.\n\nIt was mostly extracted from the changes in #244686
(with a few\nadditions I noticed while moving the code) so that it can
be backported.\nUnfortunately it required more changes than expected in
order for\n`getInitialAppState` to be useable within
`selectHasUnsavedChanges`,\nsince we don't have access to `SavedSearch`
for persisted tabs when\ncomparing.\n\nFixes #246798.\n\n###
Checklist\n\n- [ ] Any text added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[
]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [ ] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n-
[x] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.\n- [x] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed\n- [x] The PR description includes the
appropriate Release Notes section,\nand the correct `release_note:*`
label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n-
[x] Review the
[backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand
apply applicable `backport:*` labels.\n\n### Identify risks\n\nThe PR
has more changes than I'd generally like for a fix with\nbackports, but
the actual changes to logic are fairly minimal. Most of\nthe changes
come from switching to `DiscoverSessionTab` in\n`getInitialAppState` and
updating
tests.","sha":"34abb2d23e012ddbefc4655414727bc1096729f1","branchLabelMapping":{"^v9.4.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:DataDiscovery","backport:version","v9.3.0","v9.4.0","v9.2.3"],"title":"[Discover]
Fix default app state handling when detecting unsaved
changes","number":246664,"url":"https://github.com/elastic/kibana/pull/246664","mergeCommit":{"message":"[Discover]
Fix default app state handling when detecting unsaved changes
(#246664)\n\n## Summary\n\nThis PR fixes an issue in Discover where
default app state could trigger\nunsaved changes in saved Discover
sessions, such as default columns\napplied via the `defaultColumns`
advanced setting.\n\nIt was mostly extracted from the changes in #244686
(with a few\nadditions I noticed while moving the code) so that it can
be backported.\nUnfortunately it required more changes than expected in
order for\n`getInitialAppState` to be useable within
`selectHasUnsavedChanges`,\nsince we don't have access to `SavedSearch`
for persisted tabs when\ncomparing.\n\nFixes #246798.\n\n###
Checklist\n\n- [ ] Any text added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[
]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [ ] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n-
[x] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.\n- [x] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed\n- [x] The PR description includes the
appropriate Release Notes section,\nand the correct `release_note:*`
label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n-
[x] Review the
[backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand
apply applicable `backport:*` labels.\n\n### Identify risks\n\nThe PR
has more changes than I'd generally like for a fix with\nbackports, but
the actual changes to logic are fairly minimal. Most of\nthe changes
come from switching to `DiscoverSessionTab` in\n`getInitialAppState` and
updating
tests.","sha":"34abb2d23e012ddbefc4655414727bc1096729f1"}},"sourceBranch":"main","suggestedTargetBranches":["9.3","9.2"],"targetPullRequestStates":[{"branch":"9.3","label":"v9.3.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.4.0","branchLabelMappingKey":"^v9.4.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/246664","number":246664,"mergeCommit":{"message":"[Discover]
Fix default app state handling when detecting unsaved changes
(#246664)\n\n## Summary\n\nThis PR fixes an issue in Discover where
default app state could trigger\nunsaved changes in saved Discover
sessions, such as default columns\napplied via the `defaultColumns`
advanced setting.\n\nIt was mostly extracted from the changes in #244686
(with a few\nadditions I noticed while moving the code) so that it can
be backported.\nUnfortunately it required more changes than expected in
order for\n`getInitialAppState` to be useable within
`selectHasUnsavedChanges`,\nsince we don't have access to `SavedSearch`
for persisted tabs when\ncomparing.\n\nFixes #246798.\n\n###
Checklist\n\n- [ ] Any text added follows [EUI's
writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\nsentence case text and includes
[i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n-
[
]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas
added for features that require explanation or tutorials\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common scenarios\n- [ ] If a plugin
configuration key changed, check if it needs to be\nallowlisted in the
cloud and added to the
[docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n-
[x] This was checked for breaking HTTP API changes, and any
breaking\nchanges have been approved by the breaking-change committee.
The\n`release_note:breaking` label should be applied in these
situations.\n- [x] [Flaky
Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\nused on any tests changed\n- [x] The PR description includes the
appropriate Release Notes section,\nand the correct `release_note:*`
label is applied per
the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n-
[x] Review the
[backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand
apply applicable `backport:*` labels.\n\n### Identify risks\n\nThe PR
has more changes than I'd generally like for a fix with\nbackports, but
the actual changes to logic are fairly minimal. Most of\nthe changes
come from switching to `DiscoverSessionTab` in\n`getInitialAppState` and
updating
tests.","sha":"34abb2d23e012ddbefc4655414727bc1096729f1"}},{"branch":"9.2","label":"v9.2.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: Matthias Polman <matthias.wilhelm@elastic.co>
@kibanamachine kibanamachine added v9.2.4 and removed backport missing Added to PRs automatically when the are determined to be missing a backport. labels Dec 23, 2025
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Jan 6, 2026
…ges (elastic#246664)

## Summary

This PR fixes an issue in Discover where default app state could trigger
unsaved changes in saved Discover sessions, such as default columns
applied via the `defaultColumns` advanced setting.

It was mostly extracted from the changes in elastic#244686 (with a few
additions I noticed while moving the code) so that it can be backported.
Unfortunately it required more changes than expected in order for
`getInitialAppState` to be useable within `selectHasUnsavedChanges`,
since we don't have access to `SavedSearch` for persisted tabs when
comparing.

Fixes elastic#246798.

### Checklist

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
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](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [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](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) 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](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
- [x] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.

### Identify risks

The PR has more changes than I'd generally like for a fix with
backports, but the actual changes to logic are fairly minimal. Most of
the changes come from switching to `DiscoverSessionTab` in
`getInitialAppState` and updating tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels release_note:fix Team:DataDiscovery Discover, search (data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. t// v9.2.3 v9.2.4 v9.3.0 v9.4.0

5 participants