preinitModule() — react Function Reference
Architecture documentation for the preinitModule() function in ReactDOMFloat.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD 76790122_fb77_9e84_74d3_ed16373affff["preinitModule()"] 3ea12e77_bd9c_ec2a_fb3c_db692f520137["ReactDOMFloat.js"] 76790122_fb77_9e84_74d3_ed16373affff -->|defined in| 3ea12e77_bd9c_ec2a_fb3c_db692f520137 24cdce56_f095_bb7e_3cbd_6bc0a497e302["getValueDescriptorExpectingObjectForWarning()"] 76790122_fb77_9e84_74d3_ed16373affff -->|calls| 24cdce56_f095_bb7e_3cbd_6bc0a497e302 8ae8338e_757b_2763_77d2_0bd8938bd5bd["getValueDescriptorExpectingEnumForWarning()"] 76790122_fb77_9e84_74d3_ed16373affff -->|calls| 8ae8338e_757b_2763_77d2_0bd8938bd5bd style 76790122_fb77_9e84_74d3_ed16373affff fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/react-dom/src/shared/ReactDOMFloat.js lines 262–333
export function preinitModule(href: string, options?: ?PreinitModuleOptions) {
if (__DEV__) {
let encountered = '';
if (typeof href !== 'string' || !href) {
encountered += ` The \`href\` argument encountered was ${getValueDescriptorExpectingObjectForWarning(
href,
)}.`;
}
if (options !== undefined && typeof options !== 'object') {
encountered += ` The \`options\` argument encountered was ${getValueDescriptorExpectingObjectForWarning(
options,
)}.`;
} else if (options && 'as' in options && options.as !== 'script') {
encountered += ` The \`as\` option encountered was ${getValueDescriptorExpectingEnumForWarning(
options.as,
)}.`;
}
if (encountered) {
console.error(
'ReactDOM.preinitModule(): Expected up to two arguments, a non-empty `href` string and, optionally, an `options` object with a valid `as` property.%s',
encountered,
);
} else {
const as =
options && typeof options.as === 'string' ? options.as : 'script';
switch (as) {
case 'script': {
break;
}
// We have an invalid as type and need to warn
default: {
const typeOfAs = getValueDescriptorExpectingEnumForWarning(as);
console.error(
'ReactDOM.preinitModule(): Currently the only supported "as" type for this function is "script"' +
' but received "%s" instead. This warning was generated for `href` "%s". In the future other' +
' module types will be supported, aligning with the import-attributes proposal. Learn more here:' +
' (https://github.com/tc39/proposal-import-attributes)',
typeOfAs,
href,
);
}
}
}
}
if (typeof href === 'string') {
if (typeof options === 'object' && options !== null) {
if (options.as == null || options.as === 'script') {
const crossOrigin = getCrossOriginStringAs(
options.as,
options.crossOrigin,
);
ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
.M(/* preinitModuleScript */ href, {
crossOrigin,
integrity:
typeof options.integrity === 'string'
? options.integrity
: undefined,
nonce:
typeof options.nonce === 'string' ? options.nonce : undefined,
});
}
} else if (options == null) {
ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
.M(/* preinitModuleScript */ href);
}
}
// We don't error because preinit needs to be resilient to being called in a variety of scopes
// and the runtime may not be capable of responding. The function is optimistic and not critical
// so we favor silent bailout over warning or erroring.
}
Domain
Subdomains
Source
Frequently Asked Questions
What does preinitModule() do?
preinitModule() is a function in the react codebase, defined in packages/react-dom/src/shared/ReactDOMFloat.js.
Where is preinitModule() defined?
preinitModule() is defined in packages/react-dom/src/shared/ReactDOMFloat.js at line 262.
What does preinitModule() call?
preinitModule() calls 2 function(s): getValueDescriptorExpectingEnumForWarning, getValueDescriptorExpectingObjectForWarning.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free