KEMBAR78
fix(dev-overlay): prevent hydration mismatch in dialog role by prateekbisht23 · Pull Request #83718 · vercel/next.js · GitHub
Skip to content

Conversation

prateekbisht23
Copy link

What?

Fixed a hydration mismatch in the Next.js development overlay related to the dialog component. The issue occurred because the component initialized role state with document.hasFocus(), causing server-rendered HTML to differ from client-rendered HTML.

Why?

Hydration mismatches lead to runtime warnings and inconsistent UI behavior in React applications. This fix ensures that the server-rendered markup matches the client-rendered markup, improving developer experience and preventing errors in the dev overlay.

How?

  • Moved the document.hasFocus() logic into a useEffect hook to ensure it only runs on the client.
  • This prevents the initial render from producing different HTML between server and client.
  • Ran pnpm prettier-fix to apply consistent formatting.

Closes / Fixes

fixes #83710

The dialog component was initializing role state with document.hasFocus(), which caused different HTML between server and client. This patch moves the logic into useEffect so that initial render is consistent and hydration succeeds without warnings.
@ijjk
Copy link
Member

ijjk commented Sep 12, 2025

Allow CI Workflow Run

  • approve CI run for commit: b8dea4b

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@ijjk
Copy link
Member

ijjk commented Sep 12, 2025

Allow CI Workflow Run

  • approve CI run for commit: b63e6ef

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

…dialog.tsx

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error overlay is missing styles on client errors

2 participants