Fix endless rerenders in MapExplorer
Merge pull request #54 from victor-homyakov/fix-endless-loop-map-explorer
Fix endless rerenders in MapExplorer
Build webapp using vite (#52)
Fix endless rerenders in MapExplorer
Build webapp using vite (#52)
Right now MapExplorer has a problem that leads to endless rerenders:
const state = initGroupingState(props)
every time has a new property state.selectedGroup
because objects for groups are created every time from scratch at getGroupingValues()
, there is no caching or memoizationuseEffect()
relies on [state.selectedGroup, fileDeoptInfo]
, but state.selectedGroup
on every render is different, so shallow compare with previous version will return false even when deep compare would show they are similar; therefore useEffect()
is called on each rerenderuseEffect()
may call setSelectedEntry(state.selectedGroup.entry)
, starting endless rerender loopSchematically, the execution loop has next steps:
MapExplorer() // render
const state = initGroupingState(props); // create new object instance for state.selectedGroup
useEffect(/*...*/, [state.selectedGroup, fileDeoptInfo]) // trigger useEffect because shallow equality check fails for state.selectedGroup
useEffect(() => {/*...*/setSelectedEntry(state.selectedGroup.entry);/*...*/}) // trigger new rerender
MapExplorer() // rerender -> loop
Fix typo "unintialized" -> "uninitialized"
Merge pull request #50 from victor-homyakov/fix-unitialized-name
Fix typo "unintialized" -> "uninitialized"
Upgrade dependencies and switch to NPM (#51)
Upgrade some deps
Upgrade husky pre-commit hook
Switch to using npm
Reformat files using prettier
Move tape dep to root package json
Update more deps
Update workflow task versions
Describe the bug Runnable code: https://runkit.com/victor-homyakov/day-js-second-param-mutation
const dayjs = require('dayjs');
const FORMATS = ['DD-MM-YYYY', 'DD.MM.YYYY'];
console.log('1', FORMATS, Object.keys(FORMATS));
const d1 = dayjs('22.11.2022', FORMATS);
console.log('2', FORMATS, Object.keys(FORMATS));
Console output:
1 ["DD-MM-YYYY", "DD.MM.YYYY"] ["0", "1"]
2 ["DD-MM-YYYY", "DD.MM.YYYY"] ["0", "1", "date", "args"]
Expected behavior Expected console output:
1 ["DD-MM-YYYY", "DD.MM.YYYY"] ["0", "1"]
2 ["DD-MM-YYYY", "DD.MM.YYYY"] ["0", "1"]
Information
Details
The problem is in the code at https://github.com/iamkun/dayjs/blob/v1.11.6/src/index.js#L41
const dayjs = function (date, c) {
// skipped...
const cfg = typeof c === 'object' ? c : {}
cfg.date = date
cfg.args = arguments
The type of any array is 'object': typeof [] === 'object'
. When called as daysjs(string, array)
, it uses the passed array as a configuration object cfg
, and writes to it two fields date
, args
.
https://github.com/gitkraken/vscode-gitlens/blob/main/CHANGELOG.md#1310---2002-11-17
## 13.1.0 - 2002-11-17
...
## 13.0.4 - 2002-11-03
13.1.0
No response
No response
No response