@@ -2,7 +2,7 @@ import { isDev } from '@qwik.dev/core/build';
2
2
import { isQwikComponent , type OnRenderFn } from './component.public' ;
3
3
import { assertDefined } from './error/assert' ;
4
4
import { isQrl , type QRLInternal } from './qrl/qrl-class' ;
5
- import { JSXNodeImpl , isJSXNode , type Props } from './jsx/jsx-runtime' ;
5
+ import { Fragment , JSXNodeImpl , _jsxSorted , isJSXNode , type Props } from './jsx/jsx-runtime' ;
6
6
import type { JSXNodeInternal , JSXOutput } from './jsx/types/jsx-node' ;
7
7
import type { KnownEventNames } from './jsx/types/jsx-qwik-events' ;
8
8
import { invokeApply , newInvokeContext , untrack } from '../use/use-core' ;
@@ -23,6 +23,7 @@ import { logWarn } from './utils/log';
23
23
import { EffectProperty , isSignal } from '../signal/signal' ;
24
24
import { vnode_isVNode } from '../client/vnode' ;
25
25
import { clearVNodeEffectDependencies } from '../signal/signal-subscriber' ;
26
+ import { Slot } from '../shared/jsx/slot.public' ;
26
27
27
28
/**
28
29
* Use `executeComponent` to execute a component.
@@ -101,7 +102,7 @@ export const executeComponent = (
101
102
( jsx ) => {
102
103
const useOnEvents = container . getHostProp < UseOnMap > ( renderHost , USE_ON_LOCAL ) ;
103
104
if ( useOnEvents ) {
104
- return maybeThen ( addUseOnEvents ( jsx , useOnEvents ) , ( ) => jsx ) ;
105
+ return addUseOnEvents ( jsx , useOnEvents ) ;
105
106
}
106
107
return jsx ;
107
108
} ,
@@ -133,8 +134,9 @@ export const executeComponent = (
133
134
function addUseOnEvents (
134
135
jsx : JSXOutput ,
135
136
useOnEvents : UseOnMap
136
- ) : ValueOrPromise < JSXNodeInternal < string > | null > {
137
+ ) : ValueOrPromise < JSXNodeInternal < string > | null | JSXOutput > {
137
138
const jsxElement = findFirstStringJSX ( jsx ) ;
139
+ let jsxResult = jsx ;
138
140
return maybeThen ( jsxElement , ( jsxElement ) => {
139
141
let isInvisibleComponent = false ;
140
142
if ( ! jsxElement ) {
@@ -153,12 +155,14 @@ function addUseOnEvents(
153
155
if ( Object . prototype . hasOwnProperty . call ( useOnEvents , key ) ) {
154
156
if ( isInvisibleComponent ) {
155
157
if ( key === 'onQvisible$' ) {
156
- jsxElement = addScriptNodeForInvisibleComponents ( jsx ) ;
158
+ const [ jsxElement , jsx ] = addScriptNodeForInvisibleComponents ( jsxResult ) ;
159
+ jsxResult = jsx ;
157
160
if ( jsxElement ) {
158
161
addUseOnEvent ( jsxElement , 'document:onQinit$' , useOnEvents [ key ] ) ;
159
162
}
160
163
} else if ( key . startsWith ( 'document:' ) || key . startsWith ( 'window:' ) ) {
161
- jsxElement = addScriptNodeForInvisibleComponents ( jsx ) ;
164
+ const [ jsxElement , jsx ] = addScriptNodeForInvisibleComponents ( jsxResult ) ;
165
+ jsxResult = jsx ;
162
166
if ( jsxElement ) {
163
167
addUseOnEvent ( jsxElement , key , useOnEvents [ key ] ) ;
164
168
}
@@ -176,7 +180,7 @@ function addUseOnEvents(
176
180
}
177
181
}
178
182
}
179
- return jsxElement ;
183
+ return jsxResult ;
180
184
} ) ;
181
185
}
182
186
@@ -221,7 +225,9 @@ function findFirstStringJSX(jsx: JSXOutput): ValueOrPromise<JSXNodeInternal<stri
221
225
return null ;
222
226
}
223
227
224
- function addScriptNodeForInvisibleComponents ( jsx : JSXOutput ) : JSXNodeInternal < string > | null {
228
+ function addScriptNodeForInvisibleComponents (
229
+ jsx : JSXOutput
230
+ ) : [ JSXNodeInternal < string > | null , JSXOutput | null ] {
225
231
if ( isJSXNode ( jsx ) ) {
226
232
const jsxElement = new JSXNodeImpl (
227
233
'script' ,
@@ -233,6 +239,9 @@ function addScriptNodeForInvisibleComponents(jsx: JSXOutput): JSXNodeInternal<st
233
239
null ,
234
240
3
235
241
) ;
242
+ if ( jsx . type === Slot ) {
243
+ return [ jsxElement , _jsxSorted ( Fragment , null , null , [ jsx , jsxElement ] , 0 , null ) ] ;
244
+ }
236
245
237
246
if ( jsx . children == null ) {
238
247
jsx . children = jsxElement ;
@@ -241,11 +250,12 @@ function addScriptNodeForInvisibleComponents(jsx: JSXOutput): JSXNodeInternal<st
241
250
} else {
242
251
jsx . children = [ jsx . children , jsxElement ] ;
243
252
}
244
- return jsxElement ;
253
+ return [ jsxElement , jsx ] ;
245
254
} else if ( Array . isArray ( jsx ) && jsx . length ) {
246
255
// get first element
247
- return addScriptNodeForInvisibleComponents ( jsx [ 0 ] ) ;
256
+ const [ jsxElement , _ ] = addScriptNodeForInvisibleComponents ( jsx [ 0 ] ) ;
257
+ return [ jsxElement , jsx ] ;
248
258
}
249
259
250
- return null ;
260
+ return [ null , null ] ;
251
261
}
0 commit comments