MCPcopy Index your code
hub / github.com/react/react / pushAttribute

Function pushAttribute

packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js:1533–1848  ·  view source on GitHub ↗
(
  target: Array<Chunk | PrecomputedChunk>,
  name: string,
  value: string | boolean | number | Function | Object, // not null or undefined
)

Source from the content-addressed store, hash-verified

1531}
1532
1533function pushAttribute(
1534 target: Array<Chunk | PrecomputedChunk>,
1535 name: string,
1536 value: string | boolean | number | Function | Object, // not null or undefined
1537): void {
1538 switch (name) {
1539 // These are very common props and therefore are in the beginning of the switch.
1540 // TODO: aria-label is a very common prop but allows booleans so is not like the others
1541 // but should ideally go in this list too.
1542 case 'className': {
1543 pushStringAttribute(target, 'class', value);
1544 break;
1545 }
1546 case 'tabIndex': {
1547 pushStringAttribute(target, 'tabindex', value);
1548 break;
1549 }
1550 case 'dir':
1551 case 'role':
1552 case 'viewBox':
1553 case 'width':
1554 case 'height': {
1555 pushStringAttribute(target, name, value);
1556 break;
1557 }
1558 case 'style': {
1559 pushStyleAttribute(target, value);
1560 return;
1561 }
1562 case 'src': {
1563 if (enableSrcObject && typeof value === 'object' && value !== null) {
1564 if (typeof Blob === 'function' && value instanceof Blob) {
1565 pushSrcObjectAttribute(target, value);
1566 return;
1567 }
1568 }
1569 // Fallthrough to general urls
1570 }
1571 case 'href': {
1572 if (value === '') {
1573 if (__DEV__) {
1574 if (name === 'src') {
1575 console.error(
1576 'An empty string ("") was passed to the %s attribute. ' +
1577 'This may cause the browser to download the whole page again over the network. ' +
1578 'To fix this, either do not render the element at all ' +
1579 'or pass null to %s instead of an empty string.',
1580 name,
1581 name,
1582 );
1583 } else {
1584 console.error(
1585 'An empty string ("") was passed to the %s attribute. ' +
1586 'To fix this, either do not render the element at all ' +
1587 'or pass null to %s instead of an empty string.',
1588 name,
1589 name,
1590 );

Callers 15

pushFormActionAttributeFunction · 0.85
pushStartAnchorFunction · 0.85
pushStartObjectFunction · 0.85
pushStartSelectFunction · 0.85
pushStartOptionFunction · 0.85
pushStartFormFunction · 0.85
pushInputFunction · 0.85
pushStartButtonFunction · 0.85
pushStartTextAreaFunction · 0.85
pushLinkImplFunction · 0.85
pushStyleImplFunction · 0.85
pushSelfClosingFunction · 0.85

Calls 11

stringToChunkFunction · 0.90
pushStringAttributeFunction · 0.85
pushStyleAttributeFunction · 0.85
pushSrcObjectAttributeFunction · 0.85
sanitizeURLFunction · 0.85
escapeTextForBrowserFunction · 0.85
pushBooleanAttributeFunction · 0.85
isAttributeNameSafeFunction · 0.85
errorMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected