-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Mounted portals show in debug and can be found #1760
Conversation
case HostPortal: // 4 | ||
return { | ||
nodeType: 'portal', | ||
type: Portal, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im not sure if it makes more sense to use Portal
here, it may be better to just use 'Portal'
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typically type
is either a string (an html element) or a function (component). I think using the
Portal` symbol here is perfect.
f00cac8
to
c74acb4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a few tests showing that you can .find
stuff inside the Portal?
case HostPortal: // 4 | ||
return { | ||
nodeType: 'portal', | ||
type: Portal, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typically type
is either a string (an html element) or a function (component). I think using the
Portal` symbol here is perfect.
return { | ||
nodeType: 'portal', | ||
type: Portal, | ||
props: {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this shouldn't be props: { children }
- ie, have the actual children provided to createPortal?
also, perhaps include the containerInfo
as a "prop"?
@@ -94,6 +97,10 @@ export function displayNameOfNode(node) { | |||
|
|||
if (!type) return null; | |||
|
|||
if (type === Portal) { | |||
return 'Portal'; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
@@ -104,6 +111,9 @@ export function nodeTypeFromType(type) { | |||
if (type && type.prototype && type.prototype.isReactComponent) { | |||
return 'class'; | |||
} | |||
if (type && type === Portal) { | |||
return 'portal'; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
const wrapper = mount(<Foo />); | ||
expect(wrapper.debug()).to.equal(`<Foo> | ||
<div> | ||
<Portal> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps this could be <Portal container={…}>
- with the container display being something like containerDiv.outerHTML
?
The test for finding Portals descendants is at https://github.com/airbnb/enzyme/blob/master/packages/enzyme-test-suite/test/ReactWrapper-spec.jsx#L957 (since that behavior was working previously for |
0562916
to
605021d
Compare
- [New] Add Portal support (#1760, #1761, #1772, #1774, @jgzuke) - [New] Add pointer events support (#1753, @ljharb) - [New] Add `displayNameOfNode`, `isValidElementType` (#1701, @jquense) - [New] pass the adapter into `createMountWrapper` (#1592, @jquense) - [Fix] `shallow`: skip updates when nextState is `null` or `undefined` (#1785, @koba04) - update deps - [meta] ensure a license and readme is present in all packages when published
- [New] Add forwardRef support (#1592, @jquense) - [New] Add Portal support (#1760, #1761, #1772, #1774, @jgzuke) - [New] Add pointer events support (#1753, @ljharb) - [New] Add `displayNameOfNode`, `isValidElementType` (#1701, @jquense) - [New] pass the adapter into `createMountWrapper` (#1592, @jquense) - [Fix] preemptively fix compat with React v16.4.3 (#1790, #1778, @gaearon, @aweary) - [Fix] `shallow`: skip updates when nextState is `null` or `undefined` (#1785, @koba04) - update deps - [meta] ensure a license and readme is present in all packages when published
- [New] Add forwardRef support (#1592, @jquense) - [New] Add Portal support (#1760, #1761, #1772, #1774, @jgzuke) - [New] Add pointer events support (#1753, @ljharb) - [Fix] preemptively fix compat with React v16.4.3 (#1790, #1778, @gaearon, @aweary) - [Fix] `shallow`: prevent rerenders with PureComponents (#1786, @koba04) - [Fix] `shallow`: skip updates when nextState is `null` or `undefined` (#1785, @koba04) - [Fix] `shallow`: `setState` after `setProps` calls `componentWillReceiveProps` (#1779, @peanutenthusiast) - [Fix] `mount`/`shallow`: be stricter on the wrapper’s setState/setProps callback - [Fix] `shallow`/`mount`: improve error message when wrapping invalid elements (#1759, @jgzuke) - update deps - [Refactor] remove most uses of lodash - [meta] ensure a license and readme is present in all packages when published
React 16+ adapters
toTree
given aHostPortal
returns a portal wrapping the child tree, instead of returning the child tree directly. This lets Portals show up in debug output and be found. Added the portal wrapper with anodeType
of'portal'
and atype
of react-isPortal
.