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

fix react-frame-component by supporting nullish portals #3896

Merged
merged 8 commits into from
Jul 11, 2023
57 changes: 28 additions & 29 deletions compat/src/portals.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,38 @@ function Portal(props) {

// When props.vnode is undefined/false/null we are dealing with some kind of
// conditional vnode. This should not trigger a render.
if (props._vnode) {
JoviDeCroock marked this conversation as resolved.
Show resolved Hide resolved
if (!_this._temp) {
_this._container = container;
if (!_this._temp) {
_this._container = container;

// Create a fake DOM parent node that manages a subset of `container`'s children:
_this._temp = {
nodeType: 1,
parentNode: container,
childNodes: [],
appendChild(child) {
this.childNodes.push(child);
_this._container.appendChild(child);
},
insertBefore(child, before) {
this.childNodes.push(child);
_this._container.appendChild(child);
},
removeChild(child) {
this.childNodes.splice(this.childNodes.indexOf(child) >>> 1, 1);
_this._container.removeChild(child);
}
};
}

// Render our wrapping element into temp.
render(
createElement(ContextProvider, { context: _this.context }, props._vnode),
_this._temp
);
// Create a fake DOM parent node that manages a subset of `container`'s children:
_this._temp = {
nodeType: 1,
parentNode: container,
childNodes: [],
appendChild(child) {
this.childNodes.push(child);
_this._container.appendChild(child);
},
insertBefore(child, before) {
this.childNodes.push(child);
_this._container.appendChild(child);
},
removeChild(child) {
this.childNodes.splice(this.childNodes.indexOf(child) >>> 1, 1);
_this._container.removeChild(child);
}
};
}

// Render our wrapping element into temp.
render(
createElement(ContextProvider, { context: _this.context }, props._vnode),
_this._temp
);

// When we come from a conditional render, on a mounted
// portal we should clear the DOM.
else if (_this._temp) {
if (!props._vnode && _this._temp) {
Copy link
Member

Choose a reason for hiding this comment

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

I think we can just remove this condition and the this.unmount call now. When a null vnode is received, we will render the provider with null as it's only child, which produces the same result as calling unmount (because there is no componentDidUnmount method on this provider).

_this.componentWillUnmount();
}
}
Expand Down