File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -321,6 +321,11 @@ async function waitForSuccessfulPing(
321321    try  { 
322322      await  fetch ( `${ pingHostProtocol }  ://${ hostAndPath }  ` ,  { 
323323        mode : 'no-cors' , 
324+         headers : { 
325+           // Custom headers won't be included in a request with no-cors so (ab)use one of the 
326+           // safelisted headers to identify the ping request 
327+           Accept : 'text/x-vite-ping' , 
328+         } , 
324329      } ) 
325330      return  true 
326331    }  catch  { } 
Original file line number Diff line number Diff line change @@ -608,6 +608,16 @@ export async function _createServer(
608608  // open in editor support 
609609  middlewares . use ( '/__open-in-editor' ,  launchEditorMiddleware ( ) ) 
610610
611+   // ping request handler 
612+   // Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...` 
613+   middlewares . use ( function  viteHMRPingMiddleware ( req ,  res ,  next )  { 
614+     if  ( req . headers [ 'accept' ]  ===  'text/x-vite-ping' )  { 
615+       res . writeHead ( 204 ) . end ( ) 
616+     }  else  { 
617+       next ( ) 
618+     } 
619+   } ) 
620+ 
611621  // serve static files under /public 
612622  // this applies before the transform middleware so that these files are served 
613623  // as-is without transforms. 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments