-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Infinite loop with grid rendering (#1631)
- Caused by #1626 - The children on IrisGrid were getting re-rendered as a result of IrisGrid.handleViewChanged getting called after updating the canvas in Grid.componentDidUpdate - Another fix would be to memoize metrics and not emit a view change if they are exactly the same as previous metrics, but thought that was a bigger change (need to deep equals a bunch of maps and arrays in the metrics) - Tested by opening up a table with React dev tools highlighting re-renders. Table did not re-render when not being interacted with.
- Loading branch information
Showing
4 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { getChangedKeys } from './ObjectUtils'; | ||
|
||
describe('getChangedKeys', () => { | ||
it('should get changed keys', () => { | ||
const oldObject = { | ||
foo: 'bar', | ||
baz: 'qux', | ||
quux: 'corge', | ||
}; | ||
const newObject = { | ||
foo: 'bar', | ||
baz: 'quux', | ||
quux: 'corge', | ||
}; | ||
expect(getChangedKeys(oldObject, newObject)).toEqual(['baz']); | ||
}); | ||
it('should get changed keys when old object is empty', () => { | ||
const oldObject = {}; | ||
const newObject = { | ||
foo: 'bar', | ||
baz: 'qux', | ||
quux: 'corge', | ||
}; | ||
expect(getChangedKeys(oldObject, newObject)).toEqual([ | ||
'foo', | ||
'baz', | ||
'quux', | ||
]); | ||
}); | ||
it('should get changed keys when new object is empty', () => { | ||
const oldObject = { | ||
foo: 'bar', | ||
baz: 'qux', | ||
quux: 'corge', | ||
}; | ||
const newObject = {}; | ||
expect(getChangedKeys(oldObject, newObject)).toEqual([ | ||
'foo', | ||
'baz', | ||
'quux', | ||
]); | ||
}); | ||
it('should get no changed keys when both objects are empty', () => { | ||
const oldObject = {}; | ||
const newObject = {}; | ||
expect(getChangedKeys(oldObject, newObject)).toEqual([]); | ||
}); | ||
it('should get no changed keys when both objects are the same', () => { | ||
const oldObject = { | ||
foo: 'bar', | ||
baz: 'qux', | ||
quux: 'corge', | ||
}; | ||
const newObject = { | ||
foo: 'bar', | ||
baz: 'qux', | ||
quux: 'corge', | ||
}; | ||
expect(getChangedKeys(oldObject, newObject)).toEqual([]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Get the keys that have changed between two objects. | ||
* @param oldObject Old object to compare | ||
* @param newObject New object to compare | ||
* @returns Array of keys that have changed | ||
*/ | ||
export function getChangedKeys( | ||
oldObject: Record<string, unknown>, | ||
newObject: Record<string, unknown> | ||
): string[] { | ||
const keys = new Set([...Object.keys(oldObject), ...Object.keys(newObject)]); | ||
const changedKeys: string[] = []; | ||
|
||
keys.forEach(key => { | ||
if (oldObject[key] !== newObject[key]) { | ||
changedKeys.push(key); | ||
} | ||
}); | ||
|
||
return changedKeys; | ||
} | ||
|
||
export default { getChangedKeys }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters