-
-
Notifications
You must be signed in to change notification settings - Fork 233
Support React 16 #69
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
Support React 16 #69
Conversation
@benjycui ... |
我也是刚看到。。 |
src/index.js
Outdated
portal = createPortal(this.getComponent(), this._container); | ||
} | ||
|
||
return [ |
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.
要同时兼容 React@15 和 React@16,所以不能直接返回一个 fragment
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.
看上面👆,15 的话会直接返回。
src/index.js
Outdated
let portal; | ||
// prevent unmounting when visible change to false | ||
if (popupVisible || this._component) { | ||
this._container = this._container || getContainer(this); |
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.
@afc163 这个问题还是存在的。。
Updated. |
f893630
to
541ed9c
Compare
} | ||
|
||
createContainer() { | ||
this._container = this.props.getContainer(); |
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.
@afc163 FYI,getPopupContainer 之类的 API,其实只会调用一次,并且之前一直就是这样。考虑到有 removeContainer 的需要,getPopupContainer 的确只能调用一次。
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.
没懂,有啥问题。
如果父元素 dom 结构变了,可能需要调用多次吧。
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.
不缓存 getPopupContainer 的返回值其实也可以,只是每次 render 都需要对比当前返回值和之前的返回值,并相应的 mount unmount 节点。
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.
并且这样就要求用户的 getPopupContainer 必须稳定,不能出现以下的情况:
getPopupContainer() {
const div = new div
document.appendChild(div);
return div;
}
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.
这样就是 breaking changes 了。
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.
这个先保持原有的行为吧。
没问题的话,下周一合并发布个 2.0 吧,rc-menu 这边直接用就好。 |
这里引入了另外一个问题,因为要第二次 render 才能真正渲染 class Demo extends React.Component {
componentDidMount() {
console.log(this.box); // undefined
}
render() {
const popup = (
<div ref={node => this.box = node}>hello</div>
);
return (
<Trigger popupVisible={true} popup={popup}>
<div>hover me</div>
</Trigger>
)
}
} |
可以加个 warning?如果没有其他办法的话。。 |
setTimeout 终极大法可以的 componentDidMount() {
setTimeout(() => {
console.log(this.box);
}, 0);
} 先这么处理,后面升个 break change |
问题是用户会困惑。 |
|
这个没办法,后面 去掉 getContainer 里 findDOMNode,那个回传参数没用 ;
是的,只是目前这种的解决方法了 |
想了下去掉 |
ant-design/ant-design#5377 (comment)
facebook/react#10294 (comment)