-
Notifications
You must be signed in to change notification settings - Fork 215
switch to ReactDOM.createPortal #201
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
switch to ReactDOM.createPortal #201
Conversation
|
Just switching to |
| * The children of `<Portal/>` component will be appended to the `container` specified. | ||
| */ | ||
|
|
||
| const useCreatePortal = ReactDOM.createPortal !== undefined; |
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.
Should we also support the deprecated ReactDOM.unstable_ createPortal? IIRC, it's only present in React 16 pre-releases.
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'd go with "no"; just support the releases i think
111edc3 to
933a5e9
Compare
|
Thanks for the help, you might want to looks at the tests in Rea t for how the new API works. It's not the same as the old one you actually call it during render() |
|
I ran the tests with React 15 and 16 and they passed. But I can have another look. |
|
I mean look at React's tests for createPortal, not ours, for proper usage of the api :) |
933a5e9 to
c3865db
Compare
|
Getting closer. The tests that require |
c3865db to
f425ee7
Compare
|
I'm struggling with when to call |
ee125be to
a66ade9
Compare
taion
left a comment
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.
Why the change to lifecycle around creating the portal in cWM rather than cDM?
| * The children of `<Portal/>` component will be appended to the `container` specified. | ||
| */ | ||
|
|
||
| const useCreatePortal = ReactDOM.createPortal !== undefined; |
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'd go with "no"; just support the releases i think
|
|
src/Portal.js
Outdated
| }; | ||
|
|
||
| componentWillMount(){ | ||
| if (useCreatePortal){ |
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.
this also needs a canUseDOM guard here, for serverside rendering. dom-helpers exports that constant for eas of use
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.
done
src/Portal.js
Outdated
|
|
||
| render() { | ||
| return null; | ||
| if (useCreatePortal && this.props.children) { |
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.
paired with my comment above, this needs to confirm this._overlayTarget exists for the SSR case
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.
done
| }); | ||
|
|
||
| it('Should throw with multiple children', function () { | ||
| xit('Should throw with multiple children', function () { |
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.
why are these failing now?
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 have no idea. But the failure is not caused by my changes (PositionSpec fails too). I suspect, there are some changes around how errors are handled and/or reported in React 16.
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 opened #207 to track that down.
|
Given that this needs to mount its own extra portal element, I don't think you can use the cWM-based flow. I think you need to create the element in cDM, then e.g. check |
|
So the new Portal API is awkward. We want to render the portal element on the first render if possible to avoid missing updates or bubbling issues that the older api has. But yeah, it doesn't work if the mount container is isn't just a DOM node, or in the SSR case. I'm not sure what the best option forward is...I'm leaning towards just requiring a DOM node as a container vs a component instance but that might dramatically reduce the usefulness of the component? Side note, the behavior between the old and new API is different, createPortal, allows events to bubble through as if it was a real child |
|
Wait why do we need |
|
You can safely create one if you check for |
48b1132 to
2e3c4c6
Compare
|
Note that the examples does not work anymore because of |
2e3c4c6 to
6159004
Compare
|
I updated |
|
Ok, I'm realizing there is a bunch of code here (originally) that I don't really understand any more... |
|
This is probably obsolete now that #208 is merged. |
Modal stops working in React 16 (#188). I thought this might fix it but it doesn't. It might be a good idea to do the switch anyway.