@@ -16,12 +16,7 @@ import type { QRL } from '../shared/qrl/qrl.public';
1616import { qrlToString , type SerializationContext } from '../shared/serdes/index' ;
1717import { DEBUG_TYPE , VirtualType } from '../shared/types' ;
1818import { isAsyncGenerator } from '../shared/utils/async-generator' ;
19- import {
20- getEventNameFromJsxEvent ,
21- isJsxPropertyAnEventName ,
22- isPreventDefault ,
23- jsxEventToHtmlAttribute ,
24- } from '../shared/utils/event-names' ;
19+ import { isHtmlAttributeAnEventName , isPreventDefault } from '../shared/utils/event-names' ;
2520import { EMPTY_ARRAY } from '../shared/utils/flyweight' ;
2621import { getFileLocationFromJsx } from '../shared/utils/jsx-filename' ;
2722import {
@@ -321,67 +316,33 @@ export function varPropsToSsrAttrs(
321316 constProps : Record < string , unknown > | null ,
322317 options : SsrAttrsOptions
323318) : SsrAttrs | null {
324- return toSsrAttrs ( varProps , constProps , false , options ) ;
319+ return toSsrAttrs ( varProps , options ) ;
325320}
326321
327322export function constPropsToSsrAttrs (
328323 constProps : Record < string , unknown > | null ,
329324 varProps : Record < string , unknown > ,
330325 options : SsrAttrsOptions
331326) : SsrAttrs | null {
332- return toSsrAttrs ( constProps , varProps , true , options ) ;
327+ return toSsrAttrs ( constProps , options ) ;
333328}
334329
335330export function toSsrAttrs (
336331 record : Record < string , unknown > | null | undefined ,
337- anotherRecord : Record < string , unknown > | null | undefined ,
338- isConst : boolean ,
339332 options : SsrAttrsOptions
340333) : SsrAttrs | null {
341334 if ( record == null ) {
342335 return null ;
343336 }
344- const pushMergedEventProps = ! isConst ;
345337 const ssrAttrs : SsrAttrs = [ ] ;
346338 const handleProp = ( key : string , value : unknown ) => {
347339 if ( value == null ) {
348340 return ;
349341 }
350- if ( isJsxPropertyAnEventName ( key ) ) {
351- if ( anotherRecord ) {
352- /**
353- * If we have two sources of the same event like this:
354- *
355- * ```tsx
356- * const Counter = component$((props: { initial: number }) => {
357- * const count = useSignal(props.initial);
358- * useOnWindow(
359- * 'dblclick',
360- * $(() => count.value++)
361- * );
362- * return <button window:onDblClick$={() => count.value++}>Count: {count.value}!</button>;
363- * });
364- * ```
365- *
366- * Then we can end with the const and var props with the same (doubled) event. We process
367- * the const and var props separately, so:
368- *
369- * - For the var props we need to merge them into the one value (array)
370- * - For the const props we need to just skip, because we will handle this in the var props
371- */
372- const anotherValue = getEventProp ( anotherRecord , key ) ;
373- if ( anotherValue ) {
374- if ( pushMergedEventProps ) {
375- // merge values from the const props with the var props
376- value = getMergedEventPropValues ( value , anotherValue ) ;
377- } else {
378- return ;
379- }
380- }
381- }
342+ if ( isHtmlAttributeAnEventName ( key ) ) {
382343 const eventValue = setEvent ( options . serializationCtx , key , value ) ;
383344 if ( eventValue ) {
384- ssrAttrs . push ( jsxEventToHtmlAttribute ( key ) , eventValue ) ;
345+ ssrAttrs . push ( key , eventValue ) ;
385346 }
386347 return ;
387348 }
@@ -422,36 +383,6 @@ export function toSsrAttrs(
422383 return ssrAttrs ;
423384}
424385
425- function getMergedEventPropValues ( value : unknown , anotherValue : unknown ) {
426- let mergedValue = value ;
427- // merge values from the const props with the var props
428- if ( Array . isArray ( value ) && Array . isArray ( anotherValue ) ) {
429- // both values are arrays
430- mergedValue = value . concat ( anotherValue ) ;
431- } else if ( Array . isArray ( mergedValue ) ) {
432- // only first value is array
433- mergedValue . push ( anotherValue ) ;
434- } else if ( Array . isArray ( anotherValue ) ) {
435- // only second value is array
436- mergedValue = anotherValue ;
437- ( mergedValue as unknown [ ] ) . push ( value ) ;
438- } else {
439- // none of these values are array
440- mergedValue = [ value , anotherValue ] ;
441- }
442- return mergedValue ;
443- }
444-
445- function getEventProp ( record : Record < string , unknown > , propKey : string ) : unknown | null {
446- const eventProp = propKey . toLowerCase ( ) ;
447- for ( const prop in record ) {
448- if ( prop . toLowerCase ( ) === eventProp ) {
449- return record [ prop ] ;
450- }
451- }
452- return null ;
453- }
454-
455386function setEvent (
456387 serializationCtx : SerializationContext ,
457388 key : string ,
@@ -503,9 +434,17 @@ function addQwikEventToSerializationContext(
503434 key : string ,
504435 qrl : QRL
505436) {
506- const eventName = getEventNameFromJsxEvent ( key ) ;
507- if ( eventName ) {
437+ // TODO extract window/document too so qwikloader can precisely listen
438+ const match = / ^ o n ( | - ( w i n d o w | d o c u m e n t ) ) : ( .+ ) $ / . exec ( key ) ;
439+ if ( match ) {
440+ const eventName = match [ 3 ] ;
508441 serializationCtx . $eventNames$ . add ( eventName ) ;
442+ console . log (
443+ 'addQwikEventToSerializationContext' ,
444+ key ,
445+ eventName ,
446+ serializationCtx . $eventNames$
447+ ) ;
509448 serializationCtx . $eventQrls$ . add ( qrl ) ;
510449 }
511450}
0 commit comments