-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[core] Add React 18 to peer dependencies #4332
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
import { useForkRef } from '@mui/material/utils'; | ||
import { useGridApiContext } from '../../utils/useGridApiContext'; | ||
import { useGridRootProps } from '../../utils/useGridRootProps'; | ||
|
@@ -197,13 +198,18 @@ export const useGridVirtualScroller = (props: UseGridVirtualScrollerProps) => { | |
], | ||
); | ||
|
||
React.useLayoutEffect(() => { | ||
if (renderContext) { | ||
updateRenderZonePosition(renderContext); | ||
} | ||
}, [renderContext, updateRenderZonePosition]); | ||
|
||
const updateRenderContext = React.useCallback( | ||
(nextRenderContext) => { | ||
setRenderContext(nextRenderContext); | ||
updateRenderZonePosition(nextRenderContext); | ||
prevRenderContext.current = nextRenderContext; | ||
}, | ||
[setRenderContext, prevRenderContext, updateRenderZonePosition], | ||
[setRenderContext, prevRenderContext], | ||
); | ||
|
||
React.useEffect(() => { | ||
|
@@ -212,7 +218,6 @@ export const useGridVirtualScroller = (props: UseGridVirtualScrollerProps) => { | |
} | ||
|
||
const initialRenderContext = computeRenderContext(); | ||
prevRenderContext.current = initialRenderContext; | ||
updateRenderContext(initialRenderContext); | ||
|
||
const { top, left } = scrollPosition.current!; | ||
|
@@ -257,14 +262,21 @@ export const useGridVirtualScroller = (props: UseGridVirtualScrollerProps) => { | |
prevTotalWidth.current !== columnsTotalWidth; | ||
|
||
// TODO v6: rename event to a wider name, it's not only fired for row scrolling | ||
apiRef.current.publishEvent(GridEvents.rowsScroll, { | ||
top: scrollTop, | ||
left: scrollLeft, | ||
renderContext: shouldSetState ? nextRenderContext : prevRenderContext.current, | ||
}); | ||
apiRef.current.publishEvent( | ||
GridEvents.rowsScroll, | ||
{ | ||
top: scrollTop, | ||
left: scrollLeft, | ||
renderContext: shouldSetState ? nextRenderContext : prevRenderContext.current, | ||
}, | ||
event, | ||
); | ||
|
||
if (shouldSetState) { | ||
updateRenderContext(nextRenderContext); | ||
// Prevents batching render context changes | ||
ReactDOM.flushSync(() => { | ||
updateRenderContext(nextRenderContext); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixes the following glitch: From what I found, React 18 doesn't commit some renders if they take too much time. But, no matter the case, we update the render zone position so the position ends not matching the context rendered. Flushing the tree ensures that no render will be skipped. facebook/react#18402 (comment) Updating the position inside I would like to see how other virtualization libraries will solve this problem. Until there we have to use this workaround. If you have suggestions to improve this please comment. |
||
}); | ||
prevTotalWidth.current = columnsTotalWidth; | ||
} | ||
}; | ||
|
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.
Fixes