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 {
2222 private handleStyleAttributeMutation ;
2323 private handleGenericAttributeMutation ;
2424 private extractStyles ;
25+ private isElementAddedByTranslation ;
2526}
Original file line number Diff line number Diff line change @@ -1565,6 +1565,9 @@ class ExternalMutationTracker {
15651565 if ( ! this . shouldTrackChangeCallback ( element ) ) {
15661566 continue ;
15671567 }
1568+ if ( this . isElementAddedByTranslation ( element ) ) {
1569+ continue ;
1570+ }
15681571 let isChangeInAddedElement = false ;
15691572 for ( const addedElement of this . addedElements ) {
15701573 if ( addedElement . contains ( element ) ) {
@@ -1603,6 +1606,9 @@ class ExternalMutationTracker {
16031606 this . removedElements . splice ( this . removedElements . indexOf ( node ) , 1 ) ;
16041607 return ;
16051608 }
1609+ if ( this . isElementAddedByTranslation ( node ) ) {
1610+ return ;
1611+ }
16061612 this . addedElements . push ( node ) ;
16071613 } ) ;
16081614 mutation . removedNodes . forEach ( ( node ) => {
@@ -1711,6 +1717,9 @@ class ExternalMutationTracker {
17111717 } ) ;
17121718 return styleObject ;
17131719 }
1720+ isElementAddedByTranslation ( element ) {
1721+ return element . tagName === 'FONT' && element . getAttribute ( 'style' ) === 'vertical-align: inherit;' ;
1722+ }
17141723}
17151724
17161725class ChildComponentWrapper {
Original file line number Diff line number Diff line change @@ -75,6 +75,10 @@ export default class {
7575 continue ;
7676 }
7777
78+ if ( this . isElementAddedByTranslation ( element ) ) {
79+ continue ;
80+ }
81+
7882 // ignore changes in elements that were externally-added
7983 let isChangeInAddedElement = false ;
8084 for ( const addedElement of this . addedElements ) {
@@ -133,6 +137,10 @@ export default class {
133137 return ;
134138 }
135139
140+ if ( this . isElementAddedByTranslation ( node ) ) {
141+ return ;
142+ }
143+
136144 this . addedElements . push ( node ) ;
137145 } ) ;
138146
@@ -293,4 +301,16 @@ export default class {
293301
294302 return styleObject ;
295303 }
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+ }
296316}
You can’t perform that action at this time.
0 commit comments