Skip to content

Commit

Permalink
[DataGrid] Wait for remote stylesheets to load before print (#9665)
Browse files Browse the repository at this point in the history
  • Loading branch information
cherniavskii authored Jul 20, 2023
1 parent a096255 commit 62725ed
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ export const useGridPrintExport = (
printDoc.body.classList.add(...normalizeOptions.bodyClassName.split(' '));
}

const stylesheetLoadPromises: Promise<void>[] = [];

if (normalizeOptions.copyStyles) {
const rootCandidate = gridRootElement!.getRootNode();
const root =
Expand Down Expand Up @@ -213,14 +215,23 @@ export const useGridPrintExport = (
}
}

stylesheetLoadPromises.push(
new Promise((resolve) => {
newHeadStyleElements.addEventListener('load', () => resolve());
}),
);

printDoc.head.appendChild(newHeadStyleElements);
}
}
}

// Trigger print
if (process.env.NODE_ENV !== 'test') {
printWindow.contentWindow!.print();
// wait for remote stylesheets to load
Promise.all(stylesheetLoadPromises).then(() => {
printWindow.contentWindow!.print();
});
}
},
[apiRef, doc, props.columnHeaderHeight],
Expand Down

0 comments on commit 62725ed

Please sign in to comment.