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

Add inline portal node support #45

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

aeharding
Copy link

@aeharding aeharding commented 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 #44

[0] https://html.spec.whatwg.org/multipage/grouping-content.html#the-p-element

@CLAassistant
Copy link

CLAassistant commented Nov 18, 2024

CLA assistant check
All committers have signed the CLA.

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
@@ -34,7 +35,7 @@ interface PortalNodeBase<C extends Component<any>> {
}
export interface HtmlPortalNode<C extends Component<any> = Component<any>> extends PortalNodeBase<C> {
Copy link
Author

@aeharding aeharding Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to avoid breaking change, I merged block/inline elements into this interface.

Alternatively, I could separate into HtmlBlockPortalNode/HtmlInlinePortalNode (breaking change due to export name change), or keep HtmlPortalNode the same as it used to be, and export HtmlInlinePortalNode in addition/separately (non breaking change)

@@ -2,7 +2,7 @@ import React from 'react';

import { storiesOf } from '@storybook/react';

import { createHtmlPortalNode, createSvgPortalNode, InPortal, OutPortal } from '..';
import { createHtmlPortalNode, createHtmlInlinePortalNode, InPortal, OutPortal } from '..';
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left createHtmlPortalNode the same to avoid breaking change (e.g. to createHtmlBlockPortalNode)

I think most people will want the block version anyways.

@aeharding
Copy link
Author

For naming options, curious your thoughts on:

  • createHtmlInlinePortalNode vs
  • createHtmlPhrasingPortalNode

Perhaps "phrasing" is more accurate than "inline" (but maybe less well understood) in regards to when you should use it.

Copy link
Member

@pimterry pimterry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, thanks! This makes sense, but I'm not sure about the API - I don't think this should fit into the html vs svg current split, it's not a different type of DOM as such.

What about keeping the existing API, but adding this to options? Is that practical? With that, this could be configured like:

createHtmlPortalNode({ containerElement: 'span' });

I haven't tested, but that looks possible and would keep the API simpler whilst also allowing other different element types in future. Does that make sense?

@aeharding
Copy link
Author

@pimterry Yeah, I can change it.

Should I remove createSvgPortalNode then?

@pimterry
Copy link
Member

Should I remove createSvgPortalNode then?

No - I think we should still have two methods for the different fundamental types of portal (HTML/SVG), I just don't think we should create new methods for each individual element that could be used. The SVG vs HTML difference isn't just the name of the element used - for example SVG portals only allow SVG children, and the placeholder node has to be created in the http://www.w3.org/2000/svg namespace.

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 this pull request may close these issues.

Can't portal inside markdown without React hydration warnings
3 participants