You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/react-dom/src/client/ReactDOMComponent.js
+62-1Lines changed: 62 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -525,7 +525,6 @@ export function setInitialProperties(
525
525
listenToNonDelegatedEvent('error',domElement);
526
526
props=rawProps;
527
527
break;
528
-
case'img':
529
528
case'image':
530
529
case'link':
531
530
// We listen to these events in case to ensure emulated bubble
@@ -565,6 +564,68 @@ export function setInitialProperties(
565
564
// listeners still fire for the invalid event.
566
565
listenToNonDelegatedEvent('invalid',domElement);
567
566
break;
567
+
// img tags previously were implemented as void elements with non delegated events however Safari (and possibly Firefox)Collapse commentComment on line R1034eps1lon commented on Jul 15, 2024 eps1lonon Jul 15, 2024CollaboratorMore actionsSafari truly is the new IE.React😄React with 😄3gnoff, bthall16 and imagekitioWrite a replyResolve comment
568
+
// begin fetching the image as soon as the `src` or `srcSet` property is set and if we set these before other properties
569
+
// that can modify the request (such as crossorigin) or the resource fetch (such as sizes) then the browser will load
570
+
// the wrong thing or load more than one thing. This implementation ensures src and srcSet are set on the instance last
571
+
case'img': {
572
+
listenToNonDelegatedEvent('error',domElement);
573
+
listenToNonDelegatedEvent('load',domElement);
574
+
// Mostly a port of Void Element logic with special casing to ensure srcset and src are set last
575
+
let hasSrc =false;
576
+
lethasSrcSet=false;
577
+
for(constpropKeyinrawProps){
578
+
if(!rawProps.hasOwnProperty(propKey)){
579
+
continue;
580
+
}
581
+
const propValue =rawProps[propKey];
582
+
if(propValue==null){
583
+
continue;
584
+
}
585
+
switch(propKey){
586
+
case'src':
587
+
hasSrc=true;
588
+
break;
589
+
case'srcSet':
590
+
hasSrcSet=true;
591
+
break;
592
+
case'children':
593
+
case'dangerouslySetInnerHTML': {
594
+
// TODO: Can we make this a DEV warning to avoid this deny list?
595
+
thrownewError(
596
+
`${tag} is a void element tag and must neither have \`children\` nor `+
597
+
'use `dangerouslySetInnerHTML`.',
598
+
);
599
+
}
600
+
// defaultChecked and defaultValue are ignored by setProp
0 commit comments