@@ -202,8 +202,8 @@ func (d *DevServer) ServeHtml(w http.ResponseWriter, r *http.Request, pathname s
202
202
defer htmlFile .Close ()
203
203
204
204
tokenizer := html .NewTokenizer (htmlFile )
205
- unocss := ""
206
205
cssLinks := []string {}
206
+ unocss := ""
207
207
overriding := ""
208
208
209
209
for {
@@ -242,9 +242,13 @@ func (d *DevServer) ServeHtml(w http.ResponseWriter, r *http.Request, pathname s
242
242
if srcUrl , parseErr := url .Parse (srcAttr ); parseErr == nil && srcUrl .Path == "/x" {
243
243
hrefAttr , _ = utils .SplitByFirstByte (hrefAttr , '?' )
244
244
if hrefAttr == "uno.css" || strings .HasSuffix (hrefAttr , "/uno.css" ) {
245
- w .Write ([]byte ("<link rel=\" stylesheet\" href=\" " ))
246
- w .Write ([]byte (hrefAttr + "?ctx=" + base64 .RawURLEncoding .EncodeToString ([]byte (pathname ))))
247
- w .Write ([]byte {'"' , '>' })
245
+ if unocss == "" {
246
+ unocssHref := hrefAttr + "?ctx=" + base64 .RawURLEncoding .EncodeToString ([]byte (pathname ))
247
+ w .Write ([]byte ("<link rel=\" stylesheet\" href=\" " ))
248
+ w .Write ([]byte (unocssHref ))
249
+ w .Write ([]byte {'"' , '>' })
250
+ unocss = unocssHref
251
+ }
248
252
overriding = "script"
249
253
} else {
250
254
w .Write ([]byte ("<script type=\" module\" " ))
@@ -294,7 +298,7 @@ func (d *DevServer) ServeHtml(w http.ResponseWriter, r *http.Request, pathname s
294
298
}
295
299
// reload the unocss when the module dependency tree is changed
296
300
if unocss != "" {
297
- fmt .Fprintf (w , `hot.watch("*",(kind,filename)=>{if(/\.(js|mjs|jsx|ts|mts|tsx|vue|svelte)$/i.test(filename)){document.getElementById("@unocss") .href="%s&t="+Date.now().toString(36)}});` , unocss )
301
+ fmt .Fprintf (w , `hot.watch("*",(kind,filename)=>{if(/\.(js|mjs|jsx|ts|mts|tsx|vue|svelte)$/i.test(filename)){const link= document.head.querySelector("link[rel=stylesheet][href^='%s']");if(link)link .href="%s&t="+Date.now().toString(36)}});` , unocss , unocss )
298
302
u := & url.URL {Path : pathname }
299
303
u = u .ResolveReference (& url.URL {Path : "uno.css" })
300
304
filename := filepath .Join (d .rootDir , u .Path )
0 commit comments