Skip to content

Commit 984f042

Browse files
authored
Fix "Hydration Error" (#535)
Fixed a recent "Hydration Error" that was reported (`Hydration failed - the server rendered HTML didn't match the client.`) that was related to the cookie snackbar rendering differently between server and client.
1 parent b6ffcd9 commit 984f042

File tree

4 files changed

+738
-768
lines changed

4 files changed

+738
-768
lines changed

cypress/e2e/landing.cy.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,28 @@ describe('Landing Page', () => {
1616
// Check that the profile picture exists on the page
1717
cy.get('[data-testid="profile_pic"]').should('exist');
1818
});
19+
20+
it('should show cookie snackbar on first load and not after accepting', () => {
21+
const hydrationErrorPattern = /hydration|did not match|content does not match/i;
22+
cy.on('window:before:load', (win) => {
23+
cy.spy(win.console, 'error').as('consoleError');
24+
});
25+
26+
// The snackbar should be visible on first load
27+
cy.get('.MuiSnackbar-root').should('exist').and('be.visible');
28+
cy.contains('This website uses cookies to enhance the user experience.').should('be.visible');
29+
30+
// Click the close button to accept cookies
31+
cy.get('.MuiSnackbar-root button[aria-label="close"]').click();
32+
cy.get('.MuiSnackbar-root').should('not.exist');
33+
34+
// Reload the page
35+
cy.reload();
36+
37+
// The snackbar should not appear again
38+
cy.get('.MuiSnackbar-root').should('not.exist');
39+
40+
// Assert no hydration errors in the browser console
41+
cy.get('@consoleError').should('not.have.been.calledWithMatch', hydrationErrorPattern);
42+
});
1943
});

0 commit comments

Comments
 (0)