11import { toQrlOrError } from '../import/qrl' ;
22import type { QRLInternal } from '../import/qrl-class' ;
33import { $ , implicit$FirstArg , QRL } from '../import/qrl.public' ;
4- import { qPropWriteQRL , qrlFactory } from '../props/props-on' ;
4+ import { qPropWriteQRL } from '../props/props-on' ;
55import type { JSXNode } from '../render/jsx/types/jsx-node' ;
6- import { newInvokeContext , useInvoke , useWaitOn } from '../use/use-core' ;
6+ import { newInvokeContext , StyleAppend , useInvoke , useWaitOn } from '../use/use-core' ;
77import { useHostElement } from '../use/use-host-element.public' ;
88import { ComponentScopedStyles , OnRenderProp } from '../util/markers' ;
99import { styleKey } from './qrl-styles' ;
@@ -14,6 +14,8 @@ import type { FunctionComponent } from '../index';
1414import { jsx } from '../render/jsx/jsx-runtime' ;
1515
1616import { getDocument } from '../util/dom' ;
17+ import { promiseAll } from '../util/promises' ;
18+ import type { RenderFactoryOutput } from './component-ctx' ;
1719
1820// <docs markdown="https://hackmd.io/c_nNpiLZSYugTU0c5JATJA#onUnmount">
1921// !!DO NOT EDIT THIS COMMENT DIRECTLY!!!
@@ -323,14 +325,17 @@ export function componentQrl<PROPS extends {}>(
323325
324326 // Return a QComponent Factory function.
325327 return function QComponent ( props , key ) : JSXNode < PROPS > {
326- const onRenderFactory : qrlFactory = async ( hostElement : Element ) : Promise < QRLInternal > => {
327- // Turn function into QRL
328+ const onRenderFactory = async ( hostElement : Element ) : Promise < RenderFactoryOutput > => {
328329 const onMountQrl = toQrlOrError ( onMount ) ;
329330 const onMountFn = await resolveQrl ( hostElement , onMountQrl ) ;
330331 const ctx = getContext ( hostElement ) ;
331332 const props = getProps ( ctx ) as any ;
332333 const invokeCtx = newInvokeContext ( getDocument ( hostElement ) , hostElement , hostElement ) ;
333- return useInvoke ( invokeCtx , onMountFn , props ) as QRLInternal ;
334+ const renderQRL = ( await useInvoke ( invokeCtx , onMountFn , props ) ) as QRLInternal ;
335+ return {
336+ renderQRL,
337+ waitOn : await promiseAll ( invokeCtx . waitOn || [ ] ) ,
338+ } ;
334339 } ;
335340 onRenderFactory . __brand__ = 'QRLFactory' ;
336341
@@ -433,14 +438,12 @@ function _useStyles(styles: QRL<string>, scoped: boolean) {
433438
434439 useWaitOn (
435440 styleQrl . resolve ( hostElement ) . then ( ( styleText ) => {
436- const document = getDocument ( hostElement ) ;
437- const head = document . querySelector ( 'head' ) ;
438- if ( head && ! head . querySelector ( `style[q\\:style="${ styleId } "]` ) ) {
439- const style = document . createElement ( 'style' ) ;
440- style . setAttribute ( 'q:style' , styleId ) ;
441- style . textContent = scoped ? styleText . replace ( / � / g, styleId ) : styleText ;
442- head . appendChild ( style ) ;
443- }
441+ const task : StyleAppend = {
442+ type : 'style' ,
443+ scope : styleId ,
444+ content : scoped ? styleText . replace ( / � / g, styleId ) : styleText ,
445+ } ;
446+ return task ;
444447 } )
445448 ) ;
446449}
0 commit comments