Skip to content

Commit

Permalink
Merge pull request #528 from nickclaw/fix/cell-cache-invalidation
Browse files Browse the repository at this point in the history
Fix invalid cells cached on infinite loaded grids
  • Loading branch information
bvaughn authored Jan 6, 2017
2 parents 8906f30 + 2581ad7 commit 3b944e0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
20 changes: 17 additions & 3 deletions source/InfiniteLoader/InfiniteLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,23 @@ export function scanForUnloadedRanges ({
* In the first case the built-in React forceUpdate() method is sufficient to force a re-render,
* But in the latter cases we need to use the RV-specific forceUpdateGrid() method.
* Else the inner Grid will not be re-rendered and visuals may be stale.
*
* Additionally, while a Grid is scrolling the cells can be cached,
* So it's important to invalidate that cache by recalculating sizes
* before forcing a rerender.
*/
export function forceUpdateReactVirtualizedComponent (component) {
typeof component.forceUpdateGrid === 'function'
? component.forceUpdateGrid()
: component.forceUpdate()
const recomputeSize = typeof component.recomputeGridSize === 'function'
? component.recomputeGridSize
: component.recomputeRowHeights

const forceUpdate = typeof component.forceUpdateGrid === 'function'
? component.forceUpdateGrid
: component.forceUpdate

if (recomputeSize) {
recomputeSize.call(component)
}

forceUpdate.call(component)
}
32 changes: 32 additions & 0 deletions source/InfiniteLoader/InfiniteLoader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,36 @@ describe('forceUpdateReactVirtualizedComponent', () => {
)
expect(forceUpdateCalled).toEqual(true)
})

it('should call :recomputeGridSize if defined', () => {
let recomputedGridSize = false
class TestComponent extends Component {
recomputeGridSize () {
recomputedGridSize = true
}
render () {
return <div />
}
}
forceUpdateReactVirtualizedComponent(
render(<TestComponent />)
)
expect(recomputedGridSize).toEqual(true)
})

it('should called :recomputeRowHeights if defined', () => {
let recomputedRowHeights = false
class TestComponent extends Component {
recomputeRowHeights () {
recomputedRowHeights = true
}
render () {
return <div />
}
}
forceUpdateReactVirtualizedComponent(
render(<TestComponent />)
)
expect(recomputedRowHeights).toEqual(true)
})
})

0 comments on commit 3b944e0

Please sign in to comment.