30
import {NotPending} from '../shared/ReactDOMFormActions';
31
32
import {getCurrentRootHostContainer} from 'react-reconciler/src/ReactFiberHostContext';
33
+import {runWithFiberInDEV} from 'react-reconciler/src/ReactCurrentFiber';
34
35
import hasOwnProperty from 'shared/hasOwnProperty';
36
import {checkAttributeStringCoercion} from 'shared/CheckStringCoercion';
44
import {
45
precacheFiberNode,
46
updateFiberProps,
47
+ getFiberCurrentPropsFromNode,
48
+ getInstanceFromNode,
49
getClosestInstanceFromNode,
50
getFiberFromScopeInstance,
51
getInstanceFromNode as getInstanceFromNodeDOMTree,
824
}
825
}
826
827
+function warnForReactChildrenConflict(container: Container): void {
828
+ if (__DEV__) {
829
+ if ((container: any).__reactWarnedAboutChildrenConflict) {
830
+ return;
831
+ }
832
+ const props = getFiberCurrentPropsFromNode(container);
833
+ if (props !== null) {
834
+ const fiber = getInstanceFromNode(container);
835
+ if (fiber !== null) {
836
+ if (
837
+ typeof props.children === 'string' ||
838
+ typeof props.children === 'number'
839
+ ) {
840
+ (container: any).__reactWarnedAboutChildrenConflict = true;
841
+ // Run the warning with the Fiber of the container for context of where the children are specified.
842
+ // We could also maybe use the Portal. The current execution context is the child being added.
843
+ runWithFiberInDEV(fiber, () => {
844
+ console.error(
845
+ 'Cannot use a ref on a React element as a container to `createRoot` or `createPortal` ' +
846
+ 'if that element also sets "children" text content using React. It should be a leaf with no children. ' +
847
+ "Otherwise it's ambiguous which children should be used.",
848
+ );
849
+ });
850
+ } else if (props.dangerouslySetInnerHTML != null) {
851
+ (container: any).__reactWarnedAboutChildrenConflict = true;
852
+ runWithFiberInDEV(fiber, () => {
853
+ console.error(
854
+ 'Cannot use a ref on a React element as a container to `createRoot` or `createPortal` ' +
855
+ 'if that element also sets "dangerouslySetInnerHTML" using React. It should be a leaf with no children. ' +
856
+ "Otherwise it's ambiguous which children should be used.",
857
+ );
858
+ });
859
+ }
860
+ }
861
+ }
862
+ }
863
+}
864
+
865
export function appendChildToContainer(
866
container: Container,
867
child: Instance | TextInstance,
868
): void {
869
+ if (__DEV__) {
870
+ warnForReactChildrenConflict(container);
871
+ }
872
let parentNode: DocumentFragment | Element;
873
if (container.nodeType === DOCUMENT_NODE) {
874
parentNode = (container: any).body;
932
child: Instance | TextInstance,
933
beforeChild: Instance | TextInstance | SuspenseInstance,
934
): void {
935
+ if (__DEV__) {
936
+ warnForReactChildrenConflict(container);
937
+ }
938
let parentNode: DocumentFragment | Element;
939
if (container.nodeType === DOCUMENT_NODE) {
940
parentNode = (container: any).body;