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 1 commit 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') {
newArray.push({ ...child });
Comment on lines +48 to +49
Copy link
Member

Choose a reason for hiding this comment

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

This is going to be problematic for properties that are Array. The individual array values will be spread as properties on the state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good catch. Do you think something like this would be okay?

Suggested change
} else if (typeof child === 'object') {
newArray.push({ ...child });
} else if (typeof child === 'object' && !Array.isArray(child)) {
newArray.push({ ...child });

Copy link
Member

Choose a reason for hiding this comment

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

yea, that could work.

But if it's just graphite maybe we can fix the mutation here: https://github.com/grafana/grafana/blob/6abe99efd64b8867112d9d9c74971d96840ce32d/public/app/plugins/datasource/graphite/state/store.ts#L53

(and elsewhere)

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