diff --git a/docs/development/plugins/kibana_utils/public/state_sync/kibana-plugin-plugins-kibana_utils-public-state_sync.ikbnurlstatestorage.cancel.md b/docs/development/plugins/kibana_utils/public/state_sync/kibana-plugin-plugins-kibana_utils-public-state_sync.ikbnurlstatestorage.cancel.md
new file mode 100644
index 0000000000000..ed78bc0169ebf
--- /dev/null
+++ b/docs/development/plugins/kibana_utils/public/state_sync/kibana-plugin-plugins-kibana_utils-public-state_sync.ikbnurlstatestorage.cancel.md
@@ -0,0 +1,13 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-kibana\_utils-public-state\_sync](./kibana-plugin-plugins-kibana_utils-public-state_sync.md) > [IKbnUrlStateStorage](./kibana-plugin-plugins-kibana_utils-public-state_sync.ikbnurlstatestorage.md) > [cancel](./kibana-plugin-plugins-kibana_utils-public-state_sync.ikbnurlstatestorage.cancel.md)
+
+## IKbnUrlStateStorage.cancel property
+
+Cancels any pending url updates
+
+Signature:
+
+```typescript
+cancel: () => void;
+```
diff --git a/docs/development/plugins/kibana_utils/public/state_sync/kibana-plugin-plugins-kibana_utils-public-state_sync.ikbnurlstatestorage.md b/docs/development/plugins/kibana_utils/public/state_sync/kibana-plugin-plugins-kibana_utils-public-state_sync.ikbnurlstatestorage.md
index 7fb8717fae003..be77e5887e98f 100644
--- a/docs/development/plugins/kibana_utils/public/state_sync/kibana-plugin-plugins-kibana_utils-public-state_sync.ikbnurlstatestorage.md
+++ b/docs/development/plugins/kibana_utils/public/state_sync/kibana-plugin-plugins-kibana_utils-public-state_sync.ikbnurlstatestorage.md
@@ -20,6 +20,7 @@ export interface IKbnUrlStateStorage extends IStateStorage
| Property | Type | Description |
| --- | --- | --- |
+| [cancel](./kibana-plugin-plugins-kibana_utils-public-state_sync.ikbnurlstatestorage.cancel.md) | () => void
| Cancels any pending url updates |
| [change$](./kibana-plugin-plugins-kibana_utils-public-state_sync.ikbnurlstatestorage.change_.md) | <State = unknown>(key: string) => Observable<State | null>
| |
| [get](./kibana-plugin-plugins-kibana_utils-public-state_sync.ikbnurlstatestorage.get.md) | <State = unknown>(key: string) => State | null
| |
| [kbnUrlControls](./kibana-plugin-plugins-kibana_utils-public-state_sync.ikbnurlstatestorage.kbnurlcontrols.md) | IKbnUrlControls
| Lower level wrapper around history library that handles batching multiple URL updates into one history change |
diff --git a/src/plugins/dashboard/public/application/listing/__snapshots__/dashboard_listing.test.tsx.snap b/src/plugins/dashboard/public/application/listing/__snapshots__/dashboard_listing.test.tsx.snap
index faec6b4f6f24b..cd9df989c0039 100644
--- a/src/plugins/dashboard/public/application/listing/__snapshots__/dashboard_listing.test.tsx.snap
+++ b/src/plugins/dashboard/public/application/listing/__snapshots__/dashboard_listing.test.tsx.snap
@@ -4,6 +4,7 @@ exports[`after fetch When given a title that matches multiple dashboards, filter
ISessionSt
// @public
export interface IKbnUrlStateStorage extends IStateStorage {
+ cancel: () => void;
// (undocumented)
change$: (key: string) => Observable;
// (undocumented)
diff --git a/src/plugins/kibana_utils/public/state_sync/state_sync.test.ts b/src/plugins/kibana_utils/public/state_sync/state_sync.test.ts
index 890de8f6ed6a1..982d25425687f 100644
--- a/src/plugins/kibana_utils/public/state_sync/state_sync.test.ts
+++ b/src/plugins/kibana_utils/public/state_sync/state_sync.test.ts
@@ -290,7 +290,7 @@ describe('state_sync', () => {
expect(history.length).toBe(startHistoryLength);
expect(getCurrentUrl()).toMatchInlineSnapshot(`"/"`);
- urlSyncStrategy.kbnUrlControls.cancel();
+ urlSyncStrategy.cancel();
expect(history.length).toBe(startHistoryLength);
expect(getCurrentUrl()).toMatchInlineSnapshot(`"/"`);
@@ -303,6 +303,32 @@ describe('state_sync', () => {
stop();
});
+ it('cancels pending URL updates when sync stops', async () => {
+ const { stop, start } = syncStates([
+ {
+ stateContainer: withDefaultState(container, defaultState),
+ storageKey: key,
+ stateStorage: urlSyncStrategy,
+ },
+ ]);
+ start();
+
+ const startHistoryLength = history.length;
+ container.transitions.add({ id: 2, text: '2', completed: false });
+ container.transitions.add({ id: 3, text: '3', completed: false });
+ container.transitions.completeAll();
+
+ expect(history.length).toBe(startHistoryLength);
+ expect(getCurrentUrl()).toMatchInlineSnapshot(`"/"`);
+
+ stop();
+
+ await tick();
+
+ expect(history.length).toBe(startHistoryLength);
+ expect(getCurrentUrl()).toMatchInlineSnapshot(`"/"`);
+ });
+
it("should preserve reference to unchanged state slices if them didn't change", async () => {
const otherUnchangedSlice = { a: 'test' };
const oldState = {
diff --git a/src/plugins/kibana_utils/public/state_sync/state_sync_state_storage/create_kbn_url_state_storage.test.ts b/src/plugins/kibana_utils/public/state_sync/state_sync_state_storage/create_kbn_url_state_storage.test.ts
index 037c6f9fc666d..58840331a3134 100644
--- a/src/plugins/kibana_utils/public/state_sync/state_sync_state_storage/create_kbn_url_state_storage.test.ts
+++ b/src/plugins/kibana_utils/public/state_sync/state_sync_state_storage/create_kbn_url_state_storage.test.ts
@@ -51,7 +51,7 @@ describe('KbnUrlStateStorage', () => {
const key = '_s';
const pr = urlStateStorage.set(key, state);
expect(getCurrentUrl()).toMatchInlineSnapshot(`"/"`);
- urlStateStorage.kbnUrlControls.cancel();
+ urlStateStorage.cancel();
await pr;
expect(getCurrentUrl()).toMatchInlineSnapshot(`"/"`);
expect(urlStateStorage.get(key)).toEqual(null);
diff --git a/src/plugins/kibana_utils/public/state_sync/state_sync_state_storage/create_kbn_url_state_storage.ts b/src/plugins/kibana_utils/public/state_sync/state_sync_state_storage/create_kbn_url_state_storage.ts
index 0935ecd20111f..591605c22db24 100644
--- a/src/plugins/kibana_utils/public/state_sync/state_sync_state_storage/create_kbn_url_state_storage.ts
+++ b/src/plugins/kibana_utils/public/state_sync/state_sync_state_storage/create_kbn_url_state_storage.ts
@@ -39,6 +39,11 @@ export interface IKbnUrlStateStorage extends IStateStorage {
get: (key: string) => State | null;
change$: (key: string) => Observable;
+ /**
+ * Cancels any pending url updates
+ */
+ cancel: () => void;
+
/**
* Lower level wrapper around history library that handles batching multiple URL updates into one history change
*/
@@ -108,6 +113,9 @@ export const createKbnUrlStateStorage = (
}),
share()
),
+ cancel() {
+ url.cancel();
+ },
kbnUrlControls: url,
};
};