MCPcopy
hub / github.com/facebook/react / getResource

Function getResource

packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js:5032–5204  ·  view source on GitHub ↗
(
  type: string,
  currentProps: any,
  pendingProps: any,
  currentResource: null | Resource,
)

Source from the content-addressed store, hash-verified

5030
5031// This function is called in begin work and we should always have a currentDocument set
5032export function getResource(
5033 type: string,
5034 currentProps: any,
5035 pendingProps: any,
5036 currentResource: null | Resource,
5037): null | Resource {
5038 const resourceRoot = getCurrentResourceRoot();
5039 if (!resourceRoot) {
5040 throw new Error(
5041 '"resourceRoot" was expected to exist. This is a bug in React.',
5042 );
5043 }
5044 switch (type) {
5045 case 'meta':
5046 case 'title': {
5047 return null;
5048 }
5049 case 'style': {
5050 if (
5051 typeof pendingProps.precedence === 'string' &&
5052 typeof pendingProps.href === 'string'
5053 ) {
5054 const key = getStyleKey(pendingProps.href);
5055 const styles = getResourcesFromRoot(resourceRoot).hoistableStyles;
5056 let resource = styles.get(key);
5057 if (!resource) {
5058 resource = {
5059 type: 'style',
5060 instance: null,
5061 count: 0,
5062 state: null,
5063 };
5064 styles.set(key, resource);
5065 }
5066 return resource;
5067 }
5068 return {
5069 type: 'void',
5070 instance: null,
5071 count: 0,
5072 state: null,
5073 };
5074 }
5075 case 'link': {
5076 if (
5077 pendingProps.rel === 'stylesheet' &&
5078 typeof pendingProps.href === 'string' &&
5079 typeof pendingProps.precedence === 'string'
5080 ) {
5081 const qualifiedProps: StylesheetQualifyingProps = pendingProps;
5082 const key = getStyleKey(qualifiedProps.href);
5083
5084 const styles = getResourcesFromRoot(resourceRoot).hoistableStyles;
5085
5086 let resource = styles.get(key);
5087 if (!resource) {
5088 // We asserted this above but Flow can't figure out that the type satisfies
5089 const ownerDocument = getDocumentFromRoot(resourceRoot);

Callers 1

updateHostHoistableFunction · 0.90

Calls 12

getResourcesFromRootFunction · 0.90
getCurrentResourceRootFunction · 0.85
getStyleKeyFunction · 0.85
getDocumentFromRootFunction · 0.85
preloadStylesheetFunction · 0.85
getScriptKeyFunction · 0.85
setMethod · 0.80
getMethod · 0.65
hasMethod · 0.65

Tested by

no test coverage detected