@@ -441,108 +441,110 @@ describe('ReactDOMComponent', () => {
441
441
expect ( node . hasAttribute ( 'data-foo' ) ) . toBe ( false ) ;
442
442
} ) ;
443
443
444
- it ( 'should not add an empty src attribute' , ( ) => {
445
- const container = document . createElement ( 'div' ) ;
446
- expect ( ( ) => ReactDOM . render ( < img src = "" /> , container ) ) . toErrorDev (
447
- 'An empty string ("") was passed to the src attribute. ' +
448
- 'This may cause the browser to download the whole page again over the network. ' +
449
- 'To fix this, either do not render the element at all ' +
450
- 'or pass null to src instead of an empty string.' ,
451
- ) ;
452
- const node = container . firstChild ;
453
- expect ( node . hasAttribute ( 'src' ) ) . toBe ( false ) ;
444
+ if ( ReactFeatureFlags . enableFilterEmptyStringAttributesDOM ) {
445
+ it ( 'should not add an empty src attribute' , ( ) => {
446
+ const container = document . createElement ( 'div' ) ;
447
+ expect ( ( ) => ReactDOM . render ( < img src = "" /> , container ) ) . toErrorDev (
448
+ 'An empty string ("") was passed to the src attribute. ' +
449
+ 'This may cause the browser to download the whole page again over the network. ' +
450
+ 'To fix this, either do not render the element at all ' +
451
+ 'or pass null to src instead of an empty string.' ,
452
+ ) ;
453
+ const node = container . firstChild ;
454
+ expect ( node . hasAttribute ( 'src' ) ) . toBe ( false ) ;
454
455
455
- ReactDOM . render ( < img src = "abc" /> , container ) ;
456
- expect ( node . hasAttribute ( 'src' ) ) . toBe ( true ) ;
456
+ ReactDOM . render ( < img src = "abc" /> , container ) ;
457
+ expect ( node . hasAttribute ( 'src' ) ) . toBe ( true ) ;
457
458
458
- expect ( ( ) => ReactDOM . render ( < img src = "" /> , container ) ) . toErrorDev (
459
- 'An empty string ("") was passed to the src attribute. ' +
460
- 'This may cause the browser to download the whole page again over the network. ' +
461
- 'To fix this, either do not render the element at all ' +
462
- 'or pass null to src instead of an empty string.' ,
463
- ) ;
464
- expect ( node . hasAttribute ( 'src' ) ) . toBe ( false ) ;
465
- } ) ;
459
+ expect ( ( ) => ReactDOM . render ( < img src = "" /> , container ) ) . toErrorDev (
460
+ 'An empty string ("") was passed to the src attribute. ' +
461
+ 'This may cause the browser to download the whole page again over the network. ' +
462
+ 'To fix this, either do not render the element at all ' +
463
+ 'or pass null to src instead of an empty string.' ,
464
+ ) ;
465
+ expect ( node . hasAttribute ( 'src' ) ) . toBe ( false ) ;
466
+ } ) ;
466
467
467
- it ( 'should not add an empty href attribute' , ( ) => {
468
- const container = document . createElement ( 'div' ) ;
469
- expect ( ( ) => ReactDOM . render ( < link href = "" /> , container ) ) . toErrorDev (
470
- 'An empty string ("") was passed to the href attribute. ' +
471
- 'To fix this, either do not render the element at all ' +
472
- 'or pass null to href instead of an empty string.' ,
473
- ) ;
474
- const node = container . firstChild ;
475
- expect ( node . hasAttribute ( 'href' ) ) . toBe ( false ) ;
468
+ it ( 'should not add an empty href attribute' , ( ) => {
469
+ const container = document . createElement ( 'div' ) ;
470
+ expect ( ( ) => ReactDOM . render ( < link href = "" /> , container ) ) . toErrorDev (
471
+ 'An empty string ("") was passed to the href attribute. ' +
472
+ 'To fix this, either do not render the element at all ' +
473
+ 'or pass null to href instead of an empty string.' ,
474
+ ) ;
475
+ const node = container . firstChild ;
476
+ expect ( node . hasAttribute ( 'href' ) ) . toBe ( false ) ;
476
477
477
- ReactDOM . render ( < link href = "abc" /> , container ) ;
478
- expect ( node . hasAttribute ( 'href' ) ) . toBe ( true ) ;
478
+ ReactDOM . render ( < link href = "abc" /> , container ) ;
479
+ expect ( node . hasAttribute ( 'href' ) ) . toBe ( true ) ;
479
480
480
- expect ( ( ) => ReactDOM . render ( < link href = "" /> , container ) ) . toErrorDev (
481
- 'An empty string ("") was passed to the href attribute. ' +
482
- 'To fix this, either do not render the element at all ' +
483
- 'or pass null to href instead of an empty string.' ,
484
- ) ;
485
- expect ( node . hasAttribute ( 'href' ) ) . toBe ( false ) ;
486
- } ) ;
481
+ expect ( ( ) => ReactDOM . render ( < link href = "" /> , container ) ) . toErrorDev (
482
+ 'An empty string ("") was passed to the href attribute. ' +
483
+ 'To fix this, either do not render the element at all ' +
484
+ 'or pass null to href instead of an empty string.' ,
485
+ ) ;
486
+ expect ( node . hasAttribute ( 'href' ) ) . toBe ( false ) ;
487
+ } ) ;
487
488
488
- it ( 'should not add an empty action attribute' , ( ) => {
489
- const container = document . createElement ( 'div' ) ;
490
- expect ( ( ) => ReactDOM . render ( < form action = "" /> , container ) ) . toErrorDev (
491
- 'An empty string ("") was passed to the action attribute. ' +
492
- 'To fix this, either do not render the element at all ' +
493
- 'or pass null to action instead of an empty string.' ,
494
- ) ;
495
- const node = container . firstChild ;
496
- expect ( node . hasAttribute ( 'action' ) ) . toBe ( false ) ;
489
+ it ( 'should not add an empty action attribute' , ( ) => {
490
+ const container = document . createElement ( 'div' ) ;
491
+ expect ( ( ) => ReactDOM . render ( < form action = "" /> , container ) ) . toErrorDev (
492
+ 'An empty string ("") was passed to the action attribute. ' +
493
+ 'To fix this, either do not render the element at all ' +
494
+ 'or pass null to action instead of an empty string.' ,
495
+ ) ;
496
+ const node = container . firstChild ;
497
+ expect ( node . hasAttribute ( 'action' ) ) . toBe ( false ) ;
497
498
498
- ReactDOM . render ( < form action = "abc" /> , container ) ;
499
- expect ( node . hasAttribute ( 'action' ) ) . toBe ( true ) ;
499
+ ReactDOM . render ( < form action = "abc" /> , container ) ;
500
+ expect ( node . hasAttribute ( 'action' ) ) . toBe ( true ) ;
500
501
501
- expect ( ( ) => ReactDOM . render ( < form action = "" /> , container ) ) . toErrorDev (
502
- 'An empty string ("") was passed to the action attribute. ' +
503
- 'To fix this, either do not render the element at all ' +
504
- 'or pass null to action instead of an empty string.' ,
505
- ) ;
506
- expect ( node . hasAttribute ( 'action' ) ) . toBe ( false ) ;
507
- } ) ;
502
+ expect ( ( ) => ReactDOM . render ( < form action = "" /> , container ) ) . toErrorDev (
503
+ 'An empty string ("") was passed to the action attribute. ' +
504
+ 'To fix this, either do not render the element at all ' +
505
+ 'or pass null to action instead of an empty string.' ,
506
+ ) ;
507
+ expect ( node . hasAttribute ( 'action' ) ) . toBe ( false ) ;
508
+ } ) ;
508
509
509
- it ( 'should not add an empty formAction attribute' , ( ) => {
510
- const container = document . createElement ( 'div' ) ;
511
- expect ( ( ) =>
512
- ReactDOM . render ( < button formAction = "" /> , container ) ,
513
- ) . toErrorDev (
514
- 'An empty string ("") was passed to the formAction attribute. ' +
515
- 'To fix this, either do not render the element at all ' +
516
- 'or pass null to formAction instead of an empty string.' ,
517
- ) ;
518
- const node = container . firstChild ;
519
- expect ( node . hasAttribute ( 'formAction' ) ) . toBe ( false ) ;
510
+ it ( 'should not add an empty formAction attribute' , ( ) => {
511
+ const container = document . createElement ( 'div' ) ;
512
+ expect ( ( ) =>
513
+ ReactDOM . render ( < button formAction = "" /> , container ) ,
514
+ ) . toErrorDev (
515
+ 'An empty string ("") was passed to the formAction attribute. ' +
516
+ 'To fix this, either do not render the element at all ' +
517
+ 'or pass null to formAction instead of an empty string.' ,
518
+ ) ;
519
+ const node = container . firstChild ;
520
+ expect ( node . hasAttribute ( 'formAction' ) ) . toBe ( false ) ;
520
521
521
- ReactDOM . render ( < button formAction = "abc" /> , container ) ;
522
- expect ( node . hasAttribute ( 'formAction' ) ) . toBe ( true ) ;
522
+ ReactDOM . render ( < button formAction = "abc" /> , container ) ;
523
+ expect ( node . hasAttribute ( 'formAction' ) ) . toBe ( true ) ;
523
524
524
- expect ( ( ) =>
525
- ReactDOM . render ( < button formAction = "" /> , container ) ,
526
- ) . toErrorDev (
527
- 'An empty string ("") was passed to the formAction attribute. ' +
528
- 'To fix this, either do not render the element at all ' +
529
- 'or pass null to formAction instead of an empty string.' ,
530
- ) ;
531
- expect ( node . hasAttribute ( 'formAction' ) ) . toBe ( false ) ;
532
- } ) ;
525
+ expect ( ( ) =>
526
+ ReactDOM . render ( < button formAction = "" /> , container ) ,
527
+ ) . toErrorDev (
528
+ 'An empty string ("") was passed to the formAction attribute. ' +
529
+ 'To fix this, either do not render the element at all ' +
530
+ 'or pass null to formAction instead of an empty string.' ,
531
+ ) ;
532
+ expect ( node . hasAttribute ( 'formAction' ) ) . toBe ( false ) ;
533
+ } ) ;
533
534
534
- it ( 'should not filter attributes for custom elements' , ( ) => {
535
- const container = document . createElement ( 'div' ) ;
536
- ReactDOM . render (
537
- < some-custom-element action = "" formAction = "" href = "" src = "" /> ,
538
- container ,
539
- ) ;
540
- const node = container . firstChild ;
541
- expect ( node . hasAttribute ( 'action' ) ) . toBe ( true ) ;
542
- expect ( node . hasAttribute ( 'formAction' ) ) . toBe ( true ) ;
543
- expect ( node . hasAttribute ( 'href' ) ) . toBe ( true ) ;
544
- expect ( node . hasAttribute ( 'src' ) ) . toBe ( true ) ;
545
- } ) ;
535
+ it ( 'should not filter attributes for custom elements' , ( ) => {
536
+ const container = document . createElement ( 'div' ) ;
537
+ ReactDOM . render (
538
+ < some-custom-element action = "" formAction = "" href = "" src = "" /> ,
539
+ container ,
540
+ ) ;
541
+ const node = container . firstChild ;
542
+ expect ( node . hasAttribute ( 'action' ) ) . toBe ( true ) ;
543
+ expect ( node . hasAttribute ( 'formAction' ) ) . toBe ( true ) ;
544
+ expect ( node . hasAttribute ( 'href' ) ) . toBe ( true ) ;
545
+ expect ( node . hasAttribute ( 'src' ) ) . toBe ( true ) ;
546
+ } ) ;
547
+ }
546
548
547
549
it ( 'should apply React-specific aliases to HTML elements' , ( ) => {
548
550
const container = document . createElement ( 'div' ) ;
0 commit comments