Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid cells cached on infinite loaded grids #528

Merged
merged 2 commits into from
Jan 6, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
forceUpdateGrid () {
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 {
forceUpdate () {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should be named recomputedRowHeights

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, will update.

recomputedRowHeights = true
}
render () {
return <div />
}
}
forceUpdateReactVirtualizedComponent(
render(<TestComponent />)
)
expect(recomputedRowHeights).toEqual(true)
})
})