@@ -24,9 +24,10 @@ import {
24
24
USE_ON_LOCAL_SEQ_IDX ,
25
25
} from './utils/markers' ;
26
26
import { MAX_RETRY_ON_PROMISE_COUNT , isPromise , maybeThen , safeCall } from './utils/promises' ;
27
- import type { ValueOrPromise } from './utils/types' ;
27
+ import { isArray , isPrimitive , type ValueOrPromise } from './utils/types' ;
28
28
import { getSubscriber } from '../reactive-primitives/subscriber' ;
29
29
import { EffectProperty } from '../reactive-primitives/types' ;
30
+ import { EventNameJSXScope } from './utils/event-names' ;
30
31
31
32
/**
32
33
* Use `executeComponent` to execute a component.
@@ -170,7 +171,10 @@ function addUseOnEvents(
170
171
if ( jsxElement ) {
171
172
addUseOnEvent ( jsxElement , 'document:onQinit$' , useOnEvents [ key ] ) ;
172
173
}
173
- } else if ( key . startsWith ( 'document:' ) || key . startsWith ( 'window:' ) ) {
174
+ } else if (
175
+ key . startsWith ( EventNameJSXScope . document ) ||
176
+ key . startsWith ( EventNameJSXScope . window )
177
+ ) {
174
178
const [ jsxElement , jsx ] = addScriptNodeForInvisibleComponents ( jsxResult ) ;
175
179
jsxResult = jsx ;
176
180
if ( jsxElement ) {
@@ -186,7 +190,11 @@ function addUseOnEvents(
186
190
) ;
187
191
}
188
192
} else if ( jsxElement ) {
189
- addUseOnEvent ( jsxElement , key , useOnEvents [ key ] ) ;
193
+ if ( jsxElement . type === 'script' && key === 'onQvisible$' ) {
194
+ addUseOnEvent ( jsxElement , 'document:onQinit$' , useOnEvents [ key ] ) ;
195
+ } else {
196
+ addUseOnEvent ( jsxElement , key , useOnEvents [ key ] ) ;
197
+ }
190
198
}
191
199
}
192
200
}
@@ -222,7 +230,7 @@ function findFirstStringJSX(jsx: JSXOutput): ValueOrPromise<JSXNodeInternal<stri
222
230
return jsx as JSXNodeInternal < string > ;
223
231
}
224
232
queue . push ( jsx . children ) ;
225
- } else if ( Array . isArray ( jsx ) ) {
233
+ } else if ( isArray ( jsx ) ) {
226
234
queue . push ( ...jsx ) ;
227
235
} else if ( isPromise ( jsx ) ) {
228
236
return maybeThen < JSXOutput , JSXNodeInternal < string > | null > ( jsx , ( jsx ) =>
@@ -239,33 +247,40 @@ function addScriptNodeForInvisibleComponents(
239
247
jsx : JSXOutput
240
248
) : [ JSXNodeInternal < string > | null , JSXOutput | null ] {
241
249
if ( isJSXNode ( jsx ) ) {
242
- const jsxElement = new JSXNodeImpl (
243
- 'script' ,
244
- { } ,
245
- {
246
- type : 'placeholder' ,
247
- hidden : '' ,
248
- } ,
249
- null ,
250
- 3
251
- ) ;
250
+ const jsxElement = createScriptNode ( ) ;
252
251
if ( jsx . type === Slot ) {
253
252
return [ jsxElement , _jsxSorted ( Fragment , null , null , [ jsx , jsxElement ] , 0 , null ) ] ;
254
253
}
255
254
256
255
if ( jsx . children == null ) {
257
256
jsx . children = jsxElement ;
258
- } else if ( Array . isArray ( jsx . children ) ) {
257
+ } else if ( isArray ( jsx . children ) ) {
259
258
jsx . children . push ( jsxElement ) ;
260
259
} else {
261
260
jsx . children = [ jsx . children , jsxElement ] ;
262
261
}
263
262
return [ jsxElement , jsx ] ;
264
- } else if ( Array . isArray ( jsx ) && jsx . length ) {
263
+ } else if ( isArray ( jsx ) && jsx . length ) {
265
264
// get first element
266
265
const [ jsxElement , _ ] = addScriptNodeForInvisibleComponents ( jsx [ 0 ] ) ;
267
266
return [ jsxElement , jsx ] ;
267
+ } else if ( isPrimitive ( jsx ) ) {
268
+ const jsxElement = createScriptNode ( ) ;
269
+ return [ jsxElement , _jsxSorted ( Fragment , null , null , [ jsx , jsxElement ] , 0 , null ) ] ;
268
270
}
269
271
270
- return [ null , null ] ;
272
+ return [ null , jsx ] ;
273
+ }
274
+
275
+ function createScriptNode ( ) : JSXNodeInternal < string > {
276
+ return new JSXNodeImpl (
277
+ 'script' ,
278
+ { } ,
279
+ {
280
+ type : 'placeholder' ,
281
+ hidden : '' ,
282
+ } ,
283
+ null ,
284
+ 3
285
+ ) ;
271
286
}
0 commit comments