@@ -80,48 +80,50 @@ export default class GleapTooltipManager {
8080 ) ;
8181 window . addEventListener ( "resize" , handleResizeThrottled ) ;
8282
83- this . observer = new MutationObserver ( ( mutations ) => {
84- if ( self . lastUrl !== window . location . href ) {
85- self . lastUrl = window . location . href ;
86- self . filteredTooltips = self . getFilteredTooltips ( ) ;
87- }
83+ window . requestAnimationFrame ( ( ) => {
84+ this . observer = new MutationObserver ( ( mutations ) => {
85+ if ( self . lastUrl !== window . location . href ) {
86+ self . lastUrl = window . location . href ;
87+ self . filteredTooltips = self . getFilteredTooltips ( ) ;
88+ }
8889
89- mutations . forEach ( ( mutation ) => {
90- // Check for added nodes
91- mutation . addedNodes . forEach ( ( node ) => {
92- if ( node . nodeType === Node . ELEMENT_NODE ) {
93- self . processNodeInsertion ( node ) ;
94- }
95- } ) ;
90+ mutations . forEach ( ( mutation ) => {
91+ // Check for added nodes
92+ mutation . addedNodes . forEach ( ( node ) => {
93+ if ( node . nodeType === Node . ELEMENT_NODE ) {
94+ self . processNodeInsertion ( node ) ;
95+ }
96+ } ) ;
9697
97- // Check for removed nodes
98- mutation . removedNodes . forEach ( ( node ) => {
99- if (
100- node . nodeType === Node . ELEMENT_NODE &&
101- this . elementToFloatingUIMap . has ( node )
102- ) {
103- const floatingUI = this . elementToFloatingUIMap . get ( node ) ;
104- if ( floatingUI ) {
105- if ( floatingUI . tooltip ) {
106- floatingUI . tooltip . remove ( ) ;
98+ // Check for removed nodes
99+ mutation . removedNodes . forEach ( ( node ) => {
100+ if (
101+ node . nodeType === Node . ELEMENT_NODE &&
102+ this . elementToFloatingUIMap . has ( node )
103+ ) {
104+ const floatingUI = this . elementToFloatingUIMap . get ( node ) ;
105+ if ( floatingUI ) {
106+ if ( floatingUI . tooltip ) {
107+ floatingUI . tooltip . remove ( ) ;
108+ }
109+ floatingUI . cleanup ( ) ;
110+
111+ this . elementToFloatingUIMap . delete ( node ) ;
107112 }
108- floatingUI . cleanup ( ) ;
109-
110- this . elementToFloatingUIMap . delete ( node ) ;
111113 }
112- }
113114
114- if ( this . elementToTooltipMap . has ( node ) ) {
115- this . elementToTooltipMap . delete ( node ) ;
116- }
115+ if ( this . elementToTooltipMap . has ( node ) ) {
116+ this . elementToTooltipMap . delete ( node ) ;
117+ }
118+ } ) ;
117119 } ) ;
118120 } ) ;
119- } ) ;
120121
121- // Start observing the document for changes.
122- this . observer . observe ( document . body , {
123- childList : true ,
124- subtree : true ,
122+ // Start observing the document for changes.
123+ this . observer . observe ( document . body , {
124+ childList : true ,
125+ subtree : true ,
126+ } ) ;
125127 } ) ;
126128 }
127129
0 commit comments