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

Clear cell cache when external scrolling ends #649

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
39 changes: 39 additions & 0 deletions source/Grid/Grid.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,45 @@ describe('Grid', () => {
done()
})

it('should clear cache once :isScrolling via props is false', async () => {
const cellRendererCalls = []
function cellRenderer ({ columnIndex, key, rowIndex, style }) {
cellRendererCalls.push({ columnIndex, rowIndex })
return defaultCellRenderer({ columnIndex, key, rowIndex, style })
}
const props = {
cellRenderer,
columnWidth: 100,
height: 40,
rowHeight: 20,
scrollTop: 0,
isScrolling: true,
width: 100
}

render(getMarkup(props))
expect(cellRendererCalls).toEqual([
{ columnIndex: 0, rowIndex: 0 },
{ columnIndex: 0, rowIndex: 1 }
])

render(getMarkup({
...props,
isScrolling: false
}))

// Allow scrolling timeout to complete so that cell cache is reset
await new Promise(resolve => setTimeout(resolve, DEFAULT_SCROLLING_RESET_TIME_INTERVAL * 2))

cellRendererCalls.splice(0)

render(getMarkup({
...props,
isScrolling: true
}))
expect(cellRendererCalls.length).not.toEqual(0)
})

it('should clear cache if :recomputeGridSize is called', () => {
const cellRendererCalls = []
function cellRenderer ({ columnIndex, key, rowIndex, style }) {
Expand Down
6 changes: 6 additions & 0 deletions source/Grid/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,12 @@ export default class Grid extends PureComponent {
// Update onRowsRendered callback if start/stop indices have changed
this._invokeOnGridRenderedHelper()

// If scrolling is controlled outside this component, trigger a scroll end
// whenever we are no longer scrolling
if (prevProps.isScrolling === true && this.props.isScrolling === false) {
this._debounceScrollEnded()
}

// Changes to :scrollLeft or :scrollTop should also notify :onScroll listeners
if (
scrollLeft !== prevState.scrollLeft ||
Expand Down