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

[DataGrid] Fix crash when updating columns immediately after scrolling #13781

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

cherniavskii
Copy link
Member

Fixes #13719

I believe this regression was introduced in #12353
I cannot reproduce the issue if I change this timeout to 100:

scrollTimeout.start(1000, triggerUpdateRenderContext);

@cherniavskii cherniavskii added component: data grid This is the name of the generic UI component, not the React module! regression A bug, but worse v7.x labels Jul 9, 2024
@mui-bot
Copy link

mui-bot commented Jul 9, 2024

Deploy preview: https://deploy-preview-13781--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against 8222ac7

@cherniavskii cherniavskii marked this pull request as ready for review July 9, 2024 20:36
@oliviertassinari oliviertassinari added the bug 🐛 Something doesn't work label Jul 9, 2024
test/e2e/fixtures/DataGrid/DynamicVirtualizationRange.tsx Outdated Show resolved Hide resolved
Comment on lines 360 to 363
if (!column) {
// See https://github.com/mui/mui-x/issues/13719
return null;
}
Copy link
Member

@oliviertassinari oliviertassinari Jul 9, 2024

Choose a reason for hiding this comment

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

This feels like it hides something.

Suggested change
if (!column) {
// See https://github.com/mui/mui-x/issues/13719
return null;
}

Looking a bit at it, it seems that the issue is that the frozen render context isn't reset when the column changes.

diff --git a/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx b/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx
index 334d65759..d87187caa 100644
--- a/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx
+++ b/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx
@@ -277,6 +277,7 @@ export const useGridVirtualScroller = () => {
   const forceUpdateRenderContext = () => {
     const inputs = inputsSelector(apiRef, rootProps, enabled, enabledForColumns);
     const nextRenderContext = computeRenderContext(inputs, scrollPosition.current, scrollCache);
+    // Reset the frozen context when the render context changes, see the illustration in https://github.com/mui/mui-x/pull/12353
+    frozenContext.current = undefined;
     updateRenderContext(nextRenderContext);
   };

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch!


await page.click('"Update columns"');

await sleep(200);
Copy link
Contributor

@arminmeh arminmeh Jul 10, 2024

Choose a reason for hiding this comment

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

is there a way to use some grid's callback to check if the error happened instead of waiting for some fixed time?

Copy link
Member

@oliviertassinari oliviertassinari Jul 10, 2024

Choose a reason for hiding this comment

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

It feels like an end to end test is a bit too heavy (slow) for this bug. It seems that to reproduce, it's a matter of scrolling down to create a frozen context and update the columns to break part of the frozen context. So I would expect a Karma test to run significantly faster (would be curious to measure the test speed difference, maybe I'm dillusional).

It seems to break instantly as well, without the need to sleep (needs an act()).

Comment on lines +594 to +603
await page.mouse.move(200, 200);
await page.mouse.wheel(0, 1000);

let thrownError: Error | null = null;
context.once('weberror', (webError: WebError) => {
thrownError = webError.error();
console.error(thrownError);
});

await page.click('"Update columns"');
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick but I would group the page interactions together, shows more clearly the sequence of events that trigger the bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! regression A bug, but worse v7.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[data grid] Undefined property of computedWidth when toggling checkboxSelection
5 participants