feat(Chart): add meger option logic#1056
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds deep merge behavior when initializing or re-initializing chart instances so that existing chart configurations and instances can be updated in place instead of replaced. Sequence diagram for chart initialization with deep mergesequenceDiagram
participant ChartInit as Chart.init
participant ElementMap as elementMap
participant DataStore as Data
participant ChartObj as chart
ChartInit->>ElementMap: has(element)
alt element not in map
ChartInit->>ElementMap: set(element, instance)
else element already in map
ChartInit->>ElementMap: get(element)
ChartInit->>ElementMap: deepMerge(existingInstance, instance)
end
ChartInit->>DataStore: Data.get(element)
alt data.chart exists
ChartInit->>ChartObj: deepMerge(chart.config._config, instance)
ChartInit->>ChartObj: update()
end
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- When merging into an existing
elementMapentry, you're callingdeepMerge(elementMap.get(element), instance)but not resetting the map value; ifdeepMergereturns a new object rather than mutating in place this will leaveelementMappointing at the old config, so consider assigning the merged result back. - The merge into
data.chart.config._configrelies on a private_configproperty of Chart.js; consider whether there is a more stable public API for updating options to avoid potential breakage with library upgrades. - Repeated deep merges and chart updates on every
setOptionscall may become expensive; if this code path can be hit frequently, consider guarding the merge/update with a shallow comparison or more targeted updates to avoid unnecessary work.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- When merging into an existing `elementMap` entry, you're calling `deepMerge(elementMap.get(element), instance)` but not resetting the map value; if `deepMerge` returns a new object rather than mutating in place this will leave `elementMap` pointing at the old config, so consider assigning the merged result back.
- The merge into `data.chart.config._config` relies on a private `_config` property of Chart.js; consider whether there is a more stable public API for updating options to avoid potential breakage with library upgrades.
- Repeated deep merges and chart updates on every `setOptions` call may become expensive; if this code path can be hit frequently, consider guarding the merge/update with a shallow comparison or more targeted updates to avoid unnecessary work.
## Individual Comments
### Comment 1
<location path="src/components/BootstrapBlazor.Chart/Components/Chart/Chart.razor.js" line_range="24-26" />
<code_context>
+ deepMerge(elementMap.get(element), instance)
+ }
+
+ const data = Data.get(element);
+ if (data && data.chart) {
+ deepMerge(data.chart.config._config, instance);
+ data.chart.update();
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** Merging directly into `data.chart.config._config` may rely on internal/unstable Chart.js APIs and could break if `_config` changes.
`data.chart.config._config` appears to be an internal Chart.js structure rather than a stable public API. If Chart.js changes this field, the merge will start failing silently. Prefer merging into a documented config object (e.g. `data.chart.config` or `data.chart.options`) or using the library’s official update API instead.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| const data = Data.get(element); | ||
| if (data && data.chart) { | ||
| deepMerge(data.chart.config._config, instance); |
There was a problem hiding this comment.
issue (bug_risk): Merging directly into data.chart.config._config may rely on internal/unstable Chart.js APIs and could break if _config changes.
data.chart.config._config appears to be an internal Chart.js structure rather than a stable public API. If Chart.js changes this field, the merge will start failing silently. Prefer merging into a documented config object (e.g. data.chart.config or data.chart.options) or using the library’s official update API instead.
Link issues
fixes #1055
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Improve chart option handling by merging new configuration into existing chart instances instead of replacing them.
New Features:
Bug Fixes: