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

Merged
merged 8 commits into from
Feb 26, 2025
Merged
Changes from 1 commit
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') {
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!

Copy link
Member

Choose a reason for hiding this comment

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

@mdvictor did you locate where the transformations editors mutate the state?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't have time to further look into the transformation one yet. Basically any modification in a transformation editor in a duplicated panel will mutate the options in the original one because it's the same object reference.

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