-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[data grid] Improve print support #6273
Conversation
These are the results for the performance tests:
|
8e3e92e
to
56757ed
Compare
56757ed
to
80fe92a
Compare
19dab7e
to
4f270f3
Compare
@@ -23,6 +23,7 @@ const blacklist = ['sessionStorage', 'localStorage']; | |||
function createDOM() { | |||
const dom = new JSDOM('', { | |||
pretendToBeVisual: true, | |||
url: 'http://localhost', |
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.
To prove that it has no effect. I don't know if we need this URL parameter to be honest, we could remove it.
@@ -6,7 +6,9 @@ import GlobalStyles from '@mui/material/GlobalStyles'; | |||
import { useLocation } from 'react-router-dom'; | |||
import { useFakeTimers } from 'sinon'; | |||
|
|||
const StyledBox = styled(Box)(({ theme, isDataGridTest }) => ({ | |||
const StyledBox = styled(Box, { | |||
shouldForwardProp: (prop) => prop !== 'isDataGridTest', |
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.
Leaking prop on the DOM node (React warning)
handlePrintWindowAfterPrint(printWindow); | ||
}; | ||
}; | ||
doc.current!.body.appendChild(printWindow); |
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.
Set the load event listener after appending the child.
@@ -262,15 +266,21 @@ export const useGridPrintExport = ( | |||
|
|||
await updateGridColumnsForPrint(options?.fields, options?.allColumns); | |||
apiRef.current.unstable_disableVirtualization(); | |||
await raf(); // wait for the state changes to take action |
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 was already missing, but since we do no longer make a network request, the print displays a lot faster, which in the tests doesn't leave enough time for the API calls to render.
// Some agents, such as IE11 and Enzyme (as of 2 Jun 2020) continuously call the | ||
// `onload` callback. This ensures that it is only called once. | ||
printWindow.onload = null; |
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.
IE 11 and enzyme are legacy, I'm not aware that we support them.
4f270f3
to
b693e02
Compare
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.
No problem with dropping IE11 support if that's what the company is doing elsewhere.
@@ -54,6 +62,7 @@ export const useGridPrintExport = ( | |||
const updateGridColumnsForPrint = React.useCallback( | |||
(fields?: string[], allColumns?: boolean) => | |||
new Promise<void>((resolve) => { | |||
// TODO remove unused Promise |
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.
Are those TODO
here because it's breaking ?
If so, we started the alpha phase so we can do the breaking change I think.
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.
Are those TODO here because it's breaking?
The TODO is here because it would make it harder to review what changed in this PR.
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.
Make sense
We can make a follow up after that to remove the promise then
// Remove all loaded elements from the current host | ||
printDoc.body.innerHTML = ''; | ||
printDoc.body.appendChild(gridClone); | ||
// printDoc.body.appendChild(gridClone); should be enough but a clone isolation bug in Safari |
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.
If you have a link to the bug report to help future evolution of this method
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 can't find it in https://bugs.webkit.org/buglist.cgi?quicksearch=cloneNode. However, I can provide the reproduction for the next person in x years that will blame the line, to give him confidence that the problem is gone.
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.
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.
Nice cleanup
This seems to be an opportunity to:
@mui/monorepo
#4149 (comment)Before: https://mui.com/x/react-data-grid/export/#default-toolbar
After: https://deploy-preview-6273--material-ui-x.netlify.app/x/react-data-grid/export/#default-toolbar
Tested in Firefox, Safari, Chrome, latest versions
I have left a couple of TODO for a clean-up follow-up. I was also surprised with how we document the print export. If you: