Skip to content

[Lens] move reference handling to server#239029

Merged
mistic merged 29 commits into
elastic:mainfrom
nickofthyme:lens-server-refs
Oct 31, 2025
Merged

[Lens] move reference handling to server#239029
mistic merged 29 commits into
elastic:mainfrom
nickofthyme:lens-server-refs

Conversation

@nickofthyme
Copy link
Copy Markdown
Contributor

@nickofthyme nickofthyme commented Oct 14, 2025

Summary

Move Lens reference handling to server side.

Close #221943

Details

Lens no longer relies on references from the buildEmbeddable. We now inject/extract references on the server.

Lens duplicates references in it's own serialized state so we just move them there and add the savedObjectId for by-ref Lens panels. Lens still inject these references internally by type across the Lens code.

For now we still store the references duplicated in the Lens SO state, but we can clean this up when we extract all the internal reference handling.

Checklist

@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 backport:skip This PR does not require backporting labels Oct 14, 2025
@nickofthyme nickofthyme marked this pull request as ready for review October 21, 2025 22:09
@nickofthyme nickofthyme requested a review from a team as a code owner October 21, 2025 22:09
@elasticmachine
Copy link
Copy Markdown
Contributor

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

Comment thread x-pack/platform/plugins/shared/lens/common/references/index.ts
@nickofthyme nickofthyme requested a review from a team as a code owner October 22, 2025 20:05
Copy link
Copy Markdown
Contributor

@dej611 dej611 left a comment

Choose a reason for hiding this comment

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

Tested locally and works fine.
Left some minor comments, in particular about type locations.
Will approve to unblock.

Comment thread x-pack/platform/plugins/shared/lens/public/react_embeddable/renderer/types.ts Outdated
Comment thread x-pack/platform/plugins/shared/lens/public/react_embeddable/helper.ts Outdated
Comment thread x-pack/platform/plugins/shared/lens/server/api/routes/utils.ts
Comment thread x-pack/platform/plugins/shared/lens/server/embeddable/types.ts
Comment thread x-pack/platform/plugins/shared/lens/server/embeddable/types.ts
@dej611

This comment was marked as resolved.

Comment thread x-pack/platform/plugins/shared/lens/common/transforms/index.ts Outdated
@elastic-vault-github-plugin-prod elastic-vault-github-plugin-prod Bot requested a review from a team as a code owner October 28, 2025 04:02
Comment thread src/platform/packages/shared/kbn-lens-common/embeddable/types.ts
bg sessions use the public url transforms which defaults to references from the dashboard url which are now always empty, soon to be removed entirely.

But in Lens we had logic to filter references from the dashboard based on references from the lens SO. Instead we should just merge all refs from the lens SO and dashboard.
@nickofthyme nickofthyme requested a review from a team as a code owner October 30, 2025 01:31
@elasticmachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
lens 1421 1440 +19

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/lens-common 1340 1339 -1

Async chunks

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

id before after diff
dashboard 663.1KB 663.1KB +6.0B
discover 1.2MB 1.2MB +6.0B
infra 1.1MB 1.1MB +6.0B
lens 1.5MB 1.5MB +6.5KB
observability 1.7MB 1.7MB +6.0B
onechat 388.1KB 388.1KB +6.0B
total +6.5KB

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
lens 6 7 +1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
lens 57.9KB 57.5KB -356.0B
observabilityAIAssistantApp 14.2KB 14.2KB +1.0B
total -355.0B
Unknown metric groups

API count

id before after diff
@kbn/lens-common 1483 1481 -2

History

@nickofthyme nickofthyme removed request for a team October 30, 2025 14:24
Comment on lines +412 to +414
// TODO: Improve these types
const lensVis = vis as unknown as LensEmbeddableStateWithType;
return extract(lensVis).references;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The types here are complaining because vis.attributes are Record<string, unknown>.

@mistic mistic merged commit 1c53cd3 into elastic:main Oct 31, 2025
13 checks passed
@nickofthyme nickofthyme deleted the lens-server-refs branch October 31, 2025 14:19
ana-davydova pushed a commit to ana-davydova/kibana that referenced this pull request Nov 3, 2025
## Summary

Move Lens `reference` handling to server side.

Close elastic#221943

## Details

Lens no longer relies on `references` from the `buildEmbeddable`. We now
inject/extract references on the server.

Lens duplicates `references` in it's own serialized state so we just
move them there and add the `savedObjectId` for by-ref Lens panels. Lens
still inject these `references` internally by type across the Lens code.

For now we still store the `references` duplicated in the Lens SO state,
but we can clean this up when we extract all the internal reference
handling.

### Checklist

- [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
- [x] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.

---------

Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
Co-authored-by: dej611 <dej611@gmail.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
albertoblaz pushed a commit to albertoblaz/kibana that referenced this pull request Nov 4, 2025
## Summary

Move Lens `reference` handling to server side.

Close elastic#221943

## Details

Lens no longer relies on `references` from the `buildEmbeddable`. We now
inject/extract references on the server.

Lens duplicates `references` in it's own serialized state so we just
move them there and add the `savedObjectId` for by-ref Lens panels. Lens
still inject these `references` internally by type across the Lens code.

For now we still store the `references` duplicated in the Lens SO state,
but we can clean this up when we extract all the internal reference
handling.

### Checklist

- [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
- [x] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.

---------

Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
Co-authored-by: dej611 <dej611@gmail.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
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 ci:build-webpack-bundle-analyzer 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.

[Lens as code] Handle references on the server

6 participants