fix: render link safety modal in a portal to avoid <p> hydration error#529
Open
osipov-anton wants to merge 1 commit into
Open
fix: render link safety modal in a portal to avoid <p> hydration error#529osipov-anton wants to merge 1 commit into
osipov-anton wants to merge 1 commit into
Conversation
The link safety modal rendered its backdrop <div> inline next to the link <button>. Since markdown links live inside paragraph <p> elements, the modal <div> became a descendant of <p>, triggering the React hydration error "In HTML, <div> cannot be a descendant of <p>". Render the modal through createPortal to document.body so it is no longer nested inside the paragraph. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
|
@osipov-anton is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
linkSafetyis enabled, the link component renders a<button>alongside theLinkSafetyModal. The modal's root is a<div>rendered inline, but markdown links live inside paragraph<p>elements — so the modal<div>ends up as a descendant of<p>.This produces the React hydration error:
Fix
Render the default
LinkSafetyModalthroughcreatePortaltodocument.body, so the modal<div>is no longer nested inside the paragraph. The inline<button>(valid inside<p>) stays where it is. The component also guards against SSR (typeof document === "undefined").Test plan
pnpm --filter streamdown test— all 982 tests passlink-modal-keyboard,link-safety, andtranslationstests to query the portaled DOM (document/document.body) instead of the rendercontainerMade with Cursor