Fix React hydration issues (#32958)
* Add more playwright axe tests to settings dialogs * Add utility to jest setupTests to detect React hydration errors * Iterate jest utility * Fix axe issue heading-order * Fix div-in-p issues * Fix setupTests.ts * Fix heading order * Make types happier * Fix hydration issues of thead containing text nodes * Update tests * Fix form-in-form React hydration issues * Fix li-in-li React hydration issues * Fix checked in form without onChange React hydration issue * Fix styling bleeding from _common.pcss * Update snapshots * Fix more remaining issues * Remove _common.pcss h2 rule altogether * Fix test * Update snapshots * Iterate * Iterate * Update snapshots * Simplify diff * Test * Update screenshots * Update screenshot
This commit is contained in:
@@ -66,3 +66,28 @@ if (env["GITHUB_ACTIONS"] !== undefined) {
|
||||
require("./setup/setupManualMocks"); // must be first
|
||||
require("./setup/setupLanguage");
|
||||
require("./setup/setupConfig");
|
||||
|
||||
// Utility to check for React errors during the tests
|
||||
// Fails tests on errors like the following:
|
||||
// In HTML, <div> cannot be a descendant of <p>.
|
||||
// In HTML, <form> cannot be a descendant of <form>.
|
||||
// In HTML, text nodes cannot be a child of <thead>.
|
||||
// This will cause a hydration error.
|
||||
// You provided a `checked` prop to a form field without an `onChange` handler.
|
||||
let errors: any[] = [];
|
||||
beforeEach(() => {
|
||||
errors = [];
|
||||
const originalError = console.error;
|
||||
jest.spyOn(console, "error").mockImplementation((...args) => {
|
||||
if (/validateDOMNesting|Hydration failed|hydration error|prop to a form field without an/i.test(args[0])) {
|
||||
errors.push(args[0]);
|
||||
}
|
||||
originalError.call(console, ...args);
|
||||
});
|
||||
});
|
||||
afterEach(() => {
|
||||
mocked(console.error).mockRestore?.();
|
||||
if (errors.length > 0) {
|
||||
throw new Error("Test failed due to React hydration errors in the console.");
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user