diffConfig always returns true if modeBarButtons (array of array) is populated
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 18.3k
- Forks
- 2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 28
Description
diffConfig function has bug where it always returns true if modeBarButtons (array of array) is populated. This results in unnecessary re-rendering. The function should check if the array member is array inside a for loop, It should be -
/*
-
simple diff for config - for now, just treat all changes as equivalent
*/
function diffConfig(oldConfig, newConfig) {
var key;for(key in oldConfig) {
if(key.charAt(0) === '_') continue;
var oldVal = oldConfig[key];
var newVal = newConfig[key];
if(oldVal !== newVal) {
if(Lib.isPlainObject(oldVal) && Lib.isPlainObject(newVal)) {
if(diffConfig(oldVal, newVal)) {
return true;
}
} else if(Array.isArray(oldVal) && Array.isArray(newVal)) {
if(oldVal.length !== newVal.length) {
return true;
}for(var i = 0; i < oldVal.length; i++) { if(oldVal[i] !== newVal[i]) { **if(Array.isArray(oldVal[i]) && Array.isArray(newVal[i])){ if(diffConfig(oldVal[i], newVal[i])) { return true; } } else** if(Lib.isPlainObject(oldVal[i]) && Lib.isPlainObject(newVal[i])) { if(diffConfig(oldVal[i], newVal[i])) { return true; } } else { return true; } } } } else { return true; } }}
}
e.g Config object used -
const plotlyConfig: Partial = {
responsive: true,
displaylogo: false,
displayModeBar: true,
doubleClick: false,
showTips: false,
scrollZoom: false,
modeBarButtons: [
[
'select2d',
'lasso2d',
'zoom2d',
'pan2d',
'resetScale2d',
],
],
locale: language,
locales: locales
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the diffConfig function and use the plotlyConfig example with nested modeBarButtons arrays as the reproduction case. Compare equivalent nested arrays and verify that unchanged configurations are not reported as different, avoiding the unnecessary re-render; the issue names no file or test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- data-visualization, frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100