File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -22,4 +22,5 @@ export default class {
22
22
private handleStyleAttributeMutation ;
23
23
private handleGenericAttributeMutation ;
24
24
private extractStyles ;
25
+ private isElementAddedByTranslation ;
25
26
}
Original file line number Diff line number Diff line change @@ -1565,6 +1565,9 @@ class ExternalMutationTracker {
1565
1565
if ( ! this . shouldTrackChangeCallback ( element ) ) {
1566
1566
continue ;
1567
1567
}
1568
+ if ( this . isElementAddedByTranslation ( element ) ) {
1569
+ continue ;
1570
+ }
1568
1571
let isChangeInAddedElement = false ;
1569
1572
for ( const addedElement of this . addedElements ) {
1570
1573
if ( addedElement . contains ( element ) ) {
@@ -1603,6 +1606,9 @@ class ExternalMutationTracker {
1603
1606
this . removedElements . splice ( this . removedElements . indexOf ( node ) , 1 ) ;
1604
1607
return ;
1605
1608
}
1609
+ if ( this . isElementAddedByTranslation ( node ) ) {
1610
+ return ;
1611
+ }
1606
1612
this . addedElements . push ( node ) ;
1607
1613
} ) ;
1608
1614
mutation . removedNodes . forEach ( ( node ) => {
@@ -1711,6 +1717,9 @@ class ExternalMutationTracker {
1711
1717
} ) ;
1712
1718
return styleObject ;
1713
1719
}
1720
+ isElementAddedByTranslation ( element ) {
1721
+ return element . tagName === 'FONT' && element . getAttribute ( 'style' ) === 'vertical-align: inherit;' ;
1722
+ }
1714
1723
}
1715
1724
1716
1725
class ChildComponentWrapper {
Original file line number Diff line number Diff line change @@ -75,6 +75,10 @@ export default class {
75
75
continue ;
76
76
}
77
77
78
+ if ( this . isElementAddedByTranslation ( element ) ) {
79
+ continue ;
80
+ }
81
+
78
82
// ignore changes in elements that were externally-added
79
83
let isChangeInAddedElement = false ;
80
84
for ( const addedElement of this . addedElements ) {
@@ -133,6 +137,10 @@ export default class {
133
137
return ;
134
138
}
135
139
140
+ if ( this . isElementAddedByTranslation ( node ) ) {
141
+ return ;
142
+ }
143
+
136
144
this . addedElements . push ( node ) ;
137
145
} ) ;
138
146
@@ -293,4 +301,16 @@ export default class {
293
301
294
302
return styleObject ;
295
303
}
304
+
305
+ /**
306
+ * Helps avoid tracking changes by Chrome's translation feature.
307
+ *
308
+ * When Chrome translates, it mutates the dom in a way that triggers MutationObserver.
309
+ * This includes adding new elements wrapped in a <font> tag. This causes live
310
+ * components to incorrectly think that these new elements should persist through
311
+ * re-renders, causing duplicate text.
312
+ */
313
+ private isElementAddedByTranslation ( element : Element ) : boolean {
314
+ return element . tagName === 'FONT' && element . getAttribute ( 'style' ) === 'vertical-align: inherit;'
315
+ }
296
316
}
You can’t perform that action at this time.
0 commit comments