Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't portal inside markdown without React hydration warnings #44

Open
aeharding opened this issue Nov 18, 2024 · 0 comments · May be fixed by #45
Open

Can't portal inside markdown without React hydration warnings #44

aeharding opened this issue Nov 18, 2024 · 0 comments · May be fixed by #45

Comments

@aeharding
Copy link

React (and HTML, for that matter) don't really like it when <div> is inside <p>. This happens when I portal inside markdown (where virtually everything is inside a <p>), for portalling a video, for example.

So, I would like the option to use inline portal element (outputting <span>). Perhaps ELEMENT_TYPE_HTML could be renamed to ELEMENT_TYPE_HTML_BLOCK and add ELEMENT_TYPE_HTML_INLINE

Here's the error for the placeholder. There's another for the portal container. I'll make a PR to fix both of these.

In HTML, <div> cannot be a descendant of <p>.
This will cause a hydration error.

  ...
    <div ref={null} className="Positioned..." style={{...}}>
      <CommentContainer depth={1}>
        <render depth={1} themeName="rainbow">
          <div ref={null} className="Container_..." style={{...}}>
            <ModeratableItemBannerOutlet>
            <div>
              <CommentHeader>
              <div aria-hidden={false} className={"rah-stat..."} style={{height:"auto", ...}} ref={null}>
                <div className={undefined} style={{}} ref={function ref}>
                  <render onClick={function _temp2}>
                    <div onClick={function _temp2} ref={null} className="Content_ci...">
                      <CommentContent item={{id:4411616, ...}} showTouchFriendlyLinks={true} mdClassName="collapse-m...">
                        <CommentMarkdown className="collapse-m..." id="https://le../.">
                          <Markdown className="collapse-m..." id="https://le../." components={{...}}>
                            <Markdown className="collapse-m..." components={{...}} remarkPlugins={[...]} ...>
                              <div className="collapse-m...">
>                               <p>
                                  ...
                                    <Video alt="image" node={{type:"element", ...}} onClick={function onClick} ...>
                                      <span style={{opacity:0}} className="media smal...">
                                        <OutPortal2 alt="image" node={{...}} onClick={function onClick} ...>
>                                         <div ref={{current:null}}>
                        ...
      ...
aeharding added a commit to aeharding/react-reverse-portal that referenced this issue Nov 18, 2024
This adds `createHtmlInlinePortalNode` to the public api,
which creates a `<span>` instead of `<div>` wrapper.

This is helpful when portalling into phrasing content.
For example, placing a portal inside `<p>` [0]

Without this, React will emit hydration warnings.

Resolves httptoolkit#44

[0] https://html.spec.whatwg.org/multipage/grouping-content.html#the-p-element
@aeharding aeharding linked a pull request Nov 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant