@@ -27,6 +27,7 @@ import {
2727 QScopedStyle ,
2828 QStyle ,
2929 QStyleSelector ,
30+ QStylesAllSelector ,
3031 Q_PROPS_SEPARATOR ,
3132 USE_ON_LOCAL_SEQ_IDX ,
3233 getQFuncs ,
@@ -48,22 +49,21 @@ import {
4849import { mapArray_get , mapArray_has , mapArray_set } from './util-mapArray' ;
4950import {
5051 VNodeJournalOpCode ,
51- vnode_applyJournal ,
5252 vnode_createErrorDiv ,
53- vnode_getDomParent ,
54- vnode_getProps ,
53+ vnode_getProp ,
5554 vnode_insertBefore ,
5655 vnode_isElementVNode ,
57- vnode_isVNode ,
5856 vnode_isVirtualVNode ,
5957 vnode_locate ,
6058 vnode_newUnMaterializedElement ,
61- type VNodeJournal ,
59+ vnode_setProp ,
6260} from './vnode' ;
63- import type { ElementVNode , VNode , VirtualVNode } from './vnode-impl' ;
61+ import type { ElementVNode } from '../shared/vnode/element-vnode' ;
62+ import type { VNode } from '../shared/vnode/vnode' ;
63+ import type { VirtualVNode } from '../shared/vnode/virtual-vnode' ;
6464
6565/** @public */
66- export function getDomContainer ( element : Element | VNode ) : IClientContainer {
66+ export function getDomContainer ( element : Element ) : IClientContainer {
6767 const qContainerElement = _getQContainerElement ( element ) ;
6868 if ( ! qContainerElement ) {
6969 throw qError ( QError . containerNotFound ) ;
@@ -96,7 +96,6 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
9696 public qManifestHash : string ;
9797 public rootVNode : ElementVNode ;
9898 public document : QDocument ;
99- public $journal$ : VNodeJournal ;
10099 public $rawStateData$ : unknown [ ] ;
101100 public $storeProxyMap$ : ObjToProxyMap = new WeakMap ( ) ;
102101 public $qFuncs$ : Array < ( ...args : unknown [ ] ) => unknown > ;
@@ -108,29 +107,14 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
108107 private $styleIds$ : Set < string > | null = null ;
109108
110109 constructor ( element : ContainerElement ) {
111- super (
112- ( ) => {
113- this . $flushEpoch$ ++ ;
114- vnode_applyJournal ( this . $journal$ ) ;
115- } ,
116- { } ,
117- element . getAttribute ( QLocaleAttr ) !
118- ) ;
110+ super ( { } , element . getAttribute ( QLocaleAttr ) ! ) ;
119111 this . qContainer = element . getAttribute ( QContainerAttr ) ! ;
120112 if ( ! this . qContainer ) {
121113 throw qError ( QError . elementWithoutContainer ) ;
122114 }
123- this . $journal$ = [
124- // The first time we render we need to hoist the styles.
125- // (Meaning we need to move all styles from component inline to <head>)
126- // We bulk move all of the styles, because the expensive part is
127- // for the browser to recompute the styles, (not the actual DOM manipulation.)
128- // By moving all of them at once we can minimize the reflow.
129- VNodeJournalOpCode . HoistStyles ,
130- element . ownerDocument ,
131- ] ;
132115 this . document = element . ownerDocument as QDocument ;
133116 this . element = element ;
117+ this . $hoistStyles$ ( ) ;
134118 this . $buildBase$ = element . getAttribute ( QBaseAttr ) ! ;
135119 this . $instanceHash$ = element . getAttribute ( QInstanceAttr ) ! ;
136120 this . qManifestHash = element . getAttribute ( QManifestHashAttr ) ! ;
@@ -157,7 +141,24 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
157141 }
158142 }
159143
160- $setRawState$ ( id : number , vParent : ElementVNode | VirtualVNode ) : void {
144+ /**
145+ * The first time we render we need to hoist the styles. (Meaning we need to move all styles from
146+ * component inline to <head>)
147+ *
148+ * We bulk move all of the styles, because the expensive part is for the browser to recompute the
149+ * styles, (not the actual DOM manipulation.) By moving all of them at once we can minimize the
150+ * reflow.
151+ */
152+ $hoistStyles$ ( ) : void {
153+ const document = this . element . ownerDocument ;
154+ const head = document . head ;
155+ const styles = document . querySelectorAll ( QStylesAllSelector ) ;
156+ for ( let i = 0 ; i < styles . length ; i ++ ) {
157+ head . appendChild ( styles [ i ] ) ;
158+ }
159+ }
160+
161+ $setRawState$ ( id : number , vParent : VNode ) : void {
161162 this . $stateData$ [ id ] = vParent ;
162163 }
163164
@@ -168,17 +169,15 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
168169 handleError ( err : any , host : VNode | null ) : void {
169170 if ( qDev && host ) {
170171 if ( typeof document !== 'undefined' ) {
171- const vHost = host as VirtualVNode ;
172- const journal : VNodeJournal = [ ] ;
172+ const vHost = host ;
173173 const vHostParent = vHost . parent ;
174174 const vHostNextSibling = vHost . nextSibling as VNode | null ;
175- const vErrorDiv = vnode_createErrorDiv ( document , vHost , err , journal ) ;
175+ const vErrorDiv = vnode_createErrorDiv ( document , vHost , err ) ;
176176 // If the host is an element node, we need to insert the error div into its parent.
177177 const insertHost = vnode_isElementVNode ( vHost ) ? vHostParent || vHost : vHost ;
178178 // If the host is different then we need to insert errored-host in the same position as the host.
179179 const insertBefore = insertHost === vHost ? null : vHostNextSibling ;
180- vnode_insertBefore ( journal , insertHost , vErrorDiv , insertBefore ) ;
181- vnode_applyJournal ( journal ) ;
180+ vnode_insertBefore ( insertHost as ElementVNode | VirtualVNode , vErrorDiv , insertBefore ) ;
182181 }
183182
184183 if ( err && err instanceof Error ) {
@@ -220,7 +219,7 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
220219 let vNode : VNode | null = host . parent ;
221220 while ( vNode ) {
222221 if ( vnode_isVirtualVNode ( vNode ) ) {
223- if ( vNode . getProp ( OnRenderProp , null ) !== null ) {
222+ if ( vnode_getProp ( vNode , OnRenderProp , null ) !== null ) {
224223 return vNode ;
225224 }
226225 vNode =
@@ -236,7 +235,7 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
236235
237236 setHostProp < T > ( host : HostElement , name : string , value : T ) : void {
238237 const vNode : VirtualVNode = host as any ;
239- vNode . setProp ( name , value ) ;
238+ vnode_setProp ( vNode , name , value ) ;
240239 }
241240
242241 getHostProp < T > ( host : HostElement , name : string ) : T | null {
@@ -255,20 +254,21 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
255254 getObjectById = parseInt ;
256255 break ;
257256 }
258- return vNode . getProp ( name , getObjectById ) ;
257+ return vnode_getProp ( vNode , name , getObjectById ) ;
259258 }
260259
261260 ensureProjectionResolved ( vNode : VirtualVNode ) : void {
262261 if ( ( vNode . flags & VNodeFlags . Resolved ) === 0 ) {
263262 vNode . flags |= VNodeFlags . Resolved ;
264- const props = vnode_getProps ( vNode ) ;
265- for ( let i = 0 ; i < props . length ; i = i + 2 ) {
266- const prop = props [ i ] as string ;
267- if ( isSlotProp ( prop ) ) {
268- const value = props [ i + 1 ] ;
269- if ( typeof value == 'string' ) {
270- const projection = this . vNodeLocate ( value ) ;
271- props [ i + 1 ] = projection ;
263+ const props = vNode . props ;
264+ if ( props ) {
265+ for ( const prop of Object . keys ( props ) ) {
266+ if ( isSlotProp ( prop ) ) {
267+ const value = prop ;
268+ if ( typeof value == 'string' ) {
269+ const projection = this . vNodeLocate ( value ) ;
270+ props [ prop ] = projection ;
271+ }
272272 }
273273 }
274274 }
@@ -304,7 +304,7 @@ export class DomContainer extends _SharedContainer implements IClientContainer {
304304 const styleElement = this . document . createElement ( 'style' ) ;
305305 styleElement . setAttribute ( QStyle , styleId ) ;
306306 styleElement . textContent = content ;
307- this . $journal$ . push ( VNodeJournalOpCode . Insert , this . document . head , null , styleElement ) ;
307+ this . document . head . appendChild ( styleElement ) ;
308308 }
309309 }
310310
0 commit comments