Skip to content

[Lens] Infinite reference accumulation#245317

Merged
nickofthyme merged 10 commits into
elastic:mainfrom
nickofthyme:fix-infinite-refs
Dec 11, 2025
Merged

[Lens] Infinite reference accumulation#245317
nickofthyme merged 10 commits into
elastic:mainfrom
nickofthyme:fix-infinite-refs

Conversation

@nickofthyme
Copy link
Copy Markdown
Contributor

@nickofthyme nickofthyme commented Dec 4, 2025

Summary

Fixes issue where Lens panels on a dashboard that have no references, like a vis with ad-hoc dataview (i.e. ES|QL), will blindly add dashboard references. But these references are not always panel-specific thus lens will absorb all dashboard references.

Details

In #239029 we moved the lens references to the server and passed them in the SO under attributes.references until the references can be properly injected into the state itself.

Previously we were filtering the panel references from the dashboard with the references from attributes.references. But with the transforms now being run on the client side code, the dashboard references can be empty, see #239029 (comment). Thus we need to merge these two reference sources.

// match references based on name, so only references associated with this lens panel are injected.
const matchedReferences: Reference[] = [];
if (Array.isArray(typedState.attributes.references)) {
typedState.attributes.references.forEach((serializableRef) => {
const internalReference = serializableRef;
const matchedReference = references.find(
(reference) => reference.name === internalReference.name
);
if (matchedReference) matchedReferences.push(matchedReference);
});
}
typedState.attributes.references = matchedReferences;
return typedState as unknown as EmbeddableStateWithType;

But additionally, the dashboard may pass the transformOut method all the unfiltered raw references when the filter references are empty.

const panelReferences = filteredReferences.length === 0 ? references : filteredReferences;

The solution is to treat the lens attributes.references as the source of truth and only use the dashboard panel references to update the id on matching references by name and type.

fixes #245283

Checklist

  • Unit or functional tests were updated or added to match the most common scenarios
  • 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.
  • 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.

@nickofthyme nickofthyme added Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// release_note:skip Skip the PR/issue when compiling release notes Feature:Lens Feature:ES|QL ES|QL related features in Kibana backport:version Backport to applied version labels labels Dec 4, 2025
@nickofthyme nickofthyme requested a review from nreese December 4, 2025 22:37
@nickofthyme nickofthyme marked this pull request as ready for review December 5, 2025 18:25
@nickofthyme nickofthyme requested a review from a team as a code owner December 5, 2025 18:25
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/kibana-visualizations (Team:Visualizations)

@nickofthyme nickofthyme changed the title [Lens] ES|QL infinite references [Lens] Infinite reference accumulation Dec 5, 2025
Comment thread x-pack/platform/plugins/shared/lens/common/references/index.ts Outdated
@nickofthyme nickofthyme enabled auto-merge (squash) December 10, 2025 17:43
Comment thread x-pack/platform/plugins/shared/lens/common/references/index.ts
@nickofthyme nickofthyme disabled auto-merge December 10, 2025 18:18
Copy link
Copy Markdown
Contributor

@nreese nreese 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 for removing dashboard specific reference name logic.

@elasticmachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #39 / serverless search UI - search features Search Playground - Saved Playgrounds Update Saved Playground should allow updating playground name
  • [job] [logs] FTR Configs #141 / Standard Product intercept page transitions transitions from one tab to another and back again will cause the intercept to be displayed if the intercept interval has elapsed on transitioning

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
lens 1.6MB 1.6MB +78.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
lens 22 23 +1

Total ESLint disabled count

id before after diff
lens 22 23 +1

History

@nickofthyme nickofthyme merged commit 9ddbf92 into elastic:main Dec 11, 2025
12 checks passed
@nickofthyme nickofthyme deleted the fix-infinite-refs branch December 11, 2025 21:13
@kibanamachine kibanamachine removed the backport:version Backport to applied version labels label Dec 11, 2025
@kibanamachine kibanamachine added the backport:skip This PR does not require backporting label Dec 11, 2025
seanrathier pushed a commit to seanrathier/kibana that referenced this pull request Dec 15, 2025
Fixes issue with some Lens panels on a dashboard that would create duplicate `references`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting Feature:ES|QL ES|QL related features in Kibana Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[dashboard][lens embeddable] ESQL panel duplicating all references on save

5 participants