grafana / scenes

Build Grafana dashboards directly in your Grafana app plugins.
https://grafana.com/developers/scenes
Apache License 2.0
133 stars 20 forks source link

SafeSerializableSceneObject: Make sure valueOf is bound to the instance #844

Closed dprokop closed 2 months ago

dprokop commented 2 months ago

This PR fixes an issue that may occur when the data source that interpolates queries uses cloneDeep to clone the provided query request. For example:

https://github.com/grafana/athena-datasource/blob/v2.17.1/src/datasource.ts#L104 https://github.com/grafana/grafana/blob/v11.1.2/public/app/plugins/datasource/cloudwatch/datasource.ts#L88

When such an object is cloned the previously unbound SafeSerializableSceneObject.valueOf would change this context that would point to the newly (cloned) created instance. This creates an issue with the code generated by typescript when using private properties (#). The diff of the compiled code can be observed here: https://www.diffchecker.com/WLJEvKvj/

The cloneDeep will not call the cloned object constructor - this means that the originally bound valueOf function must preserve the this context of the source object.

📦 Published PR as canary version: 5.6.2--canary.844.10073760230.0
:sparkles: Test out this PR locally via: ```bash npm install @grafana/scenes-react@5.6.2--canary.844.10073760230.0 npm install @grafana/scenes@5.6.2--canary.844.10073760230.0 # or yarn add @grafana/scenes-react@5.6.2--canary.844.10073760230.0 yarn add @grafana/scenes@5.6.2--canary.844.10073760230.0 ```
grafanabot commented 2 months ago

:rocket: PR was released in v5.6.2 :rocket: