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

Introducing ReactDOM unstable_createSandboxedPortal #11930

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/react-dom/src/client/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,20 @@ function createPortal(
'Target container is not a DOM element.',
);
// TODO: pass ReactDOM portal implementation as third argument
return ReactPortal.createPortal(children, container, null, key);
return ReactPortal.createPortal(children, container, null, key, false);
}

function createSandboxedPortal(
children: ReactNodeList,
container: DOMContainer,
key: ?string = null,
) {
invariant(
isValidContainer(container),
'Target container is not a DOM element.',
);
// TODO: pass ReactDOM portal implementation as third argument
return ReactPortal.createPortal(children, container, null, key, true);
}

const ReactDOM: Object = {
Expand Down Expand Up @@ -1291,6 +1304,8 @@ const ReactDOM: Object = {
return createPortal(...args);
},

unstable_createSandboxedPortal: createSandboxedPortal,

unstable_batchedUpdates: ReactGenericBatching.batchedUpdates,

unstable_deferredUpdates: DOMRenderer.deferredUpdates,
Expand Down
1 change: 1 addition & 0 deletions packages/react-reconciler/src/ReactFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ export function createFiberFromPortal(
containerInfo: portal.containerInfo,
pendingChildren: null, // Used by persistent updates
implementation: portal.implementation,
sandbox: portal.sandbox,
};
return fiber;
}
2 changes: 2 additions & 0 deletions packages/shared/ReactPortal.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ export function createPortal(
// TODO: figure out the API for cross-renderer implementation.
implementation: any,
key: ?string = null,
sandbox: ?boolean = false,
): ReactPortal {
return {
// This tag allow us to uniquely identify this as a React Portal
$$typeof: REACT_PORTAL_TYPE,
key: key == null ? null : '' + key,
children,
containerInfo,
sandbox,
implementation,
};
}
5 changes: 4 additions & 1 deletion packages/shared/ReactTreeTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {HostComponent} from './ReactTypeOfWork';
import {HostComponent, HostPortal} from './ReactTypeOfWork';

function getParent(inst) {
do {
Expand All @@ -15,6 +15,9 @@ function getParent(inst) {
// events to their parent. We could also go through parentNode on the
// host node but that wouldn't work for React Native and doesn't let us
// do the portal feature.
if (inst && inst.tag === HostPortal && inst.stateNode.sandbox) {
return null;
}
} while (inst && inst.tag !== HostComponent);
if (inst) {
return inst;
Expand Down