-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[DataGrid] Raf Timer stored in apiRef #506
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not hands-on in the grid, so it's only feedback from a high-level perspective, the change seems to go in the opposite direction I was expecting. We are introducing a leaking side effect, an update scheduled in one use ref call can be canceled and never called again in another update, this will likely create bugs. I mean, it only works if the use raf hooks are used in the same component. Have you considered to share the update function instead of the then timer? This would guarantee the constraint and hence avoid dropped updates.
I don't understand why we need to use Raf in the first place. react-virtualized, react-window, react-virtuoso, react-virtual barely uses it. I would encourage we remove this hook from the codebase to make usage of Raf painful, the default solution being to defer rendering prioritization to React.
I'm having a closer look at the usage of raf:
So it seems that we can/should remove the hook. |
Please try on the fast streaming stories. |
Isn't streaming a different concern? Why apply the same solution for the other use cases? I definitely agree that for streaming we could considering rerendering at each RAF, bypassing React. But at the same time, isn't it the same with the onScroll events (it fires a lot and yet we don't use it)? In the above exploration, I believe streaming has no impact. 1. is already backed by a React state, 2. will need to be (it won't behave correctly without), 3. can be done with a set timeout or a RAF. |
I'm not sure I understand what you mean. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't share rerendering between different components.
Conflicts: packages/grid/_modules_/grid/hooks/features/virtualization/useVirtualRows.ts packages/grid/_modules_/grid/hooks/utils/useScrollFn.ts
expect(checkbox).to.have.property('checked', true); | ||
|
||
fireEvent.click(screen.getByRole('cell', { name: 'Nike' })); | ||
await raf(); | ||
expect(row!.classList.contains('Mui-selected')).to.equal(false); | ||
expect(row!.classList.contains('Mui-selected')).to.equal(false, 'class mui-selected 2'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like in Jest we don't use assertion descriptions. It's very often outdated and doesn't help much.
expect(row!.classList.contains('Mui-selected')).to.equal(false, 'class mui-selected 2'); | |
expect(row!.classList.contains('Mui-selected')).to.equal(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is to see where the fails in the ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I thought you were using Jest in the past, this isn't supported in Jest :p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to keep it, my feedback, at its core, is that it's often ignored and get outdated after refactoring in the tests. So usually, we don't bother 🤷♂️
await raf(); | ||
expect(row!.classList.contains('Mui-selected')).to.equal(true); | ||
await sleep(100) | ||
expect(row!.classList.contains('Mui-selected')).to.equal(true, 'class mui-selected 1'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect(row!.classList.contains('Mui-selected')).to.equal(true, 'class mui-selected 1'); | |
expect(row!.classList.contains('Mui-selected')).to.equal(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By leaving this we know where the test can potentially failed. Up to you?
Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
Browser tests are flaky after the change. Something is wrong with the logic. |
* add rafTimer Conflicts: packages/grid/_modules_/grid/hooks/features/virtualization/useVirtualRows.ts packages/grid/_modules_/grid/hooks/utils/useScrollFn.ts * fix cyclic dep and cleanup * fix import * fix import * trying to fix test in CI * refactor scroll * Update packages/grid/_modules_/grid/hooks/utils/useRafUpdate.ts Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com> * Update packages/grid/_modules_/grid/hooks/utils/useScrollFn.ts Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com> * fix tests * prettier * fix test * fix test * fix tests * more sleep * Update packages/grid/_modules_/grid/models/api/coreApi.ts Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com> * Update packages/grid/_modules_/grid/models/api/coreApi.ts Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com> * small refactoring Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
This PR allows to coordinates all calls to requestAnimationFrame
It fixes the raf violation