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
61 changes: 26 additions & 35 deletions compat/src/portals.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,34 @@ function Portal(props) {
_this.componentWillUnmount();
}

// 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) {
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
);
}
// When we come from a conditional render, on a mounted
// portal we should clear the DOM.
else if (_this._temp) {
_this.componentWillUnmount();
// 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
);
}

/**
Expand Down