MCPcopy Index your code
hub / github.com/microsoft/SandDance / createElement

Function createElement

docs/external/js/react-dom.development.js:5977–6056  ·  view source on GitHub ↗
(type, props, rootContainerElement, parentNamespace)

Source from the content-addressed store, hash-verified

5975 }
5976
5977 function createElement(type, props, rootContainerElement, parentNamespace) {
5978 var isCustomComponentTag; // We create tags in the namespace of their parent container, except HTML
5979 // tags get no namespace.
5980
5981 var ownerDocument = getOwnerDocumentFromRootContainer(rootContainerElement);
5982 var domElement;
5983 var namespaceURI = parentNamespace;
5984
5985 if (namespaceURI === HTML_NAMESPACE$1) {
5986 namespaceURI = getIntrinsicNamespace(type);
5987 }
5988
5989 if (namespaceURI === HTML_NAMESPACE$1) {
5990 {
5991 isCustomComponentTag = isCustomComponent(type, props); // Should this check be gated by parent namespace? Not sure we want to
5992 // allow <SVG> or <mATH>.
5993
5994 if (!isCustomComponentTag && type !== type.toLowerCase()) {
5995 error('<%s /> is using incorrect casing. ' + 'Use PascalCase for React components, ' + 'or lowercase for HTML elements.', type);
5996 }
5997 }
5998
5999 if (type === 'script') {
6000 // Create the script via .innerHTML so its "parser-inserted" flag is
6001 // set to true and it does not execute
6002 var div = ownerDocument.createElement('div');
6003
6004 div.innerHTML = '<script><' + '/script>'; // eslint-disable-line
6005 // This is guaranteed to yield a script element.
6006
6007 var firstChild = div.firstChild;
6008 domElement = div.removeChild(firstChild);
6009 } else if (typeof props.is === 'string') {
6010 // $FlowIssue `createElement` should be updated for Web Components
6011 domElement = ownerDocument.createElement(type, {
6012 is: props.is
6013 });
6014 } else {
6015 // Separate else branch instead of using `props.is || undefined` above because of a Firefox bug.
6016 // See discussion in https://github.com/facebook/react/pull/6896
6017 // and discussion in https://bugzilla.mozilla.org/show_bug.cgi?id=1276240
6018 domElement = ownerDocument.createElement(type); // Normally attributes are assigned in `setInitialDOMProperties`, however the `multiple` and `size`
6019 // attributes on `select`s needs to be added before `option`s are inserted.
6020 // This prevents:
6021 // - a bug where the `select` does not scroll to the correct option because singular
6022 // `select` elements automatically pick the first item #13222
6023 // - a bug where the `select` set the first item as selected despite the `size` attribute #14239
6024 // See https://github.com/facebook/react/issues/13222
6025 // and https://github.com/facebook/react/issues/14239
6026
6027 if (type === 'select') {
6028 var node = domElement;
6029
6030 if (props.multiple) {
6031 node.multiple = true;
6032 } else if (props.size) {
6033 // Setting a size greater than 1 causes a select to behave like `multiple=true`, where
6034 // it is possible that no option is selected.

Callers 1

createInstanceFunction · 0.70

Calls 4

getIntrinsicNamespaceFunction · 0.85
isCustomComponentFunction · 0.85
errorFunction · 0.70

Tested by

no test coverage detected