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

Prvent early _debounceScrollEndedCallback(&cellRangeRenderer), when process slow Grid's #1141

Merged
merged 1 commit into from
Jul 11, 2018
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
37 changes: 37 additions & 0 deletions source/Grid/Grid.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {Simulate} from 'react-dom/test-utils';
import TestRenderer from 'react-test-renderer';
import {render} from '../TestUtils';
import Grid, {DEFAULT_SCROLLING_RESET_TIME_INTERVAL} from './Grid';
import defaultCellRangeRenderer from './defaultCellRangeRenderer';
import {CellMeasurer, CellMeasurerCache} from '../CellMeasurer';
import {
SCROLL_DIRECTION_BACKWARD,
Expand Down Expand Up @@ -2001,6 +2002,42 @@ describe('Grid', () => {
expect(cellRendererCalls.length).toEqual(0);
});

it('should not trigger render by _debounceScrollEndedCallback if process slow table', async () => {
const scrollingResetTimeInterval = 50;
let cellRangeRendererCalls = 0;
function cellRangeRenderer(props) {
const startTime = Date.now();
while (Date.now() - startTime <= scrollingResetTimeInterval); // imitate very slow render
cellRangeRendererCalls++;
return defaultCellRangeRenderer(props);
}
const props = {
scrollingResetTimeInterval,
cellRangeRenderer,
};

const grid = render(getMarkup(props));
render(getMarkup(props));
expect(cellRangeRendererCalls).toEqual(1);

for (let i = 1; i <= 5; i++) {
cellRangeRendererCalls = 0;
simulateScroll({grid, scrollTop: i});
// small wait for maybe early _debounceScrollEndedCallback
await new Promise(resolve =>
setTimeout(resolve, scrollingResetTimeInterval / 2),
);
expect(cellRangeRendererCalls).toEqual(1);
}

cellRangeRendererCalls = 0;
// wait for real _debounceScrollEndedCallback
await new Promise(resolve =>
setTimeout(resolve, scrollingResetTimeInterval * 1.5),
);
expect(cellRangeRendererCalls).toEqual(1);
});

it('should support a custom :scrollingResetTimeInterval prop', async done => {
const cellRendererCalls = [];
const scrollingResetTimeInterval =
Expand Down
6 changes: 5 additions & 1 deletion source/utils/requestAnimationTimeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export const requestAnimationTimeout = (
callback: Function,
delay: number,
): AnimationTimeoutId => {
const start = Date.now();
let start;
// wait for end of processing current event handler, because event handler may be long
Promise.resolve().then(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI this adds core-js polyfill to the output

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have no idea what to do with it.
Looks like we'll have to leave it at that.

start = Date.now();
});

const timeout = () => {
if (Date.now() - start >= delay) {
Expand Down