MCPcopy Create free account
hub / github.com/reactjs/react-rails / unmountComponentAtNode

Function unmountComponentAtNode

lib/assets/react-source/development/react.js:28552–28603  ·  view source on GitHub ↗
(container)

Source from the content-addressed store, hash-verified

28550 return legacyRenderSubtreeIntoContainer(parentComponent, element, containerNode, false, callback);
28551 }
28552 function unmountComponentAtNode(container) {
28553 if (!isValidContainer(container)) {
28554 {
28555 throw Error( "unmountComponentAtNode(...): Target container is not a DOM element." );
28556 }
28557 }
28558
28559 {
28560 var isModernRoot = isContainerMarkedAsRoot(container) && container._reactRootContainer === undefined;
28561
28562 if (isModernRoot) {
28563 error('You are calling ReactDOM.unmountComponentAtNode() on a container that was previously ' + 'passed to ReactDOM.createRoot(). This is not supported. Did you mean to call root.unmount()?');
28564 }
28565 }
28566
28567 if (container._reactRootContainer) {
28568 {
28569 var rootEl = getReactRootElementInContainer(container);
28570 var renderedByDifferentReact = rootEl && !getInstanceFromNode$1(rootEl);
28571
28572 if (renderedByDifferentReact) {
28573 error("unmountComponentAtNode(): The node you're attempting to unmount " + 'was rendered by another copy of React.');
28574 }
28575 } // Unmount should not be batched.
28576
28577
28578 unbatchedUpdates(function () {
28579 legacyRenderSubtreeIntoContainer(null, null, container, false, function () {
28580 // $FlowFixMe This should probably use `delete container._reactRootContainer`
28581 container._reactRootContainer = null;
28582 unmarkContainerAsRoot(container);
28583 });
28584 }); // If you call unmountComponentAtNode twice in quick succession, you'll
28585 // get `true` twice. That's probably fine?
28586
28587 return true;
28588 } else {
28589 {
28590 var _rootEl = getReactRootElementInContainer(container);
28591
28592 var hasNonRootReactChild = !!(_rootEl && getInstanceFromNode$1(_rootEl)); // Check if the container itself is a React root node.
28593
28594 var isContainerReactRoot = container.nodeType === ELEMENT_NODE && isValidContainer(container.parentNode) && !!container.parentNode._reactRootContainer;
28595
28596 if (hasNonRootReactChild) {
28597 error("unmountComponentAtNode(): The node you're attempting to unmount " + 'was rendered by React and is not a top-level container. %s', isContainerReactRoot ? 'You may have accidentally passed in a React root node instead ' + 'of its container.' : 'Instead, have the parent component update its state and ' + 'rerender in order to remove this component.');
28598 }
28599 }
28600
28601 return false;
28602 }
28603 }
28604
28605 function createPortal(children, containerInfo, // TODO: figure out the API for cross-renderer implementation.
28606 implementation) {

Callers

nothing calls this directly

Calls 8

isValidContainerFunction · 0.85
isContainerMarkedAsRootFunction · 0.85
getInstanceFromNode$1Function · 0.85
unbatchedUpdatesFunction · 0.85
unmarkContainerAsRootFunction · 0.85
errorFunction · 0.70

Tested by

no test coverage detected