@@ -246,15 +246,25 @@ if (typeof browser === 'undefined' && typeof chrome !== 'undefined') {
246246 let currentUrl = location . href ;
247247 let navigationTimeout = null ;
248248
249- // Setup observer to handle SPA navigation by watching DOM changes
249+ // Setup observer to handle SPA navigation and React re-renders
250250 function setupNavigationObserver ( ) {
251251 // Watch for DOM changes - observe body to catch all navigation
252252 // (observing <main> fails when <main> itself is replaced during navigation)
253253 const observer = new MutationObserver ( ( ) => {
254254 const newUrl = location . href ;
255- if ( newUrl !== currentUrl ) {
256- currentUrl = newUrl ;
257- console . log ( '[GitHub Bookmarked Issues] Navigation detected:' , currentUrl ) ;
255+ const urlChanged = newUrl !== currentUrl ;
256+
257+ // Also check if button was removed by React re-render (belt-and-suspenders)
258+ const mainHeader = document . querySelector ( HEADER_ACTIONS_SELECTOR ) ;
259+ const buttonMissing = mainHeader && ! mainHeader . querySelector ( `[${ BOOKMARK_BUTTON_ATTR } ]` ) ;
260+
261+ if ( urlChanged || buttonMissing ) {
262+ if ( urlChanged ) {
263+ currentUrl = newUrl ;
264+ console . log ( '[GitHub Bookmarked Issues] Navigation detected:' , currentUrl ) ;
265+ } else if ( buttonMissing ) {
266+ console . log ( '[GitHub Bookmarked Issues] Button removed by React, re-inserting' ) ;
267+ }
258268
259269 // Debounce: clear any pending timeout and set a new one
260270 if ( navigationTimeout ) {
@@ -294,15 +304,20 @@ if (typeof browser === 'undefined' && typeof chrome !== 'undefined') {
294304 console . log ( `[GitHub Bookmarked Issues] [${ timestamp } ms] init() readyState: ${ document . readyState } , URL: ${ location . pathname } ` ) ;
295305 setupIconTemplates ( ) ;
296306
297- // Initial button insertion
307+ // Initial button insertion - delay to allow React hydration to complete
308+ // (prevents button from being removed by React re-render, especially on Windows)
298309 if ( document . readyState === 'loading' ) {
299310 document . addEventListener ( 'DOMContentLoaded' , ( ) => {
300- insertBookmarkButton ( ) ;
301- setupNavigationObserver ( ) ;
311+ setTimeout ( ( ) => {
312+ insertBookmarkButton ( ) ;
313+ setupNavigationObserver ( ) ;
314+ } , 50 ) ;
302315 } ) ;
303316 } else {
304- insertBookmarkButton ( ) ;
305- setupNavigationObserver ( ) ;
317+ setTimeout ( ( ) => {
318+ insertBookmarkButton ( ) ;
319+ setupNavigationObserver ( ) ;
320+ } , 50 ) ;
306321 }
307322 }
308323
0 commit comments