diff --git a/x-pack/platform/plugins/shared/lens/public/react_embeddable/initializers/initialize_integrations.test.ts b/x-pack/platform/plugins/shared/lens/public/react_embeddable/initializers/initialize_integrations.test.ts index 97ead5c8cbfd2..ce9ae21d86848 100644 --- a/x-pack/platform/plugins/shared/lens/public/react_embeddable/initializers/initialize_integrations.test.ts +++ b/x-pack/platform/plugins/shared/lens/public/react_embeddable/initializers/initialize_integrations.test.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { faker } from '@faker-js/faker'; import { createEmptyLensState } from '../helper'; import { makeEmbeddableServices, getLensRuntimeStateMock } from '../mocks'; import { LensRuntimeState } from '../types'; @@ -55,5 +56,15 @@ describe('Dashboard services API', () => { // * references should be at root level expect(references).toEqual(attributes.references); }); + + it('should remove the searchSessionId from the serializedState', async () => { + const attributes = createAttributesWithReferences(); + const api = setupIntegrationsApi({ + attributes, + searchSessionId: faker.string.uuid(), + }); + const { rawState } = api.serializeState(); + expect('searchSessionId' in rawState).toBeFalsy(); + }); }); }); diff --git a/x-pack/platform/plugins/shared/lens/public/react_embeddable/initializers/initialize_integrations.ts b/x-pack/platform/plugins/shared/lens/public/react_embeddable/initializers/initialize_integrations.ts index 302433a143095..1fb7556071fcf 100644 --- a/x-pack/platform/plugins/shared/lens/public/react_embeddable/initializers/initialize_integrations.ts +++ b/x-pack/platform/plugins/shared/lens/public/react_embeddable/initializers/initialize_integrations.ts @@ -10,12 +10,27 @@ import { getLanguageDisplayName, isOfAggregateQueryType, } from '@kbn/es-query'; -import { noop } from 'lodash'; +import { noop, omit } from 'lodash'; import type { HasSerializableState } from '@kbn/presentation-publishing'; +import { SavedObjectReference } from '@kbn/core/types'; import { emptySerializer, isTextBasedLanguage } from '../helper'; -import type { GetStateType, LensEmbeddableStartServices } from '../types'; +import type { GetStateType, LensEmbeddableStartServices, LensRuntimeState } from '../types'; import type { IntegrationCallbacks } from '../types'; +function cleanupSerializedState({ + rawState, + references, +}: { + rawState: LensRuntimeState; + references: SavedObjectReference[]; +}) { + const cleanedState = omit(rawState, 'searchSessionId'); + return { + rawState: cleanedState, + references, + }; +} + export function initializeIntegrations( getLatestState: GetStateType, { attributeService }: LensEmbeddableStartServices @@ -43,7 +58,9 @@ export function initializeIntegrations( */ serializeState: () => { const currentState = getLatestState(); - const cleanedState = attributeService.extractReferences(currentState); + const cleanedState = cleanupSerializedState( + attributeService.extractReferences(currentState) + ); if (cleanedState.rawState.savedObjectId) { return { ...cleanedState, rawState: { ...cleanedState.rawState, attributes: undefined } }; }