77 * @flow
88 */
99
10- import { enableDeprecatedFlareAPI } from 'shared/ReactFeatureFlags' ;
10+ import {
11+ enableDeprecatedFlareAPI ,
12+ enableFilterEmptyStringAttributesDOM ,
13+ } from 'shared/ReactFeatureFlags' ;
1114
1215type PropertyType = 0 | 1 | 2 | 3 | 4 | 5 | 6 ;
1316
@@ -52,6 +55,7 @@ export type PropertyInfo = {|
5255 + propertyName : string ,
5356 + type : PropertyType ,
5457 + sanitizeURL : boolean ,
58+ + removeEmptyString : boolean ,
5559| } ;
5660
5761/* eslint-disable max-len */
@@ -146,6 +150,15 @@ export function shouldRemoveAttribute(
146150 propertyInfo : PropertyInfo | null ,
147151 isCustomComponentTag : boolean ,
148152) : boolean {
153+ if ( enableFilterEmptyStringAttributesDOM ) {
154+ if (
155+ propertyInfo !== null &&
156+ propertyInfo . removeEmptyString === true &&
157+ value === ''
158+ ) {
159+ return true ;
160+ }
161+ }
149162 if ( value === null || typeof value === 'undefined' ) {
150163 return true ;
151164 }
@@ -188,6 +201,7 @@ function PropertyInfoRecord(
188201 attributeName : string ,
189202 attributeNamespace : string | null ,
190203 sanitizeURL : boolean ,
204+ removeEmptyString : boolean ,
191205) {
192206 this . acceptsBooleans =
193207 type === BOOLEANISH_STRING ||
@@ -199,6 +213,7 @@ function PropertyInfoRecord(
199213 this . propertyName = name ;
200214 this . type = type ;
201215 this . sanitizeURL = sanitizeURL ;
216+ this . removeEmptyString = removeEmptyString ;
202217}
203218
204219// When adding attributes to this list, be sure to also add them to
@@ -232,6 +247,7 @@ reservedProps.forEach(name => {
232247 name , // attributeName
233248 null , // attributeNamespace
234249 false , // sanitizeURL
250+ false , // removeEmptyString
235251 ) ;
236252} ) ;
237253
@@ -250,6 +266,7 @@ reservedProps.forEach(name => {
250266 attributeName , // attributeName
251267 null , // attributeNamespace
252268 false , // sanitizeURL
269+ false , // removeEmptyString
253270 ) ;
254271} ) ;
255272
@@ -264,6 +281,7 @@ reservedProps.forEach(name => {
264281 name . toLowerCase ( ) , // attributeName
265282 null , // attributeNamespace
266283 false , // sanitizeURL
284+ false , // removeEmptyString
267285 ) ;
268286} ) ;
269287
@@ -284,6 +302,7 @@ reservedProps.forEach(name => {
284302 name , // attributeName
285303 null , // attributeNamespace
286304 false , // sanitizeURL
305+ false , // removeEmptyString
287306 ) ;
288307} ) ;
289308
@@ -322,6 +341,7 @@ reservedProps.forEach(name => {
322341 name . toLowerCase ( ) , // attributeName
323342 null , // attributeNamespace
324343 false , // sanitizeURL
344+ false , // removeEmptyString
325345 ) ;
326346} ) ;
327347
@@ -346,6 +366,7 @@ reservedProps.forEach(name => {
346366 name , // attributeName
347367 null , // attributeNamespace
348368 false , // sanitizeURL
369+ false , // removeEmptyString
349370 ) ;
350371} ) ;
351372
@@ -366,6 +387,7 @@ reservedProps.forEach(name => {
366387 name , // attributeName
367388 null , // attributeNamespace
368389 false , // sanitizeURL
390+ false , // removeEmptyString
369391 ) ;
370392} ) ;
371393
@@ -387,6 +409,7 @@ reservedProps.forEach(name => {
387409 name , // attributeName
388410 null , // attributeNamespace
389411 false , // sanitizeURL
412+ false , // removeEmptyString
390413 ) ;
391414} ) ;
392415
@@ -399,6 +422,7 @@ reservedProps.forEach(name => {
399422 name . toLowerCase ( ) , // attributeName
400423 null , // attributeNamespace
401424 false , // sanitizeURL
425+ false , // removeEmptyString
402426 ) ;
403427} ) ;
404428
@@ -497,6 +521,7 @@ const capitalize = token => token[1].toUpperCase();
497521 attributeName ,
498522 null , // attributeNamespace
499523 false , // sanitizeURL
524+ false , // removeEmptyString
500525 ) ;
501526} ) ;
502527
@@ -521,6 +546,7 @@ const capitalize = token => token[1].toUpperCase();
521546 attributeName ,
522547 'http://www.w3.org/1999/xlink' ,
523548 false , // sanitizeURL
549+ false , // removeEmptyString
524550 ) ;
525551} ) ;
526552
@@ -542,6 +568,7 @@ const capitalize = token => token[1].toUpperCase();
542568 attributeName ,
543569 'http://www.w3.org/XML/1998/namespace' ,
544570 false , // sanitizeURL
571+ false , // removeEmptyString
545572 ) ;
546573} ) ;
547574
@@ -556,6 +583,7 @@ const capitalize = token => token[1].toUpperCase();
556583 attributeName . toLowerCase ( ) , // attributeName
557584 null , // attributeNamespace
558585 false , // sanitizeURL
586+ false , // removeEmptyString
559587 ) ;
560588} ) ;
561589
@@ -569,6 +597,7 @@ properties[xlinkHref] = new PropertyInfoRecord(
569597 'xlink:href' ,
570598 'http://www.w3.org/1999/xlink' ,
571599 true , // sanitizeURL
600+ false , // removeEmptyString
572601) ;
573602
574603[ 'src' , 'href' , 'action' , 'formAction' ] . forEach ( attributeName => {
@@ -579,5 +608,6 @@ properties[xlinkHref] = new PropertyInfoRecord(
579608 attributeName . toLowerCase ( ) , // attributeName
580609 null , // attributeNamespace
581610 true , // sanitizeURL
611+ true , // removeEmptyString
582612 ) ;
583613} ) ;
0 commit comments