( target: Array<Chunk | PrecomputedChunk>, name: string, value: string | boolean | number | Function | Object, // not null or undefined )
| 1531 | } |
| 1532 | |
| 1533 | function 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 | ); |
no test coverage detected