@@ -85,6 +85,10 @@ export async function configureDevServer(
85
85
const hasQwikCity = server . config . plugins ?. some (
86
86
( plugin ) => plugin . name === 'vite-plugin-qwik-city'
87
87
) ;
88
+
89
+ // to maintain css importers after HMR
90
+ const cssImportedByCSS = new Set < string > ( ) ;
91
+
88
92
// qwik middleware injected BEFORE vite internal middlewares
89
93
server . middlewares . use ( async ( req , res , next ) => {
90
94
try {
@@ -159,12 +163,30 @@ export async function configureDevServer(
159
163
160
164
if ( query === '' && CSS_EXTENSIONS . some ( ( ext ) => pathId . endsWith ( ext ) ) ) {
161
165
const isEntryCSS = v . importers . size === 0 ;
166
+ const hasCSSImporter = Array . from ( v . importers ) . some ( ( importer ) => {
167
+ const importerPath = ( importer as typeof v ) . url || ( importer as typeof v ) . file ;
168
+
169
+ const isCSS =
170
+ importerPath && CSS_EXTENSIONS . some ( ( ext ) => importerPath . endsWith ( ext ) ) ;
171
+
172
+ if ( isCSS && v . url ) {
173
+ cssImportedByCSS . add ( v . url ) ;
174
+ }
175
+
176
+ return isCSS ;
177
+ } ) ;
178
+
162
179
const hasJSImporter = Array . from ( v . importers ) . some ( ( importer ) => {
163
180
const importerPath = ( importer as typeof v ) . url || ( importer as typeof v ) . file ;
164
181
return importerPath && JS_EXTENSIONS . test ( importerPath ) ;
165
182
} ) ;
166
183
167
- if ( ( isEntryCSS || hasJSImporter ) && ! added . has ( v . url ) ) {
184
+ if (
185
+ ( isEntryCSS || hasJSImporter ) &&
186
+ ! hasCSSImporter &&
187
+ ! cssImportedByCSS . has ( v . url ) &&
188
+ ! added . has ( v . url )
189
+ ) {
168
190
added . add ( v . url ) ;
169
191
manifest . injections ! . push ( {
170
192
tag : 'link' ,
@@ -214,12 +236,29 @@ export async function configureDevServer(
214
236
CSS_EXTENSIONS . some ( ( ext ) => pathId . endsWith ( ext ) )
215
237
) {
216
238
const isEntryCSS = v . importers . size === 0 ;
239
+ const hasCSSImporter = Array . from ( v . importers ) . some ( ( importer ) => {
240
+ const importerPath = ( importer as typeof v ) . url || ( importer as typeof v ) . file ;
241
+
242
+ const isCSS =
243
+ importerPath && CSS_EXTENSIONS . some ( ( ext ) => importerPath . endsWith ( ext ) ) ;
244
+
245
+ if ( isCSS && v . url ) {
246
+ cssImportedByCSS . add ( v . url ) ;
247
+ }
248
+
249
+ return isCSS ;
250
+ } ) ;
251
+
217
252
const hasJSImporter = Array . from ( v . importers ) . some ( ( importer ) => {
218
253
const importerPath = ( importer as typeof v ) . url || ( importer as typeof v ) . file ;
219
254
return importerPath && JS_EXTENSIONS . test ( importerPath ) ;
220
255
} ) ;
221
256
222
- if ( isEntryCSS || hasJSImporter ) {
257
+ if (
258
+ ( isEntryCSS || hasJSImporter ) &&
259
+ ! hasCSSImporter &&
260
+ ! cssImportedByCSS . has ( v . url )
261
+ ) {
223
262
res . write ( `<link rel="stylesheet" href="${ base } ${ v . url . slice ( 1 ) } ">` ) ;
224
263
added . add ( v . url ) ;
225
264
}
0 commit comments