@@ -72,8 +72,6 @@ function CitationMarkers({
7272 const anchor = findAssistantCitationSourceAnchor ( viewport , citation ) ;
7373 anchors . set ( key , anchor ) ;
7474 resolvedSource = true ;
75- if ( anchor )
76- sourceMutations . observe ( anchor . source , { subtree : true , characterData : true } ) ;
7775 }
7876 const anchor = anchors . get ( key ) ;
7977 const rect =
@@ -110,19 +108,10 @@ function CitationMarkers({
110108 const schedule = ( ) => {
111109 if ( frame === null ) frame = requestAnimationFrame ( update ) ;
112110 } ;
113- const stopResize = observeResize ( viewport , schedule ) ;
114- let stopSourceResize = ( ) => { } ;
115- const invalidateText = ( records : MutationRecord [ ] ) => {
116- for ( const [ key , anchor ] of anchors ) {
117- if ( anchor && records . some ( ( record ) => anchor . source . contains ( record . target ) ) )
118- anchors . delete ( key ) ;
119- }
120- } ;
111+ let stopResize = ( ) => { } ;
121112 const rebuildSourceObservations = ( ) => {
122- invalidateText ( sourceMutations . takeRecords ( ) ) ;
123- sourceMutations . disconnect ( ) ;
124- stopSourceResize ( ) ;
125- const geometry = new Set < Element > ( ) ;
113+ stopResize ( ) ;
114+ const geometry = new Set < Element > ( [ viewport ] ) ;
126115 for ( const anchor of anchors . values ( ) ) {
127116 for (
128117 let node : Element | null = anchor ?. source ?? null ;
@@ -131,10 +120,7 @@ function CitationMarkers({
131120 )
132121 geometry . add ( node ) ;
133122 }
134- stopSourceResize = observeResize ( [ ...geometry ] , schedule ) ;
135- for ( const anchor of anchors . values ( ) ) {
136- if ( anchor ) sourceMutations . observe ( anchor . source , { subtree : true , characterData : true } ) ;
137- }
123+ stopResize = observeResize ( [ ...geometry ] , schedule ) ;
138124 } ;
139125 const mutations = new MutationObserver ( ( records ) => {
140126 const relevant = records . filter ( ( record ) => ! overlay . contains ( record . target ) ) ;
@@ -153,30 +139,17 @@ function CitationMarkers({
153139 mutations . observe ( viewport , {
154140 childList : true ,
155141 subtree : true ,
142+ characterData : true ,
156143 attributes : true ,
157144 attributeFilter : [ "style" , "class" ] ,
158145 } ) ;
159- const sourceMutations = new MutationObserver ( ( records ) => {
160- invalidateText ( records ) ;
161- rebuildSourceObservations ( ) ;
162- schedule ( ) ;
163- } ) ;
164- for ( const marker of citations ) {
165- const { citation, key } = marker ;
166- const anchor = findAssistantCitationSourceAnchor ( viewport , citation ) ;
167- anchors . set ( key , anchor ) ;
168- if ( anchor ) sourceMutations . observe ( anchor . source , { subtree : true , characterData : true } ) ;
169- }
170- rebuildSourceObservations ( ) ;
171146 viewport . addEventListener ( "scroll" , schedule , true ) ;
172147 window . addEventListener ( "resize" , schedule ) ;
173148 schedule ( ) ;
174149 return ( ) => {
175150 if ( frame !== null ) cancelAnimationFrame ( frame ) ;
176151 viewport . removeAttribute ( "data-has-draft-citations" ) ;
177- stopSourceResize ( ) ;
178152 stopResize ( ) ;
179- sourceMutations . disconnect ( ) ;
180153 mutations . disconnect ( ) ;
181154 viewport . removeEventListener ( "scroll" , schedule , true ) ;
182155 window . removeEventListener ( "resize" , schedule ) ;
0 commit comments