Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utils: Spread objects in cloneSceneObjectState #967

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/scenes/src/core/sceneGraph/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export function cloneSceneObjectState<TState extends SceneObjectState>(
for (const child of propValue) {
if (child instanceof SceneObjectBase) {
newArray.push(child.clone());
} else if (typeof child === 'object' && !Array.isArray(child)) {
newArray.push({ ...child });
Copy link
Collaborator

Choose a reason for hiding this comment

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

An issue just popped up around transformations that is kind of related to this PR. Basically, duplicating a panel with some transformation and then modifying the transformation options within the second panel would also modify the transformation options in the initial panel.

This happens because of the spread operator won't cover objects that contain deeper nested arrays, which is the case for transformations where you'd have an object of the form:

{
   id: "convertFieldType",
   options: {
       conversions: [{ ...some objects in array }]
   }
}

Modifying this line to use lodash cloneDeep instead of spread op fixes the issue with transformations, so maybe we can use that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the info! I worry that using cloneDeep might introduce some performance issues considering how often scene objects are cloned, but I'd need to benchmark it to be sure. I'll look into it :)

Copy link
Collaborator

@mdvictor mdvictor Jan 21, 2025

Choose a reason for hiding this comment

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

Indeed, I share your worry, thought about it myself, not sure how to deal with it tho. Some benchmarking would be great!

} else {
newArray.push(child);
}
Expand Down
Loading