@qwik.dev/core 2.0.0-beta.35 → 2.0.0-beta.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * @qwik.dev/core/server 2.0.0-beta.35-dev+4603135
3
+ * @qwik.dev/core/server 2.0.0-beta.37-dev+82dc74d
4
4
  * Copyright QwikDev. All Rights Reserved.
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://github.com/QwikDev/qwik/blob/main/LICENSE
@@ -523,6 +523,11 @@ var VNodeDataChar = {
523
523
  "~"
524
524
  )
525
525
  };
526
+ var getSegmentVNodeRefId = (segmentId, localIndex) => {
527
+ const segmentIndex = parseInt(segmentId, 10) - 1;
528
+ const diagonal = segmentIndex + localIndex;
529
+ return -(diagonal * (diagonal + 1) / 2 + localIndex + 1);
530
+ };
526
531
 
527
532
  // packages/qwik/src/core/shared/utils/character-escaping.ts
528
533
  function escapeHTML(html) {
@@ -573,11 +578,44 @@ function encodeVNodeDataString(str) {
573
578
  return escapedHTML + str.substring(lastIdx);
574
579
  }
575
580
  }
581
+ function encodeVNodeDataKey(str) {
582
+ const encoded = encodeURI(str);
583
+ let encodedKey = "";
584
+ const length = encoded.length;
585
+ let idx = 0;
586
+ let lastIdx = idx;
587
+ for (; idx < length; idx++) {
588
+ const ch = encoded.charCodeAt(idx);
589
+ let replacement = null;
590
+ if (ch === 59) {
591
+ replacement = "%3B";
592
+ } else if (ch === 61) {
593
+ replacement = "%3D";
594
+ } else if (ch === 63) {
595
+ replacement = "%3F";
596
+ } else if (ch === 64) {
597
+ replacement = "%40";
598
+ } else if (ch === 126) {
599
+ replacement = "%7E";
600
+ } else {
601
+ continue;
602
+ }
603
+ encodedKey += encoded.substring(lastIdx, idx) + replacement;
604
+ lastIdx = idx + 1;
605
+ }
606
+ if (lastIdx === 0) {
607
+ return encoded;
608
+ } else {
609
+ return encodedKey + encoded.substring(lastIdx);
610
+ }
611
+ }
576
612
 
577
613
  // packages/qwik/src/core/shared/utils/markers.ts
578
614
  var OnRenderProp = "q:renderFn";
579
615
  var QSlot = "q:slot";
580
616
  var QSlotParent = "q:sparent";
617
+ var QStatePatchAttr = "q:patch";
618
+ var QSuspenseResolved = "q:r";
581
619
  var QStyle = "q:style";
582
620
  var QStyleSelector = "style[q\\:style]";
583
621
  var QStyleSSelector = "style[q\\:sstyle]";
@@ -585,6 +623,7 @@ var QStylesAllSelector = QStyleSelector + "," + QStyleSSelector;
585
623
  var QScopedStyle = "q:sstyle";
586
624
  var QCtxAttr = "q:ctx";
587
625
  var QBackRefs = "q:brefs";
626
+ var QwikEvContainerReady = 0;
588
627
  var QRenderAttr = "q:render";
589
628
  var QRuntimeAttr = "q:runtime";
590
629
  var QVersionAttr = "q:version";
@@ -607,15 +646,13 @@ var ELEMENT_PROPS = "q:props";
607
646
  var ELEMENT_SEQ = "q:seq";
608
647
  var ELEMENT_SEQ_IDX = "q:seqIdx";
609
648
  var ELEMENT_BACKPATCH_DATA = "qwik/backpatch";
610
- var Q_PREFIX = "q:";
611
649
  var ITERATION_ITEM_SINGLE = "q:p";
612
650
  var ITERATION_ITEM_MULTI = "q:ps";
613
651
  var NON_SERIALIZABLE_MARKER_PREFIX = ":";
614
652
  var USE_ON_LOCAL = NON_SERIALIZABLE_MARKER_PREFIX + "on";
615
653
  var USE_ON_LOCAL_SEQ_IDX = NON_SERIALIZABLE_MARKER_PREFIX + "onIdx";
616
654
  var USE_ON_LOCAL_FLAGS = NON_SERIALIZABLE_MARKER_PREFIX + "onFlags";
617
- var QCursorBoundary = Q_PREFIX + "cursorBoundary";
618
- var QNearestCursorBoundary = NON_SERIALIZABLE_MARKER_PREFIX + "nearestCursorBoundary";
655
+ var NEAREST_CURSOR_BOUNDARY = NON_SERIALIZABLE_MARKER_PREFIX + "nearestCursorBoundary";
619
656
  var Q_PROPS_SEPARATOR = ":";
620
657
  var dangerouslySetInnerHTML = "dangerouslySetInnerHTML";
621
658
 
@@ -878,6 +915,26 @@ var isObjectEmpty = (obj) => {
878
915
  return true;
879
916
  };
880
917
 
918
+ // packages/qwik/src/core/ssr/stream-writer.ts
919
+ var stringifyRootRefPath = (path) => {
920
+ let text = String(path[0]);
921
+ for (let i = 1; i < path.length; i++) {
922
+ text += " " + path[i];
923
+ }
924
+ return text;
925
+ };
926
+ var writeStringRootRef = (writer, id) => writer.write(String(id));
927
+ var writeStringRootRefPath = (writer, path) => writer.write(stringifyRootRefPath(path));
928
+ var createStringStreamWriter = (write) => ({
929
+ write,
930
+ writeRootRef(id) {
931
+ return writeStringRootRef(this, id);
932
+ },
933
+ writeRootRefPath(path) {
934
+ return writeStringRootRefPath(this, path);
935
+ }
936
+ });
937
+
881
938
  // packages/qwik/src/core/shared/ssr-const.ts
882
939
  var LT = "<";
883
940
  var GT = ">";
@@ -978,6 +1035,69 @@ import {
978
1035
  isSignal
979
1036
  } from "@qwik.dev/core/internal";
980
1037
 
1038
+ // packages/qwik/src/server/ooos-utils.ts
1039
+ import { _SubscriptionPatch as SubscriptionPatch } from "@qwik.dev/core/internal";
1040
+ var recordExternalRootEffect = (rootCtx, segmentCtx, storeProxyMap, records, producer, effect, prop, sourceEffects) => {
1041
+ if (!records || prop !== null && !sourceEffects) {
1042
+ return;
1043
+ }
1044
+ let rootObj = producer;
1045
+ if (prop !== null && producer && (typeof producer === "object" || typeof producer === "function")) {
1046
+ rootObj = storeProxyMap.get(producer) || producer;
1047
+ }
1048
+ const rootId = rootCtx.$hasRootId$(rootObj);
1049
+ segmentCtx.$addRoot$(rootObj);
1050
+ segmentCtx.$addRoot$(effect);
1051
+ if (prop !== null && typeof prop !== "string") {
1052
+ segmentCtx.$addRoot$(prop);
1053
+ }
1054
+ records.push({
1055
+ rootObj,
1056
+ rootId,
1057
+ effect,
1058
+ prop
1059
+ });
1060
+ };
1061
+ var collectSubscriptionPatches = (rootCtx, records, rootLimit) => {
1062
+ if (!records?.length) {
1063
+ return;
1064
+ }
1065
+ const patches = [];
1066
+ const patchesByRoot = /* @__PURE__ */ new Map();
1067
+ for (let i = 0; i < records.length; i++) {
1068
+ const entry = records[i];
1069
+ const rootId = entry.rootId === void 0 ? rootCtx.$hasRootId$(entry.rootObj) : entry.rootId;
1070
+ if (rootId === void 0 || rootId >= rootLimit) {
1071
+ continue;
1072
+ }
1073
+ let patch = patchesByRoot.get(rootId);
1074
+ if (!patch) {
1075
+ patch = new SubscriptionPatch(
1076
+ rootId,
1077
+ entry.prop === null ? /* @__PURE__ */ new Set() : /* @__PURE__ */ new Map()
1078
+ );
1079
+ patchesByRoot.set(rootId, patch);
1080
+ patches.push(patch);
1081
+ }
1082
+ const subscriptions = patch.subscriptions;
1083
+ if (entry.prop === null) {
1084
+ if (subscriptions instanceof Set) {
1085
+ subscriptions.add(entry.effect);
1086
+ }
1087
+ } else {
1088
+ if (subscriptions instanceof Map) {
1089
+ let effects = subscriptions.get(entry.prop);
1090
+ if (!effects) {
1091
+ effects = /* @__PURE__ */ new Set();
1092
+ subscriptions.set(entry.prop, effects);
1093
+ }
1094
+ effects.add(entry.effect);
1095
+ }
1096
+ }
1097
+ }
1098
+ return patches.length ? patches : void 0;
1099
+ };
1100
+
981
1101
  // packages/qwik/src/server/preload-impl.ts
982
1102
  import { getPlatform } from "@qwik.dev/core";
983
1103
  var simplifyPath = (base2, path) => {
@@ -1048,9 +1168,7 @@ var preloaderPre = (container, options, nonce) => {
1048
1168
  if (nonce) {
1049
1169
  scriptAttrs["nonce"] = nonce;
1050
1170
  }
1051
- container.openElement("script", null, scriptAttrs, null, null, null);
1052
- container.write(script);
1053
- container.closeElement();
1171
+ container.writeScript(scriptAttrs, script);
1054
1172
  }
1055
1173
  const corePath = simplifyPath(base2, resolvedManifest?.manifest.core);
1056
1174
  if (corePath) {
@@ -1105,9 +1223,7 @@ var includePreloader = (container, options, referencedBundles, nonce) => {
1105
1223
  if (nonce) {
1106
1224
  attrs["nonce"] = nonce;
1107
1225
  }
1108
- container.openElement("script", null, attrs, null, null, null);
1109
- container.write(script);
1110
- container.closeElement();
1226
+ container.writeScript(attrs, script);
1111
1227
  }
1112
1228
  return null;
1113
1229
  };
@@ -1143,14 +1259,15 @@ var preLoaderOptionsDefault = {
1143
1259
  };
1144
1260
 
1145
1261
  // packages/qwik/src/server/scripts.ts
1146
- var QWIK_LOADER_DEFAULT_MINIFIED = 'const e=document,t=window,r="w",n="wp",o="d",s="dp",i="e",c="ep",l="capture:",a=new Set,p=new Set([e]),q=new Map;let u,f,h;const d=(e,t)=>Array.from(e.querySelectorAll(t)),b=e=>{const t=[];return p.forEach(r=>t.push(...d(r,e))),t},m=(e,t,r,n=!1,o=!1)=>e.addEventListener(t,r,{capture:n,passive:o}),g=e=>{J(e);const t=d(e,"[q\\\\:shadowroot]");for(let e=0;e<t.length;e++){const r=t[e].shadowRoot;r&&g(r)}},v=e=>e&&"function"==typeof e.then,y=async e=>{for(let t=0;t<e.length;t++)await e[t]()},w=e=>{if(e.length){const t=()=>y(e);h=h?h.then(t,t):t()}},E=t=>{if(void 0===t._qwikjson_){let r=(t===e.documentElement?e.body:t).lastElementChild;for(;r;){if("SCRIPT"===r.tagName&&"qwik/json"===r.getAttribute("type")){t._qwikjson_=JSON.parse(r.textContent.replace(/\\\\x3C(\\/?script)/gi,"<$1"));break}r=r.previousElementSibling}}},A=(e,t)=>new CustomEvent(e,{detail:t}),C=(t,r)=>{e.dispatchEvent(A(t,r))},_=e=>e.replace(/([A-Z-])/g,e=>"-"+e.toLowerCase()),k=e=>e.replace(/-./g,e=>e[1].toUpperCase()),B=e=>{const t=e.indexOf(":");return{scope:e.slice(0,t),eventName:k(e.slice(t+1))}},S=e=>2===e.length,I=e=>e.charAt(0),N=e=>!!e&&1===e.nodeType,T=(e,t,r)=>e.hasAttribute(r)&&(!!e._qDispatch?.[t]||e.hasAttribute("q-"+t)),$=(t,r,n,o,s,i,c)=>{const l={qBase:n,symbol:i,element:r,reqTime:c};if(""===s){const r=t.getAttribute("q:instance"),n=(e["qFuncs_"+r]||[])[Number.parseInt(i)];if(!n){const e=Error("sym:"+i);C("qerror",{importError:"sync",error:e,...l}),console.error(e)}return n}const a=`${i}|${n}|${s}`,p=q.get(a);if(p)return p;const u=new URL(s,o).href,f=import(u);return E(t),f.then(e=>{const t=e[i];if(t)q.set(a,t),C("qsymbol",l);else{const e=Error(`${i} not in ${u}`);C("qerror",{importError:"no-symbol",error:e,...l}),console.error(e)}return t},e=>{C("qerror",{importError:"async",error:e,...l}),console.error(e)})},R=(t,r,n,o,s,i=!0)=>{let c=!1;s&&(i&&t.hasAttribute("preventdefault:"+s)&&r.preventDefault(),t.hasAttribute("stoppropagation:"+s)&&r.stopPropagation());const l=t._qDispatch?.[n];if(l){if("function"==typeof l){const e=()=>l(r,t);if(c)o.push(async()=>{const t=e();v(t)&&await t});else{const t=e();v(t)&&(c=!0,o.push(()=>t))}}else if(l.length)for(let e=0;e<l.length;e++){const n=l[e];if(n){const e=()=>n(r,t);if(c)o.push(async()=>{const t=e();v(t)&&await t});else{const t=e();v(t)&&(c=!0,o.push(()=>t))}}}return}const a=t.getAttribute("q-"+n);if(a){const n=t.closest("[q\\\\:container]:not([q\\\\:container=html]):not([q\\\\:container=text])"),s=n.getAttribute("q:base"),i=new URL(s,e.baseURI),l=a.split("|");for(let e=0;e<l.length;e++){const a=l[e],p=performance.now(),[q,u,f]=a.split("#"),h=e=>{if(e&&t.isConnected)try{const n=e.call(f,r,t);if(v(n))return n.catch(e=>{C("qerror",{error:e,qBase:s,symbol:u,element:t,reqTime:p})})}catch(e){C("qerror",{error:e,qBase:s,symbol:u,element:t,reqTime:p})}},d=$(n,t,s,i,q,u,p);if(c||v(d))c=!0,o.push(async()=>{await h(v(d)?await d:d)});else{const e=h(d);v(e)&&(c=!0,o.push(()=>e))}}}},x=(e,t=i,r=!0)=>{const n=_(e.type),o=t+":"+n,s=l+n,c=[],a=[],p=[];let q=e.target;for(;q;)N(q)?(c.push(q),a.push(T(q,o,s)),q=q.parentElement):q=q.parentElement;for(let t=c.length-1;t>=0;t--)if(a[t]&&(R(c[t],e,o,p,n,r),e.cancelBubble||e.cancelBubble))return void w(p);for(let t=0;t<c.length;t++)if(!a[t]&&(R(c[t],e,o,p,n,r),!e.bubbles||e.cancelBubble||e.cancelBubble))return void w(p);w(p)},L=e=>x(e,c,!1),U=(e,t,r=!0)=>{const n=_(t.type),o=e+":"+n,s=b("[q-"+e+"\\\\:"+n+"]"),i=[];for(let e=0;e<s.length;e++){const c=s[e];R(c,t,o,i,n,r)}w(i)},j=e=>{U(o,e)},D=e=>{U(s,e,!1)},O=e=>{U(r,e)},P=e=>{U(n,e,!1)},F=()=>{const r=e.readyState;if("interactive"==r||"complete"==r){if(f=1,p.forEach(g),a.has("d:qinit")){a.delete("d:qinit");const e=A("qinit"),t=b("[q-d\\\\:qinit]"),r=[];for(let n=0;n<t.length;n++){const o=t[n];R(o,e,"d:qinit",r),o.removeAttribute("q-d:qinit")}w(r)}if(a.has("d:qidle")&&(a.delete("d:qidle"),(t.requestIdleCallback??t.setTimeout).bind(t)(()=>{const e=A("qidle"),t=b("[q-d\\\\:qidle]"),r=[];for(let n=0;n<t.length;n++){const o=t[n];R(o,e,"d:qidle",r),o.removeAttribute("q-d:qidle")}w(r)})),a.has("e:qvisible")){u||(u=new IntersectionObserver(e=>{const t=[];for(let r=0;r<e.length;r++){const n=e[r];n.isIntersecting&&(u.unobserve(n.target),R(n.target,A("qvisible",n),"e:qvisible",t))}w(t)}));const e=b("[q-e\\\\:qvisible]:not([q\\\\:observed])");for(let t=0;t<e.length;t++){const r=e[t];u.observe(r),r.setAttribute("q:observed","true")}}}},J=(...e)=>{for(let n=0;n<e.length;n++){const s=e[n];if("string"==typeof s){if(!a.has(s)){a.add(s);const{scope:e,eventName:n}=B(s),i=S(e),c=I(e);c===r?m(t,n,i?P:O,!0,i):p.forEach(e=>m(e,n,c===o?i?D:j:i?L:x,!0,i)),1!==f||"e:qvisible"!==s&&"d:qinit"!==s&&"d:qidle"!==s||F()}}else p.has(s)||(a.forEach(e=>{const{scope:t,eventName:n}=B(e),i=S(t),c=I(t);c!==r&&m(s,n,c===o?i?D:j:i?L:x,!0,i)}),p.add(s))}},M=t._qwikEv;M?.roots||(Array.isArray(M)?J(...M):J("e:click","e:input"),t._qwikEv={events:a,roots:p,push:J},m(e,"readystatechange",F),F())';
1147
- var QWIK_LOADER_DEFAULT_DEBUG = 'const doc = document;\nconst win = window;\nconst windowPrefix = "w";\nconst passiveWindowPrefix = "wp";\nconst documentPrefix = "d";\nconst passiveDocumentPrefix = "dp";\nconst elementPrefix = "e";\nconst passiveElementPrefix = "ep";\nconst capturePrefix = "capture:";\nconst events = /* @__PURE__ */ new Set();\nconst roots = /* @__PURE__ */ new Set([doc]);\nconst symbols = /* @__PURE__ */ new Map();\nlet observer;\nlet hasInitialized;\nlet queuedTasks;\nconst nativeQuerySelectorAll = (root, selector) => Array.from(root.querySelectorAll(selector));\nconst querySelectorAll = (query) => {\n const elements = [];\n roots.forEach((root) => elements.push(...nativeQuerySelectorAll(root, query)));\n return elements;\n};\nconst addEventListener = (el, eventName, handler, capture = false, passive = false) => el.addEventListener(eventName, handler, { capture, passive });\nconst findShadowRoots = (fragment) => {\n addEventOrRoot(fragment);\n const shadowRoots = nativeQuerySelectorAll(fragment, "[q\\\\:shadowroot]");\n for (let i = 0; i < shadowRoots.length; i++) {\n const parent = shadowRoots[i];\n const shadowRoot = parent.shadowRoot;\n shadowRoot && findShadowRoots(shadowRoot);\n }\n};\nconst isPromise = (promise) => promise && typeof promise.then === "function";\nconst runTasks = async (tasks) => {\n for (let i = 0; i < tasks.length; i++) {\n await tasks[i]();\n }\n};\nconst queueTasks = (tasks) => {\n if (tasks.length) {\n const run = () => runTasks(tasks);\n queuedTasks = queuedTasks ? queuedTasks.then(run, run) : run();\n }\n};\nconst resolveContainer = (containerEl) => {\n if (containerEl._qwikjson_ === void 0) {\n const parentJSON = containerEl === doc.documentElement ? doc.body : containerEl;\n let script = parentJSON.lastElementChild;\n while (script) {\n if (script.tagName === "SCRIPT" && script.getAttribute("type") === "qwik/json") {\n containerEl._qwikjson_ = JSON.parse(\n script.textContent.replace(/\\\\x3C(\\/?script)/gi, "<$1")\n );\n break;\n }\n script = script.previousElementSibling;\n }\n }\n};\nconst createEvent = (eventName, detail) => new CustomEvent(eventName, { detail });\nconst emitEvent = (eventName, detail) => {\n doc.dispatchEvent(createEvent(eventName, detail));\n};\nconst camelToKebab = (str) => str.replace(/([A-Z-])/g, (a) => "-" + a.toLowerCase());\nconst kebabToCamel = (eventName) => eventName.replace(/-./g, (a) => a[1].toUpperCase());\nconst parseKebabEvent = (event) => {\n const separatorIndex = event.indexOf(":");\n const scope = event.slice(0, separatorIndex);\n return {\n scope,\n eventName: kebabToCamel(event.slice(separatorIndex + 1))\n };\n};\nconst isPassiveScope = (scope) => scope.length === 2;\nconst getRootScope = (scope) => scope.charAt(0);\nconst isElementNode = (node) => !!node && node.nodeType === 1;\nconst isCaptureHandlerElement = (element, scopedKebabName, captureAttribute) => element.hasAttribute(captureAttribute) && (!!element._qDispatch?.[scopedKebabName] || element.hasAttribute("q-" + scopedKebabName));\nconst resolveHandler = (container, element, qBase, base, chunk, symbol, reqTime) => {\n const eventData = {\n qBase,\n symbol,\n element,\n reqTime\n };\n if (chunk === "") {\n const hash = container.getAttribute("q:instance");\n const handler2 = (doc["qFuncs_" + hash] || [])[Number.parseInt(symbol)];\n if (!handler2) {\n const error = new Error("sym:" + symbol);\n emitEvent("qerror", {\n importError: "sync",\n error,\n ...eventData\n });\n console.error(error);\n }\n return handler2;\n }\n const key = `${symbol}|${qBase}|${chunk}`;\n const handler = symbols.get(key);\n if (handler) {\n return handler;\n }\n const href = new URL(chunk, base).href;\n const module = import(\n href\n );\n resolveContainer(container);\n return module.then(\n (module2) => {\n const handler2 = module2[symbol];\n if (!handler2) {\n const error = new Error(`${symbol} not in ${href}`);\n emitEvent("qerror", {\n importError: "no-symbol",\n error,\n ...eventData\n });\n console.error(error);\n } else {\n symbols.set(key, handler2);\n emitEvent("qsymbol", eventData);\n }\n return handler2;\n },\n (error) => {\n emitEvent("qerror", {\n importError: "async",\n error,\n ...eventData\n });\n console.error(error);\n return void 0;\n }\n );\n};\nconst dispatch = (element, ev, scopedKebabName, tasks, kebabName, allowPreventDefault = true) => {\n let defer = false;\n if (kebabName) {\n if (allowPreventDefault && element.hasAttribute("preventdefault:" + kebabName)) {\n ev.preventDefault();\n }\n if (element.hasAttribute("stoppropagation:" + kebabName)) {\n ev.stopPropagation();\n }\n }\n const handlers = element._qDispatch?.[scopedKebabName];\n if (handlers) {\n if (typeof handlers === "function") {\n const run = () => handlers(ev, element);\n if (defer) {\n tasks.push(async () => {\n const result = run();\n if (isPromise(result)) {\n await result;\n }\n });\n } else {\n const result = run();\n if (isPromise(result)) {\n defer = true;\n tasks.push(() => result);\n }\n }\n } else if (handlers.length) {\n for (let i = 0; i < handlers.length; i++) {\n const handler = handlers[i];\n if (handler) {\n const run = () => handler(ev, element);\n if (defer) {\n tasks.push(async () => {\n const result = run();\n if (isPromise(result)) {\n await result;\n }\n });\n } else {\n const result = run();\n if (isPromise(result)) {\n defer = true;\n tasks.push(() => result);\n }\n }\n }\n }\n }\n return;\n }\n const attrValue = element.getAttribute("q-" + scopedKebabName);\n if (attrValue) {\n const container = element.closest(\n "[q\\\\:container]:not([q\\\\:container=html]):not([q\\\\:container=text])"\n );\n const qBase = container.getAttribute("q:base");\n const base = new URL(qBase, doc.baseURI);\n const qrls = attrValue.split("|");\n for (let i = 0; i < qrls.length; i++) {\n const qrl = qrls[i];\n const reqTime = performance.now();\n const [chunk, symbol, capturedIds] = qrl.split("#");\n const run = (handler2) => {\n if (handler2 && element.isConnected) {\n try {\n const result = handler2.call(capturedIds, ev, element);\n if (isPromise(result)) {\n return result.catch((error) => {\n emitEvent("qerror", {\n error,\n qBase,\n symbol,\n element,\n reqTime\n });\n });\n }\n } catch (error) {\n emitEvent("qerror", {\n error,\n qBase,\n symbol,\n element,\n reqTime\n });\n }\n }\n };\n const handler = resolveHandler(container, element, qBase, base, chunk, symbol, reqTime);\n if (defer || isPromise(handler)) {\n defer = true;\n tasks.push(async () => {\n await run(isPromise(handler) ? await handler : handler);\n });\n } else {\n const result = run(handler);\n if (isPromise(result)) {\n defer = true;\n tasks.push(() => result);\n }\n }\n }\n }\n};\nconst processElementEvent = (ev, scope = elementPrefix, allowPreventDefault = true) => {\n const kebabName = camelToKebab(ev.type);\n const scopedKebabName = scope + ":" + kebabName;\n const captureAttribute = capturePrefix + kebabName;\n const elements = [];\n const captureHandlers = [];\n const tasks = [];\n let current = ev.target;\n while (current) {\n if (isElementNode(current)) {\n elements.push(current);\n captureHandlers.push(isCaptureHandlerElement(current, scopedKebabName, captureAttribute));\n current = current.parentElement;\n } else {\n current = current.parentElement;\n }\n }\n for (let i = elements.length - 1; i >= 0; i--) {\n if (captureHandlers[i]) {\n dispatch(elements[i], ev, scopedKebabName, tasks, kebabName, allowPreventDefault);\n const continuePropagation = !ev.cancelBubble;\n if (!continuePropagation || ev.cancelBubble) {\n queueTasks(tasks);\n return;\n }\n }\n }\n for (let i = 0; i < elements.length; i++) {\n if (!captureHandlers[i]) {\n dispatch(elements[i], ev, scopedKebabName, tasks, kebabName, allowPreventDefault);\n const doBubble = ev.bubbles && !ev.cancelBubble;\n if (!doBubble || ev.cancelBubble) {\n queueTasks(tasks);\n return;\n }\n }\n }\n queueTasks(tasks);\n};\nconst processPassiveElementEvent = (ev) => processElementEvent(ev, passiveElementPrefix, false);\nconst broadcast = (scope, ev, allowPreventDefault = true) => {\n const kebabName = camelToKebab(ev.type);\n const scopedKebabName = scope + ":" + kebabName;\n const elements = querySelectorAll("[q-" + scope + "\\\\:" + kebabName + "]");\n const tasks = [];\n for (let i = 0; i < elements.length; i++) {\n const el = elements[i];\n dispatch(el, ev, scopedKebabName, tasks, kebabName, allowPreventDefault);\n }\n queueTasks(tasks);\n};\nconst processDocumentEvent = (ev) => {\n broadcast(documentPrefix, ev);\n};\nconst processPassiveDocumentEvent = (ev) => {\n broadcast(passiveDocumentPrefix, ev, false);\n};\nconst processWindowEvent = (ev) => {\n broadcast(windowPrefix, ev);\n};\nconst processPassiveWindowEvent = (ev) => {\n broadcast(passiveWindowPrefix, ev, false);\n};\nconst processReadyStateChange = () => {\n const readyState = doc.readyState;\n if (readyState == "interactive" || readyState == "complete") {\n hasInitialized = 1;\n roots.forEach(findShadowRoots);\n if (events.has("d:qinit")) {\n events.delete("d:qinit");\n const ev = createEvent("qinit");\n const elements = querySelectorAll("[q-d\\\\:qinit]");\n const tasks = [];\n for (let i = 0; i < elements.length; i++) {\n const el = elements[i];\n dispatch(el, ev, "d:qinit", tasks);\n el.removeAttribute("q-d:qinit");\n }\n queueTasks(tasks);\n }\n if (events.has("d:qidle")) {\n events.delete("d:qidle");\n const riC = win.requestIdleCallback ?? win.setTimeout;\n riC.bind(win)(() => {\n const ev = createEvent("qidle");\n const elements = querySelectorAll("[q-d\\\\:qidle]");\n const tasks = [];\n for (let i = 0; i < elements.length; i++) {\n const el = elements[i];\n dispatch(el, ev, "d:qidle", tasks);\n el.removeAttribute("q-d:qidle");\n }\n queueTasks(tasks);\n });\n }\n if (events.has("e:qvisible")) {\n observer || (observer = new IntersectionObserver((entries) => {\n const tasks = [];\n for (let i = 0; i < entries.length; i++) {\n const entry = entries[i];\n if (entry.isIntersecting) {\n observer.unobserve(entry.target);\n dispatch(\n entry.target,\n createEvent("qvisible", entry),\n "e:qvisible",\n tasks\n );\n }\n }\n queueTasks(tasks);\n }));\n const elements = querySelectorAll("[q-e\\\\:qvisible]:not([q\\\\:observed])");\n for (let i = 0; i < elements.length; i++) {\n const el = elements[i];\n observer.observe(el);\n el.setAttribute("q:observed", "true");\n }\n }\n }\n};\nconst addEventOrRoot = (...eventNames) => {\n for (let i = 0; i < eventNames.length; i++) {\n const eventNameOrRoot = eventNames[i];\n if (typeof eventNameOrRoot === "string") {\n if (!events.has(eventNameOrRoot)) {\n events.add(eventNameOrRoot);\n const { scope, eventName } = parseKebabEvent(eventNameOrRoot);\n const passive = isPassiveScope(scope);\n const rootScope = getRootScope(scope);\n if (rootScope === windowPrefix) {\n addEventListener(\n win,\n eventName,\n passive ? processPassiveWindowEvent : processWindowEvent,\n true,\n passive\n );\n } else {\n roots.forEach(\n (root) => addEventListener(\n root,\n eventName,\n rootScope === documentPrefix ? passive ? processPassiveDocumentEvent : processDocumentEvent : passive ? processPassiveElementEvent : processElementEvent,\n true,\n passive\n )\n );\n }\n if (hasInitialized === 1 && (eventNameOrRoot === "e:qvisible" || eventNameOrRoot === "d:qinit" || eventNameOrRoot === "d:qidle")) {\n processReadyStateChange();\n }\n }\n } else {\n if (!roots.has(eventNameOrRoot)) {\n events.forEach((kebabEventName) => {\n const { scope, eventName } = parseKebabEvent(kebabEventName);\n const passive = isPassiveScope(scope);\n const rootScope = getRootScope(scope);\n if (rootScope !== windowPrefix) {\n addEventListener(\n eventNameOrRoot,\n eventName,\n rootScope === documentPrefix ? passive ? processPassiveDocumentEvent : processDocumentEvent : passive ? processPassiveElementEvent : processElementEvent,\n true,\n passive\n );\n }\n });\n roots.add(eventNameOrRoot);\n }\n }\n }\n};\nconst _qwikEv = win._qwikEv;\nif (!_qwikEv?.roots) {\n if (Array.isArray(_qwikEv)) {\n addEventOrRoot(..._qwikEv);\n } else {\n addEventOrRoot("e:click", "e:input");\n }\n win._qwikEv = {\n events,\n roots,\n push: addEventOrRoot\n };\n addEventListener(doc, "readystatechange", processReadyStateChange);\n processReadyStateChange();\n}';
1148
- var QWIK_BACKPATCH_EXECUTOR_MINIFIED = `const t='script[type="qwik/backpatch"]';function e(e,n){const o=n||e.querySelector("[q\\\\:container]:not([q\\\\:container=html]):not([q\\\\:container=text])");if(o){const n=o.querySelector(t);if(n){const t=JSON.parse(n.textContent||"[]"),r=e.createTreeWalker(o,NodeFilter.SHOW_ELEMENT);let c=r.currentNode,i=c.hasAttribute(":")?0:-1;for(let e=0;e<t.length;e+=3){const n=t[e],o=t[e+1];let s=t[e+2];for(;i<n&&(c=r.nextNode(),c);)c.hasAttribute(":")&&i++;const a=c;null==s||!1===s?a.removeAttribute(o):("boolean"==typeof s&&(s=""),a.setAttribute(o,s))}}}}const n=document.currentScript;if(n){const t=n.closest("[q\\\\:container]:not([q\\\\:container=html]):not([q\\\\:container=text])");t&&e(document,t)}`;
1262
+ var QWIK_LOADER_DEFAULT_MINIFIED = 'const e=document,t=window,n="w",r="wp",o="d",s="dp",i="e",a="ep",c="capture:",l="readystatechange",p=0,u=new Set,d=new Set([e]),f=new Map,h={};let q,b,g;const m=(e,t)=>Array.from(e.querySelectorAll(t)),v=e=>{const t=[];return d.forEach(n=>t.push(...m(n,e))),t},w=(e,t,n,r=!1,o=!1)=>e.addEventListener(t,n,{capture:r,passive:o}),y=e=>{H(e);const t=m(e,"[q\\\\:shadowroot]");for(let e=0;e<t.length;e++){const n=t[e].shadowRoot;n&&y(n)}},A=e=>e&&"function"==typeof e.then,E=async e=>{for(let t=0;t<e.length;t++)await e[t]()},C=e=>{if(e.length){const t=()=>E(e);g=g?g.then(t,t):t()}},S=t=>{if(void 0===t._qwikjson_){let n=(t===e.documentElement?e.body:t).lastElementChild;for(;n;){if("SCRIPT"===n.tagName&&"qwik/json"===n.getAttribute("type")){t._qwikjson_=JSON.parse(n.textContent.replace(/\\\\x3C(\\/?script)/gi,"<$1"));break}n=n.previousElementSibling}}},_=e=>{h[e]=1,I(l)},k=t=>{const n=t.getAttribute("q:instance");return"paused"===t.getAttribute("q:container")&&"loading"===e.readyState&&!h[n]&&new Promise(t=>{w(e,l,()=>{("loading"!==e.readyState||h[n])&&t()})})},$=(e,t)=>new CustomEvent(e,{detail:t}),I=(t,n)=>{e.dispatchEvent($(t,n))},N=e=>e.replace(/([A-Z-])/g,e=>"-"+e.toLowerCase()),R=e=>e.replace(/-./g,e=>e[1].toUpperCase()),T=e=>{const t=e.indexOf(":");return{scope:e.slice(0,t),eventName:R(e.slice(t+1))}},x=e=>2===e.length,B=e=>e.charAt(0),L=e=>!!e&&1===e.nodeType,U=(e,t,n)=>e.hasAttribute(n)&&(!!e._qDispatch?.[t]||e.hasAttribute("q-"+t)),j=(t,n,r,o,s,i,a,c=!0)=>{const l={qBase:r,symbol:i,element:n,reqTime:a};if(!s){const n=(e["qFuncs_"+t.getAttribute("q:instance")]||[])[+i];if(!n&&c){const e=Error("sym:"+i);I("qerror",{importError:"sync",error:e,...l}),console.error(e)}return n}const p=`${i}|${r}|${s}`,u=f.get(p);if(u)return u;const d=new URL(s,o).href,h=import(d);return S(t),h.then(e=>{const t=e[i];if(t)f.set(p,t),I("qsymbol",l);else{const e=Error(`${i} not in ${d}`);I("qerror",{importError:"no-symbol",error:e,...l}),console.error(e)}return t},e=>{I("qerror",{importError:"async",error:e,...l}),console.error(e)})},D=(t,n,r,o,s,i=!0)=>{let a=!1;s&&(i&&t.hasAttribute("preventdefault:"+s)&&n.preventDefault(),t.hasAttribute("stoppropagation:"+s)&&n.stopPropagation());const c=t._qDispatch?.[r];if(c){if("function"==typeof c){const e=()=>c(n,t);if(a)o.push(async()=>{const t=e();A(t)&&await t});else{const t=e();A(t)&&(a=!0,o.push(()=>t))}}else if(c.length)for(let e=0;e<c.length;e++){const r=c[e];if(r){const e=()=>r(n,t);if(a)o.push(async()=>{const t=e();A(t)&&await t});else{const t=e();A(t)&&(a=!0,o.push(()=>t))}}}return}const l=t.getAttribute("q-"+r);if(l){const r=t.closest("[q\\\\:container]:not([q\\\\:container=html]):not([q\\\\:container=text])"),s=r.getAttribute("q:base"),i=new URL(s,e.baseURI),c=l.split("|"),p=k(r);for(let e=0;e<c.length;e++){const l=c[e],u=performance.now(),[d,f,h]=l.split("#"),q=e=>{if(e&&t.isConnected){const r=e=>{I("qerror",{error:e,qBase:s,symbol:f,element:t,reqTime:u})};try{const o=e.call(h,n,t);if(A(o))return o.catch(r)}catch(e){return r(e)}}},b=(e=!0)=>j(r,t,s,i,d,f,u,e),g=p?void 0:b();if(p)a=!0,o.push(async()=>{await p,await q(await b(!1)||await b())});else if(A(g))a=!0,o.push(()=>g.then(q));else if(a)a=!0,o.push(async()=>{await q(g||await b())});else{const e=q(g);A(e)&&(a=!0,o.push(()=>e))}}}},O=(e,t=i,n=!0)=>{const r=N(e.type),o=t+":"+r,s=c+r,a=[],l=[],p=[];let u=e.target;for(;u;)L(u)?(a.push(u),l.push(U(u,o,s)),u=u.parentElement):u=u.parentElement;for(let t=a.length-1;t>=0;t--)if(l[t]&&(D(a[t],e,o,p,r,n),e.cancelBubble))return void C(p);for(let t=0;t<a.length;t++)if(!l[t]&&(D(a[t],e,o,p,r,n),!e.bubbles||e.cancelBubble))return void C(p);C(p)},P=e=>O(e,a,!1),F=(e,t,n=!0)=>{const r=N(t.type),o=e+":"+r,s=v("[q-"+e+"\\\\:"+r+"]"),i=[];for(let e=0;e<s.length;e++){const a=s[e];D(a,t,o,i,r,n)}C(i)},J=e=>{F(o,e)},M=e=>{F(s,e,!1)},Z=e=>{F(n,e)},z=e=>{F(r,e,!1)},G=()=>{const n=e.readyState;if("interactive"==n||"complete"==n){if(b=1,d.forEach(y),u.has("d:qinit")){u.delete("d:qinit");const e=$("qinit"),t=v("[q-d\\\\:qinit]"),n=[];for(let r=0;r<t.length;r++){const o=t[r];D(o,e,"d:qinit",n),o.removeAttribute("q-d:qinit")}C(n)}if(u.has("d:qidle")&&(u.delete("d:qidle"),(t.requestIdleCallback??t.setTimeout).bind(t)(()=>{const e=$("qidle"),t=v("[q-d\\\\:qidle]"),n=[];for(let r=0;r<t.length;r++){const o=t[r];D(o,e,"d:qidle",n),o.removeAttribute("q-d:qidle")}C(n)})),u.has("e:qvisible")){q||(q=new IntersectionObserver(e=>{const t=[];for(let n=0;n<e.length;n++){const r=e[n];r.isIntersecting&&(q.unobserve(r.target),D(r.target,$("qvisible",r),"e:qvisible",t))}C(t)}));const e=v("[q-e\\\\:qvisible]:not([q\\\\:observed])");for(let t=0;t<e.length;t++){const n=e[t];q.observe(n),n.setAttribute("q:observed","true")}}}},H=(...e)=>{for(let r=0;r<e.length;r++){const s=e[r];if(0===s)_(e[++r]);else if("string"==typeof s){if(!u.has(s)){u.add(s);const{scope:e,eventName:r}=T(s),i=x(e),a=B(e);a===n?w(t,r,i?z:Z,!0,i):d.forEach(e=>w(e,r,a===o?i?M:J:i?P:O,!0,i)),1!==b||"e:qvisible"!==s&&"d:qinit"!==s&&"d:qidle"!==s||G()}}else d.has(s)||(u.forEach(e=>{const{scope:t,eventName:r}=T(e),i=x(t),a=B(t);a!==n&&w(s,r,a===o?i?M:J:i?P:O,!0,i)}),d.add(s))}},K=t._qwikEv;K?.roots||(Array.isArray(K)?H(...K):H("e:click","e:input"),t._qwikEv={events:u,roots:d,push:H},w(e,l,G),G())';
1263
+ var QWIK_LOADER_DEFAULT_DEBUG = 'const doc = document;\nconst win = window;\nconst windowPrefix = "w";\nconst passiveWindowPrefix = "wp";\nconst documentPrefix = "d";\nconst passiveDocumentPrefix = "dp";\nconst elementPrefix = "e";\nconst passiveElementPrefix = "ep";\nconst capturePrefix = "capture:";\nconst readyStateChange = "readystatechange";\nconst QwikEvContainerReady = 0;\nconst events = /* @__PURE__ */ new Set();\nconst roots = /* @__PURE__ */ new Set([doc]);\nconst symbols = /* @__PURE__ */ new Map();\nconst readyContainers = {};\nlet observer;\nlet hasInitialized;\nlet queuedTasks;\nconst nativeQuerySelectorAll = (root, selector) => Array.from(root.querySelectorAll(selector));\nconst querySelectorAll = (query) => {\n const elements = [];\n roots.forEach((root) => elements.push(...nativeQuerySelectorAll(root, query)));\n return elements;\n};\nconst addEventListener = (el, eventName, handler, capture = false, passive = false) => el.addEventListener(eventName, handler, { capture, passive });\nconst findShadowRoots = (fragment) => {\n addEventOrRoot(fragment);\n const shadowRoots = nativeQuerySelectorAll(fragment, "[q\\\\:shadowroot]");\n for (let i = 0; i < shadowRoots.length; i++) {\n const parent = shadowRoots[i];\n const shadowRoot = parent.shadowRoot;\n shadowRoot && findShadowRoots(shadowRoot);\n }\n};\nconst isPromise = (promise) => promise && typeof promise.then === "function";\nconst runTasks = async (tasks) => {\n for (let i = 0; i < tasks.length; i++) {\n await tasks[i]();\n }\n};\nconst queueTasks = (tasks) => {\n if (tasks.length) {\n const run = () => runTasks(tasks);\n queuedTasks = queuedTasks ? queuedTasks.then(run, run) : run();\n }\n};\nconst resolveContainer = (containerEl) => {\n if (containerEl._qwikjson_ === void 0) {\n const parentJSON = containerEl === doc.documentElement ? doc.body : containerEl;\n let script = parentJSON.lastElementChild;\n while (script) {\n if (script.tagName === "SCRIPT" && script.getAttribute("type") === "qwik/json") {\n containerEl._qwikjson_ = JSON.parse(\n script.textContent.replace(/\\\\x3C(\\/?script)/gi, "<$1")\n );\n break;\n }\n script = script.previousElementSibling;\n }\n }\n};\nconst markContainerReady = (hash) => {\n readyContainers[hash] = 1;\n emitEvent(readyStateChange);\n};\nconst waitForContainerReady = (container) => {\n const hash = container.getAttribute("q:instance");\n return container.getAttribute("q:container") === "paused" && doc.readyState === "loading" && !readyContainers[hash] && new Promise((resolve) => {\n const ready = () => {\n if (doc.readyState !== "loading" || readyContainers[hash]) {\n resolve();\n }\n };\n addEventListener(doc, readyStateChange, ready);\n });\n};\nconst createEvent = (eventName, detail) => new CustomEvent(eventName, { detail });\nconst emitEvent = (eventName, detail) => {\n doc.dispatchEvent(createEvent(eventName, detail));\n};\nconst camelToKebab = (str) => str.replace(/([A-Z-])/g, (a) => "-" + a.toLowerCase());\nconst kebabToCamel = (eventName) => eventName.replace(/-./g, (a) => a[1].toUpperCase());\nconst parseKebabEvent = (event) => {\n const separatorIndex = event.indexOf(":");\n const scope = event.slice(0, separatorIndex);\n return {\n scope,\n eventName: kebabToCamel(event.slice(separatorIndex + 1))\n };\n};\nconst isPassiveScope = (scope) => scope.length === 2;\nconst getRootScope = (scope) => scope.charAt(0);\nconst isElementNode = (node) => !!node && node.nodeType === 1;\nconst isCaptureHandlerElement = (element, scopedKebabName, captureAttribute) => element.hasAttribute(captureAttribute) && (!!element._qDispatch?.[scopedKebabName] || element.hasAttribute("q-" + scopedKebabName));\nconst resolveHandler = (container, element, qBase, base, chunk, symbol, reqTime, reportSyncError = true) => {\n const eventData = {\n qBase,\n symbol,\n element,\n reqTime\n };\n if (!chunk) {\n const handler2 = (doc["qFuncs_" + container.getAttribute("q:instance")] || [])[+symbol];\n if (!handler2 && reportSyncError) {\n const error = new Error("sym:" + symbol);\n emitEvent("qerror", {\n importError: "sync",\n error,\n ...eventData\n });\n console.error(error);\n }\n return handler2;\n }\n const key = `${symbol}|${qBase}|${chunk}`;\n const handler = symbols.get(key);\n if (handler) {\n return handler;\n }\n const href = new URL(chunk, base).href;\n const module = import(\n href\n );\n resolveContainer(container);\n return module.then(\n (module2) => {\n const handler2 = module2[symbol];\n if (!handler2) {\n const error = new Error(`${symbol} not in ${href}`);\n emitEvent("qerror", {\n importError: "no-symbol",\n error,\n ...eventData\n });\n console.error(error);\n } else {\n symbols.set(key, handler2);\n emitEvent("qsymbol", eventData);\n }\n return handler2;\n },\n (error) => {\n emitEvent("qerror", {\n importError: "async",\n error,\n ...eventData\n });\n console.error(error);\n return void 0;\n }\n );\n};\nconst dispatch = (element, ev, scopedKebabName, tasks, kebabName, allowPreventDefault = true) => {\n let defer = false;\n if (kebabName) {\n if (allowPreventDefault && element.hasAttribute("preventdefault:" + kebabName)) {\n ev.preventDefault();\n }\n if (element.hasAttribute("stoppropagation:" + kebabName)) {\n ev.stopPropagation();\n }\n }\n const handlers = element._qDispatch?.[scopedKebabName];\n if (handlers) {\n if (typeof handlers === "function") {\n const run = () => handlers(ev, element);\n if (defer) {\n tasks.push(async () => {\n const result = run();\n if (isPromise(result)) {\n await result;\n }\n });\n } else {\n const result = run();\n if (isPromise(result)) {\n defer = true;\n tasks.push(() => result);\n }\n }\n } else if (handlers.length) {\n for (let i = 0; i < handlers.length; i++) {\n const handler = handlers[i];\n if (handler) {\n const run = () => handler(ev, element);\n if (defer) {\n tasks.push(async () => {\n const result = run();\n if (isPromise(result)) {\n await result;\n }\n });\n } else {\n const result = run();\n if (isPromise(result)) {\n defer = true;\n tasks.push(() => result);\n }\n }\n }\n }\n }\n return;\n }\n const attrValue = element.getAttribute("q-" + scopedKebabName);\n if (attrValue) {\n const container = element.closest(\n "[q\\\\:container]:not([q\\\\:container=html]):not([q\\\\:container=text])"\n );\n const qBase = container.getAttribute("q:base");\n const base = new URL(qBase, doc.baseURI);\n const qrls = attrValue.split("|");\n const waitForReady = waitForContainerReady(container);\n for (let i = 0; i < qrls.length; i++) {\n const qrl = qrls[i];\n const reqTime = performance.now();\n const [chunk, symbol, capturedIds] = qrl.split("#");\n const run = (handler2) => {\n if (handler2 && element.isConnected) {\n const onError = (error) => {\n emitEvent("qerror", {\n error,\n qBase,\n symbol,\n element,\n reqTime\n });\n };\n try {\n const result = handler2.call(capturedIds, ev, element);\n if (isPromise(result)) {\n return result.catch(onError);\n }\n } catch (error) {\n return onError(error);\n }\n }\n };\n const resolve = (reportSyncError = true) => resolveHandler(container, element, qBase, base, chunk, symbol, reqTime, reportSyncError);\n const handler = waitForReady ? void 0 : resolve();\n if (waitForReady) {\n defer = true;\n tasks.push(async () => {\n await waitForReady;\n await run(await resolve(false) || await resolve());\n });\n } else if (isPromise(handler)) {\n defer = true;\n tasks.push(() => handler.then(run));\n } else if (defer) {\n defer = true;\n tasks.push(async () => {\n await run(handler || await resolve());\n });\n } else {\n const result = run(handler);\n if (isPromise(result)) {\n defer = true;\n tasks.push(() => result);\n }\n }\n }\n }\n};\nconst processElementEvent = (ev, scope = elementPrefix, allowPreventDefault = true) => {\n const kebabName = camelToKebab(ev.type);\n const scopedKebabName = scope + ":" + kebabName;\n const captureAttribute = capturePrefix + kebabName;\n const elements = [];\n const captureHandlers = [];\n const tasks = [];\n let current = ev.target;\n while (current) {\n if (isElementNode(current)) {\n elements.push(current);\n captureHandlers.push(isCaptureHandlerElement(current, scopedKebabName, captureAttribute));\n current = current.parentElement;\n } else {\n current = current.parentElement;\n }\n }\n for (let i = elements.length - 1; i >= 0; i--) {\n if (captureHandlers[i]) {\n dispatch(elements[i], ev, scopedKebabName, tasks, kebabName, allowPreventDefault);\n if (ev.cancelBubble) {\n queueTasks(tasks);\n return;\n }\n }\n }\n for (let i = 0; i < elements.length; i++) {\n if (!captureHandlers[i]) {\n dispatch(elements[i], ev, scopedKebabName, tasks, kebabName, allowPreventDefault);\n if (!ev.bubbles || ev.cancelBubble) {\n queueTasks(tasks);\n return;\n }\n }\n }\n queueTasks(tasks);\n};\nconst processPassiveElementEvent = (ev) => processElementEvent(ev, passiveElementPrefix, false);\nconst broadcast = (scope, ev, allowPreventDefault = true) => {\n const kebabName = camelToKebab(ev.type);\n const scopedKebabName = scope + ":" + kebabName;\n const elements = querySelectorAll("[q-" + scope + "\\\\:" + kebabName + "]");\n const tasks = [];\n for (let i = 0; i < elements.length; i++) {\n const el = elements[i];\n dispatch(el, ev, scopedKebabName, tasks, kebabName, allowPreventDefault);\n }\n queueTasks(tasks);\n};\nconst processDocumentEvent = (ev) => {\n broadcast(documentPrefix, ev);\n};\nconst processPassiveDocumentEvent = (ev) => {\n broadcast(passiveDocumentPrefix, ev, false);\n};\nconst processWindowEvent = (ev) => {\n broadcast(windowPrefix, ev);\n};\nconst processPassiveWindowEvent = (ev) => {\n broadcast(passiveWindowPrefix, ev, false);\n};\nconst processReadyStateChange = () => {\n const readyState = doc.readyState;\n if (readyState == "interactive" || readyState == "complete") {\n hasInitialized = 1;\n roots.forEach(findShadowRoots);\n if (events.has("d:qinit")) {\n events.delete("d:qinit");\n const ev = createEvent("qinit");\n const elements = querySelectorAll("[q-d\\\\:qinit]");\n const tasks = [];\n for (let i = 0; i < elements.length; i++) {\n const el = elements[i];\n dispatch(el, ev, "d:qinit", tasks);\n el.removeAttribute("q-d:qinit");\n }\n queueTasks(tasks);\n }\n if (events.has("d:qidle")) {\n events.delete("d:qidle");\n const riC = win.requestIdleCallback ?? win.setTimeout;\n riC.bind(win)(() => {\n const ev = createEvent("qidle");\n const elements = querySelectorAll("[q-d\\\\:qidle]");\n const tasks = [];\n for (let i = 0; i < elements.length; i++) {\n const el = elements[i];\n dispatch(el, ev, "d:qidle", tasks);\n el.removeAttribute("q-d:qidle");\n }\n queueTasks(tasks);\n });\n }\n if (events.has("e:qvisible")) {\n observer || (observer = new IntersectionObserver((entries) => {\n const tasks = [];\n for (let i = 0; i < entries.length; i++) {\n const entry = entries[i];\n if (entry.isIntersecting) {\n observer.unobserve(entry.target);\n dispatch(\n entry.target,\n createEvent("qvisible", entry),\n "e:qvisible",\n tasks\n );\n }\n }\n queueTasks(tasks);\n }));\n const elements = querySelectorAll("[q-e\\\\:qvisible]:not([q\\\\:observed])");\n for (let i = 0; i < elements.length; i++) {\n const el = elements[i];\n observer.observe(el);\n el.setAttribute("q:observed", "true");\n }\n }\n }\n};\nconst addEventOrRoot = (...eventNames) => {\n for (let i = 0; i < eventNames.length; i++) {\n const eventNameOrRoot = eventNames[i];\n if (eventNameOrRoot === QwikEvContainerReady) {\n markContainerReady(eventNames[++i]);\n } else if (typeof eventNameOrRoot === "string") {\n if (!events.has(eventNameOrRoot)) {\n events.add(eventNameOrRoot);\n const { scope, eventName } = parseKebabEvent(eventNameOrRoot);\n const passive = isPassiveScope(scope);\n const rootScope = getRootScope(scope);\n if (rootScope === windowPrefix) {\n addEventListener(\n win,\n eventName,\n passive ? processPassiveWindowEvent : processWindowEvent,\n true,\n passive\n );\n } else {\n roots.forEach(\n (root) => addEventListener(\n root,\n eventName,\n rootScope === documentPrefix ? passive ? processPassiveDocumentEvent : processDocumentEvent : passive ? processPassiveElementEvent : processElementEvent,\n true,\n passive\n )\n );\n }\n if (hasInitialized === 1 && (eventNameOrRoot === "e:qvisible" || eventNameOrRoot === "d:qinit" || eventNameOrRoot === "d:qidle")) {\n processReadyStateChange();\n }\n }\n } else {\n if (!roots.has(eventNameOrRoot)) {\n events.forEach((kebabEventName) => {\n const { scope, eventName } = parseKebabEvent(kebabEventName);\n const passive = isPassiveScope(scope);\n const rootScope = getRootScope(scope);\n if (rootScope !== windowPrefix) {\n addEventListener(\n eventNameOrRoot,\n eventName,\n rootScope === documentPrefix ? passive ? processPassiveDocumentEvent : processDocumentEvent : passive ? processPassiveElementEvent : processElementEvent,\n true,\n passive\n );\n }\n });\n roots.add(eventNameOrRoot);\n }\n }\n }\n};\nconst _qwikEv = win._qwikEv;\nif (!_qwikEv?.roots) {\n if (Array.isArray(_qwikEv)) {\n addEventOrRoot(..._qwikEv);\n } else {\n addEventOrRoot("e:click", "e:input");\n }\n win._qwikEv = {\n events,\n roots,\n push: addEventOrRoot\n };\n addEventListener(doc, readyStateChange, processReadyStateChange);\n processReadyStateChange();\n}';
1264
+ var QWIK_BACKPATCH_EXECUTOR_MINIFIED = `const t='script[type="qwik/backpatch"]';function e(e,n){const o=n||e.querySelector("[q\\\\:container]:not([q\\\\:container=html]):not([q\\\\:container=text])");if(o){const n=o.querySelectorAll(t),r=n[n.length-1];if(r){const t=JSON.parse(r.textContent||"[]"),n=e.createTreeWalker(o,NodeFilter.SHOW_ELEMENT);let c=n.currentNode,i=c.hasAttribute(":")?0:-1;for(let e=0;e<t.length;e+=3){const o=t[e],r=t[e+1];let l=t[e+2];for(;i<o&&(c=n.nextNode(),c);)c.hasAttribute(":")&&i++;const s=c;null==l||!1===l?s.removeAttribute(r):("boolean"==typeof l&&(l=""),s.setAttribute(r,l))}}}}const n=document.currentScript;if(n){const t=n.closest("[q\\\\:container]:not([q\\\\:container=html]):not([q\\\\:container=text])");t&&e(document,t)}`;
1149
1265
  var QWIK_BACKPATCH_EXECUTOR_DEBUG = `const BACKPATCH_DATA_SELECTOR = 'script[type="qwik/backpatch"]';
1150
1266
  function executeBackpatch(doc, containerElement) {
1151
1267
  const container = containerElement || doc.querySelector("[q\\\\:container]:not([q\\\\:container=html]):not([q\\\\:container=text])");
1152
1268
  if (container) {
1153
- const script = container.querySelector(BACKPATCH_DATA_SELECTOR);
1269
+ const scripts = container.querySelectorAll(BACKPATCH_DATA_SELECTOR);
1270
+ const script = scripts[scripts.length - 1];
1154
1271
  if (script) {
1155
1272
  const data = JSON.parse(script.textContent || "[]");
1156
1273
  const walker = doc.createTreeWalker(container, NodeFilter.SHOW_ELEMENT);
@@ -1191,6 +1308,170 @@ if (executorScript) {
1191
1308
  executeBackpatch(document, container);
1192
1309
  }
1193
1310
  }`;
1311
+ var QWIK_OUT_OF_ORDER_EXECUTOR_MINIFIED = `const t='template[q\\\\:r="',e="q:r",n='[q\\\\:rp="',r="q:g",l="q:i",o="q:o",s="[q\\\\:container]:not([q\\\\:container=html]):not([q\\\\:container=text])",u=u=>{const i=new WeakMap,c=()=>{const t=u.currentScript;return t&&t.closest(s)||u},f=(t,e,n,r)=>{let l=i.get(t);return l||i.set(t,l={}),l[e]||(l[e]={r:{},n:0,t:n,o:r})},a=(t,e)=>t?(e&&e.style&&(e.style.display="none"),t.style&&(t.style.display="contents"),1):0,q=t=>{const e=t.o;let n,r,l=0;if("p"===e)for(const e in t.r)n=t.r[e],n[0]&&a(n[0],n[1])&&(n[0]=0,l++);else if("s"===e)for(r=t.n;(n=t.r[r])&&n[0]&&a(n[0],n[1]);r++)n[0]=0,l++,t.n=r+1;else if("r"===e){if(t.t<0)return 0;for(t.n<0&&(t.n=t.t-1),r=t.n;(n=t.r[r])&&n[0]&&a(n[0],n[1]);r--)n[0]=0,l++,t.n=r-1}else{if(t.t<0)return 0;for(r=0;r<t.t;r++)if(n=t.r[r],!n)return 0;for(r=0;r<t.t;r++)n=t.r[r],n[0]&&a(n[0],n[1])&&(n[0]=0,l++)}return l},p=s=>{const i=c(),p=((n,r)=>{const l=u.currentScript,o=l?l.previousElementSibling:null;if(o&&"template"===o.localName&&o.getAttribute(e)===r+"")return o;const s=n.querySelectorAll(t+r+'"]');return s.length?s[s.length-1]:null})(i,s);if(!p)return;const g=((e,r,l)=>{if(!l)return null;const o=((t,e)=>t.querySelector(n+e+'"]'))(e,r),s=o?((e,n)=>e.querySelector(t+n+'"]'))(o,r):null,u=s?s.parentNode:null;return s&&o&&u?(u.insertBefore(l.content,s),s.remove(),l.remove(),[o,o.previousElementSibling]):null})(i,s,p);if(!g)return;((t,e)=>{var n;const r=u;null==(n=r.qProcessOOOS)||n.call(r,t,e)})(s,g[0]||null);const m=p.getAttribute(r);if(m){const t=+(p.getAttribute(l)||0),e=f(i,m,-1,p.getAttribute(o)||"p");return e.r[t]=g,void q(e)}a(g[0]||null,g[1])};p.g=(t,e,n)=>{const r=f(c(),t,e,n);r.t=e,r.o=n,"r"===r.o&&0===r.n&&(r.n=e-1),q(r)},p.d=u,globalThis.qO=p};u(document)`;
1312
+ var QWIK_OUT_OF_ORDER_EXECUTOR_DEBUG = `const Q_RESOLVED_SELECTOR = 'template[q\\\\:r="';
1313
+ const Q_RESOLVED_ATTR = "q:r";
1314
+ const Q_RESULT_PARENT_SELECTOR = '[q\\\\:rp="';
1315
+ const Q_GROUP_ATTR = "q:g";
1316
+ const Q_INDEX_ATTR = "q:i";
1317
+ const Q_ORDER_ATTR = "q:o";
1318
+ const Q_CONTAINER_SELECTOR = "[q\\\\:container]:not([q\\\\:container=html]):not([q\\\\:container=text])";
1319
+ const installOutOfOrderExecutor = (doc) => {
1320
+ const groups = /* @__PURE__ */ new WeakMap();
1321
+ const process = (boundaryId, content) => {
1322
+ var _a;
1323
+ const executorDoc = doc;
1324
+ (_a = executorDoc.qProcessOOOS) == null ? void 0 : _a.call(executorDoc, boundaryId, content);
1325
+ };
1326
+ const getScope = () => {
1327
+ const script = doc.currentScript;
1328
+ return script ? script.closest(Q_CONTAINER_SELECTOR) || doc : doc;
1329
+ };
1330
+ const group = (scope, groupId, total, order) => {
1331
+ let scopedGroups = groups.get(scope);
1332
+ if (!scopedGroups) {
1333
+ groups.set(scope, scopedGroups = {});
1334
+ }
1335
+ return scopedGroups[groupId] || (scopedGroups[groupId] = {
1336
+ r: {},
1337
+ n: 0,
1338
+ t: total,
1339
+ o: order
1340
+ });
1341
+ };
1342
+ const getResolvedTemplate = (scope, boundaryId) => {
1343
+ const currentScript = doc.currentScript;
1344
+ const previousElement = currentScript ? currentScript.previousElementSibling : null;
1345
+ if (previousElement && previousElement.localName === "template" && previousElement.getAttribute(Q_RESOLVED_ATTR) === String(boundaryId)) {
1346
+ return previousElement;
1347
+ }
1348
+ const templates = scope.querySelectorAll(Q_RESOLVED_SELECTOR + boundaryId + '"]');
1349
+ return templates.length ? templates[templates.length - 1] : null;
1350
+ };
1351
+ const getPlaceholderTemplate = (content, boundaryId) => {
1352
+ return content.querySelector(Q_RESOLVED_SELECTOR + boundaryId + '"]');
1353
+ };
1354
+ const getResultParent = (scope, boundaryId) => {
1355
+ return scope.querySelector(Q_RESULT_PARENT_SELECTOR + boundaryId + '"]');
1356
+ };
1357
+ const reveal = (content, fallback) => {
1358
+ if (!content) {
1359
+ return 0;
1360
+ }
1361
+ if (fallback && fallback.style) {
1362
+ fallback.style.display = "none";
1363
+ }
1364
+ if (content.style) {
1365
+ content.style.display = "contents";
1366
+ }
1367
+ return 1;
1368
+ };
1369
+ const move = (scope, boundaryId, resolved) => {
1370
+ if (!resolved) {
1371
+ return null;
1372
+ }
1373
+ const content = getResultParent(scope, boundaryId);
1374
+ const placeholder = content ? getPlaceholderTemplate(content, boundaryId) : null;
1375
+ const parent = placeholder ? placeholder.parentNode : null;
1376
+ if (!placeholder || !content || !parent) {
1377
+ return null;
1378
+ }
1379
+ parent.insertBefore(resolved.content, placeholder);
1380
+ placeholder.remove();
1381
+ resolved.remove();
1382
+ return [content, content.previousElementSibling];
1383
+ };
1384
+ const flush = (group2) => {
1385
+ const order = group2.o;
1386
+ let entry;
1387
+ let index;
1388
+ let swapped = 0;
1389
+ if (order === "p") {
1390
+ for (const key in group2.r) {
1391
+ entry = group2.r[key];
1392
+ if (entry[0] && reveal(entry[0], entry[1])) {
1393
+ entry[0] = 0;
1394
+ swapped++;
1395
+ }
1396
+ }
1397
+ } else if (order === "s") {
1398
+ for (index = group2.n; (entry = group2.r[index]) && entry[0]; index++) {
1399
+ if (!reveal(entry[0], entry[1])) {
1400
+ break;
1401
+ }
1402
+ entry[0] = 0;
1403
+ swapped++;
1404
+ group2.n = index + 1;
1405
+ }
1406
+ } else if (order === "r") {
1407
+ if (group2.t < 0) {
1408
+ return 0;
1409
+ }
1410
+ if (group2.n < 0) {
1411
+ group2.n = group2.t - 1;
1412
+ }
1413
+ for (index = group2.n; (entry = group2.r[index]) && entry[0]; index--) {
1414
+ if (!reveal(entry[0], entry[1])) {
1415
+ break;
1416
+ }
1417
+ entry[0] = 0;
1418
+ swapped++;
1419
+ group2.n = index - 1;
1420
+ }
1421
+ } else {
1422
+ if (group2.t < 0) {
1423
+ return 0;
1424
+ }
1425
+ for (index = 0; index < group2.t; index++) {
1426
+ entry = group2.r[index];
1427
+ if (!entry) {
1428
+ return 0;
1429
+ }
1430
+ }
1431
+ for (index = 0; index < group2.t; index++) {
1432
+ entry = group2.r[index];
1433
+ if (entry[0] && reveal(entry[0], entry[1])) {
1434
+ entry[0] = 0;
1435
+ swapped++;
1436
+ }
1437
+ }
1438
+ }
1439
+ return swapped;
1440
+ };
1441
+ const qO = ((boundaryId) => {
1442
+ const scope = getScope();
1443
+ const resolved = getResolvedTemplate(scope, boundaryId);
1444
+ if (!resolved) {
1445
+ return;
1446
+ }
1447
+ const entry = move(scope, boundaryId, resolved);
1448
+ if (!entry) {
1449
+ return;
1450
+ }
1451
+ process(boundaryId, entry[0] || null);
1452
+ const groupId = resolved.getAttribute(Q_GROUP_ATTR);
1453
+ if (groupId) {
1454
+ const index = +(resolved.getAttribute(Q_INDEX_ATTR) || 0);
1455
+ const currentGroup = group(scope, groupId, -1, resolved.getAttribute(Q_ORDER_ATTR) || "p");
1456
+ currentGroup.r[index] = entry;
1457
+ flush(currentGroup);
1458
+ return;
1459
+ }
1460
+ reveal(entry[0] || null, entry[1]);
1461
+ });
1462
+ qO.g = (groupId, total, order) => {
1463
+ const currentGroup = group(getScope(), groupId, total, order);
1464
+ currentGroup.t = total;
1465
+ currentGroup.o = order;
1466
+ if (currentGroup.o === "r" && currentGroup.n === 0) {
1467
+ currentGroup.n = total - 1;
1468
+ }
1469
+ flush(currentGroup);
1470
+ };
1471
+ qO.d = doc;
1472
+ globalThis.qO = qO;
1473
+ };
1474
+ installOutOfOrderExecutor(document)`;
1194
1475
  function getQwikLoaderScript(opts = {}) {
1195
1476
  return opts.debug ? QWIK_LOADER_DEFAULT_DEBUG : QWIK_LOADER_DEFAULT_MINIFIED;
1196
1477
  }
@@ -1202,6 +1483,13 @@ function getQwikPrefetchWorkerScript(opts = {}) {
1202
1483
  function getQwikBackpatchExecutorScript(opts = {}) {
1203
1484
  return opts.debug ? QWIK_BACKPATCH_EXECUTOR_DEBUG : QWIK_BACKPATCH_EXECUTOR_MINIFIED;
1204
1485
  }
1486
+ function getQwikOutOfOrderExecutorScript(opts = {}) {
1487
+ if (!__EXPERIMENTAL__.suspense) {
1488
+ return "";
1489
+ }
1490
+ const script = opts.debug ? QWIK_OUT_OF_ORDER_EXECUTOR_DEBUG : QWIK_OUT_OF_ORDER_EXECUTOR_MINIFIED;
1491
+ return `if(!globalThis.qO||globalThis.qO.d!==document){${script}}`;
1492
+ }
1205
1493
 
1206
1494
  // packages/qwik/src/server/ssr-node.ts
1207
1495
  import {
@@ -1374,14 +1662,80 @@ var SsrComponentFrame = class {
1374
1662
  hasSlot(slotName) {
1375
1663
  return mapArray_has(this.slots, slotName, 0);
1376
1664
  }
1665
+ claimChildrenForSlot(slotName) {
1666
+ return mapApp_remove(this.slots, slotName, 0);
1667
+ }
1377
1668
  consumeChildrenForSlot(projectionNode, slotName) {
1378
- const children = mapApp_remove(this.slots, slotName, 0);
1669
+ const children = this.claimChildrenForSlot(slotName);
1379
1670
  this.componentNode.setProp(slotName, projectionNode.id);
1380
1671
  projectionNode.setProp(QSlotParent, this.componentNode.id);
1381
1672
  return children;
1382
1673
  }
1383
1674
  };
1384
1675
 
1676
+ // packages/qwik/src/server/ssr-stream-writer.ts
1677
+ var renderSSRChunks = (chunks, remap) => {
1678
+ let out = "";
1679
+ for (let i = 0; i < chunks.length; i++) {
1680
+ const chunk = chunks[i];
1681
+ if (typeof chunk === "string") {
1682
+ out += chunk;
1683
+ } else {
1684
+ const localId = chunk.type === "root-ref" ? chunk.localId : chunk.localPath[0];
1685
+ out += String(remap ? remap[localId] ?? localId : localId);
1686
+ if (chunk.type !== "root-ref-path") {
1687
+ continue;
1688
+ }
1689
+ const path = chunk.localPath;
1690
+ for (let j = 1; j < path.length; j++) {
1691
+ out += " " + path[j];
1692
+ }
1693
+ }
1694
+ }
1695
+ return out;
1696
+ };
1697
+ var StringSSRWriter = class {
1698
+ buffer = [];
1699
+ write(text) {
1700
+ this.buffer.push(text);
1701
+ }
1702
+ writeRootRef(id) {
1703
+ writeStringRootRef(this, id);
1704
+ }
1705
+ writeRootRefPath(path) {
1706
+ writeStringRootRefPath(this, path);
1707
+ }
1708
+ clear() {
1709
+ this.buffer.length = 0;
1710
+ }
1711
+ toString(_) {
1712
+ return this.buffer.join("");
1713
+ }
1714
+ };
1715
+ var StringBufferSegmentWriter = class {
1716
+ chunks = [];
1717
+ write(text) {
1718
+ this.chunks.push(text);
1719
+ }
1720
+ writeRootRef(id) {
1721
+ this.chunks.push({ type: "root-ref", localId: id });
1722
+ }
1723
+ writeRootRefPath(path) {
1724
+ this.chunks.push({ type: "root-ref-path", localPath: path });
1725
+ }
1726
+ clear() {
1727
+ this.chunks.length = 0;
1728
+ }
1729
+ extract() {
1730
+ const chunks = this.chunks;
1731
+ this.chunks = [];
1732
+ return chunks;
1733
+ }
1734
+ toString(remap) {
1735
+ return renderSSRChunks(this.chunks, remap);
1736
+ }
1737
+ };
1738
+
1385
1739
  // packages/qwik/src/server/tag-nesting.ts
1386
1740
  var allowedContent = (state) => {
1387
1741
  switch (state) {
@@ -1724,7 +2078,7 @@ function getBuildBase(opts) {
1724
2078
  return `${import.meta.env?.BASE_URL || "/"}build/`;
1725
2079
  }
1726
2080
  var versions = {
1727
- qwik: "2.0.0-beta.35-dev+4603135",
2081
+ qwik: "2.0.0-beta.37-dev+82dc74d",
1728
2082
  qwikDom: "2.1.19"
1729
2083
  };
1730
2084
 
@@ -1785,7 +2139,7 @@ function vNodeData_createSsrNodeReference(currentComponentNode, vNodeData, depth
1785
2139
  stack[stack.length - 1]++;
1786
2140
  }
1787
2141
  }
1788
- let refId = depthFirstElementIdx + "";
2142
+ let refId = String(depthFirstElementIdx);
1789
2143
  if (vNodeData[0] & (2 /* VIRTUAL_NODE */ | 1 /* TEXT_DATA */)) {
1790
2144
  for (let i = 0; i < stack.length; i++) {
1791
2145
  const childCount = stack[i];
@@ -1824,11 +2178,24 @@ function encodeAsAlphanumeric(value) {
1824
2178
  }
1825
2179
 
1826
2180
  // packages/qwik/src/server/ssr-container.ts
2181
+ var NO_SCRIPT_HERE_ELEMENTS = /* @__PURE__ */ new Set([
2182
+ "script",
2183
+ "style",
2184
+ "textarea",
2185
+ "title",
2186
+ "iframe",
2187
+ "noframes",
2188
+ "noscript",
2189
+ "xmp",
2190
+ "template",
2191
+ "svg",
2192
+ "math"
2193
+ ]);
1827
2194
  function ssrCreateContainer(opts) {
1828
2195
  opts.renderOptions ||= {};
1829
2196
  return new SSRContainer({
1830
2197
  tagName: opts.tagName || "div",
1831
- writer: opts.writer || new StringBufferWriter(),
2198
+ writer: opts.writer || new StringSSRWriter(),
1832
2199
  streamHandler: opts.streamHandler,
1833
2200
  locale: opts.locale || "",
1834
2201
  timing: opts.timing || {
@@ -1847,16 +2214,16 @@ function ssrCreateContainer(opts) {
1847
2214
  renderOptions: opts.renderOptions
1848
2215
  });
1849
2216
  }
1850
- var StringBufferWriter = class {
1851
- buffer = [];
1852
- write(text) {
1853
- this.buffer.push(text);
1854
- }
1855
- toString() {
1856
- return this.buffer.join("");
2217
+ var noopStreamHandler = {
2218
+ flush() {
2219
+ },
2220
+ waitForPendingFlush() {
2221
+ },
2222
+ streamBlockStart() {
2223
+ },
2224
+ streamBlockEnd() {
1857
2225
  }
1858
2226
  };
1859
- var EMPTY_OBJ = {};
1860
2227
  var QTemplateProps = {
1861
2228
  hidden: true,
1862
2229
  "aria-hidden": true
@@ -1871,7 +2238,12 @@ var SSRContainer = class extends _SharedContainer {
1871
2238
  resolvedManifest;
1872
2239
  symbolToChunkResolver;
1873
2240
  renderOptions;
2241
+ outOfOrderStreaming;
1874
2242
  serializationCtx;
2243
+ // Sometimes there is no app state, but framework metadata still points to a vnode id.
2244
+ // For example, an OOOS segment can point outside the segment to a root vnode through
2245
+ // q:sparent, so root vnode data must still be emitted for the client ref table.
2246
+ hasVNodeRefsForSerialization = false;
1875
2247
  /**
1876
2248
  * We use this to append additional nodes in the head node
1877
2249
  *
@@ -1889,6 +2261,7 @@ var SSRContainer = class extends _SharedContainer {
1889
2261
  currentComponentNode = null;
1890
2262
  styleIds = /* @__PURE__ */ new Set();
1891
2263
  isBackpatchExecutorEmitted = false;
2264
+ isOutOfOrderExecutorEmitted = false;
1892
2265
  backpatchMap = /* @__PURE__ */ new Map();
1893
2266
  currentElementFrame = null;
1894
2267
  renderTimer;
@@ -1900,6 +2273,7 @@ var SSRContainer = class extends _SharedContainer {
1900
2273
  */
1901
2274
  depthFirstElementCount = -1;
1902
2275
  vNodeDatas = [];
2276
+ vNodeDataOffset = 0;
1903
2277
  componentStack = [];
1904
2278
  cleanupQueue = [];
1905
2279
  emitContainerDataFrame = null;
@@ -1908,8 +2282,22 @@ var SSRContainer = class extends _SharedContainer {
1908
2282
  $noMoreRoots$ = false;
1909
2283
  qlInclude;
1910
2284
  promiseAttributes = null;
2285
+ vnodeSegment = null;
2286
+ $containerState$ = 0 /* NotReady */;
2287
+ // OOOS related fields
2288
+ outOfOrderId = 0;
2289
+ outOfOrderUsed = false;
2290
+ outOfOrderPendingSegments = [];
2291
+ outOfOrderSegments = [];
2292
+ rootContainerReadyPromise = null;
2293
+ resolveRootContainerReady = null;
2294
+ renderQueue = Promise.resolve();
2295
+ emittedQwikEventNames = /* @__PURE__ */ new Set();
2296
+ emittedSyncFnCount = 0;
2297
+ rootContainerSerializedRootCount = 0;
2298
+ emittedVNodeDataOwners = null;
1911
2299
  constructor(opts) {
1912
- super(opts.renderOptions.serverData ?? EMPTY_OBJ, opts.locale);
2300
+ super(opts.renderOptions.serverData ?? {}, opts.locale);
1913
2301
  this.symbolToChunkResolver = (symbol) => {
1914
2302
  const idx = symbol.lastIndexOf("_");
1915
2303
  const chunk = this.resolvedManifest.mapper[idx == -1 ? symbol : symbol.substring(idx + 1)];
@@ -1930,6 +2318,17 @@ var SSRContainer = class extends _SharedContainer {
1930
2318
  this.$buildBase$ = opts.buildBase;
1931
2319
  this.resolvedManifest = opts.resolvedManifest;
1932
2320
  this.renderOptions = opts.renderOptions;
2321
+ const outOfOrderStreaming = this.renderOptions.streaming?.outOfOrder === true;
2322
+ if (!__EXPERIMENTAL__.suspense) {
2323
+ if (outOfOrderStreaming) {
2324
+ throw new Error(
2325
+ 'Out-of-order Suspense streaming requires `experimental: ["suspense"]` in the `qwikVite` plugin.'
2326
+ );
2327
+ }
2328
+ this.outOfOrderStreaming = false;
2329
+ } else {
2330
+ this.outOfOrderStreaming = outOfOrderStreaming;
2331
+ }
1933
2332
  this.$currentUniqueId$ = 1e5;
1934
2333
  const qlOpt = this.renderOptions.qwikLoader;
1935
2334
  this.qlInclude = qlOpt ? typeof qlOpt === "object" ? qlOpt.include === "never" ? 2 /* Done */ : 0 /* Module */ : qlOpt === "inline" ? 1 /* Inline */ : qlOpt === "never" ? 2 /* Done */ : 0 /* Module */ : 0 /* Module */;
@@ -1967,6 +2366,157 @@ var SSRContainer = class extends _SharedContainer {
1967
2366
  async renderJSX(jsx, options) {
1968
2367
  await _walkJSX(this, jsx, options);
1969
2368
  }
2369
+ $isReadyForOOOS$() {
2370
+ return this.$containerState$ === 2 /* OOOSReady */;
2371
+ }
2372
+ /** Queue OOOS serialization/write work that must not overlap with root state serialization. */
2373
+ $runQueuedRender$(render) {
2374
+ if (!__EXPERIMENTAL__.suspense || !this.outOfOrderStreaming) {
2375
+ return render();
2376
+ }
2377
+ if (this.$containerState$ === 0 /* NotReady */) {
2378
+ return render();
2379
+ }
2380
+ const result = this.$containerState$ === 1 /* DataStreamStarted */ ? this.renderQueue.then(() => this.$waitForRootContainerReady$()).then(render) : this.renderQueue.then(render);
2381
+ this.renderQueue = result.catch(() => {
2382
+ });
2383
+ return result;
2384
+ }
2385
+ $waitForRootContainerReady$() {
2386
+ if (!__EXPERIMENTAL__.suspense || !this.outOfOrderStreaming || this.$isReadyForOOOS$()) {
2387
+ return;
2388
+ }
2389
+ return this.rootContainerReadyPromise ||= new Promise((resolve) => {
2390
+ this.resolveRootContainerReady = resolve;
2391
+ });
2392
+ }
2393
+ $markRootContainerReady$() {
2394
+ if (!__EXPERIMENTAL__.suspense || !this.outOfOrderStreaming || this.$isReadyForOOOS$()) {
2395
+ return;
2396
+ }
2397
+ this.rootContainerSerializedRootCount = this.serializationCtx.$roots$.length;
2398
+ this.$containerState$ = 2 /* OOOSReady */;
2399
+ this.resolveRootContainerReady?.();
2400
+ this.resolveRootContainerReady = null;
2401
+ this.rootContainerReadyPromise = null;
2402
+ }
2403
+ nextOutOfOrderId() {
2404
+ if (!__EXPERIMENTAL__.suspense || !this.outOfOrderStreaming) {
2405
+ return 0;
2406
+ }
2407
+ this.outOfOrderUsed = true;
2408
+ return ++this.outOfOrderId;
2409
+ }
2410
+ emitOutOfOrderSegmentScripts(scripts) {
2411
+ if (!__EXPERIMENTAL__.suspense || !this.outOfOrderStreaming || !scripts) {
2412
+ return;
2413
+ }
2414
+ this.write(scripts);
2415
+ }
2416
+ async segment(segmentId, jsx, options) {
2417
+ if (!__EXPERIMENTAL__.suspense) {
2418
+ throw new Error(
2419
+ 'Out-of-order Suspense streaming requires `experimental: ["suspense"]` in the `qwikVite` plugin.'
2420
+ );
2421
+ }
2422
+ if (!this.outOfOrderStreaming) {
2423
+ throw new Error(
2424
+ "Out-of-order Suspense streaming requires `streaming.outOfOrder` to be `true`."
2425
+ );
2426
+ }
2427
+ this.markVNodeRefForSerialization(options.parentComponentFrame?.componentNode);
2428
+ const writer = new StringBufferSegmentWriter();
2429
+ const segmentContainer = this.createSegmentContainer(segmentId, writer);
2430
+ this.outOfOrderSegments.push(segmentContainer);
2431
+ try {
2432
+ await segmentContainer.renderJSX(jsx, options);
2433
+ await segmentContainer.resolvePromiseAttributes();
2434
+ const htmlChunks = writer.extract();
2435
+ return {
2436
+ container: segmentContainer,
2437
+ writer,
2438
+ htmlChunks
2439
+ };
2440
+ } catch (error) {
2441
+ this.removeOutOfOrderSegment(segmentContainer);
2442
+ throw error;
2443
+ }
2444
+ }
2445
+ $getRootContainer$() {
2446
+ let rootContainer = this;
2447
+ while (rootContainer instanceof SSRSegmentContainer) {
2448
+ rootContainer = rootContainer.$rootContainer$;
2449
+ }
2450
+ return rootContainer;
2451
+ }
2452
+ createSegmentContainer(segmentId, writer) {
2453
+ const rootContainer = this.$getRootContainer$();
2454
+ const contentHostNode = this.getOrCreateLastNode();
2455
+ this.addRoot(contentHostNode);
2456
+ this.markVNodeRefForSerialization(contentHostNode);
2457
+ const rootFrame = {
2458
+ tagNesting: 10 /* ANYTHING */,
2459
+ parent: null,
2460
+ elementName: "#segment",
2461
+ depthFirstElementIdx: -1,
2462
+ // OOOS inserts this synthetic root under the Suspense content host on the client.
2463
+ vNodeData: [16 /* SERIALIZE */],
2464
+ currentFile: null,
2465
+ refBase: contentHostNode.id
2466
+ };
2467
+ const segmentContainer = new SSRSegmentContainer(
2468
+ {
2469
+ tagName: this.tag,
2470
+ writer,
2471
+ streamHandler: noopStreamHandler,
2472
+ locale: this.$locale$,
2473
+ timing: this.timing,
2474
+ buildBase: this.$buildBase$ || "/build/",
2475
+ resolvedManifest: this.resolvedManifest,
2476
+ renderOptions: this.renderOptions
2477
+ },
2478
+ rootContainer
2479
+ );
2480
+ const innerSegmentContainer = segmentContainer;
2481
+ innerSegmentContainer.$isOutOfOrderSegment$ = true;
2482
+ innerSegmentContainer.$storeProxyMap$ = this.$storeProxyMap$;
2483
+ segmentContainer.serializationCtx = segmentContainer.serializationCtxFactory(
2484
+ SsrNode,
2485
+ DomRef,
2486
+ this.symbolToChunkResolver,
2487
+ writer
2488
+ );
2489
+ segmentContainer.serializationCtx.$addSyncFn$ = this.serializationCtx.$addSyncFn$.bind(
2490
+ this.serializationCtx
2491
+ );
2492
+ segmentContainer.currentElementFrame = rootFrame;
2493
+ segmentContainer.currentComponentNode = this.currentComponentNode;
2494
+ segmentContainer.depthFirstElementCount = 0;
2495
+ segmentContainer.vNodeDatas = [rootFrame.vNodeData];
2496
+ segmentContainer.componentStack = this.componentStack.slice();
2497
+ segmentContainer.vnodeSegment = segmentId;
2498
+ segmentContainer.styleIds = this.styleIds;
2499
+ segmentContainer.emittedQwikEventNames = this.emittedQwikEventNames;
2500
+ segmentContainer.qlInclude = 2 /* Done */;
2501
+ segmentContainer.$instanceHash$ = this.$instanceHash$;
2502
+ innerSegmentContainer._didAddQwikLoader = true;
2503
+ return segmentContainer;
2504
+ }
2505
+ queueOutOfOrderSegment(segment) {
2506
+ if (!__EXPERIMENTAL__.suspense || !this.outOfOrderStreaming) {
2507
+ return;
2508
+ }
2509
+ this.outOfOrderPendingSegments.push(segment);
2510
+ }
2511
+ removeOutOfOrderSegment(segment) {
2512
+ const segments = this.outOfOrderSegments;
2513
+ for (let i = 0; i < segments.length; i++) {
2514
+ if (segments[i] === segment) {
2515
+ segments.splice(i, 1);
2516
+ return;
2517
+ }
2518
+ }
2519
+ }
1970
2520
  setContext(host, context, value) {
1971
2521
  const ssrNode = host;
1972
2522
  let ctx = ssrNode.getProp(QCtxAttr);
@@ -2031,7 +2581,7 @@ var SSRContainer = class extends _SharedContainer {
2031
2581
  /** Renders opening tag for DOM element */
2032
2582
  openElement(elementName, key, varAttrs, constAttrs = null, styleScopedId = null, currentFile = null, hasMovedCaptures = true) {
2033
2583
  const isQwikStyle = isQwikStyleElement(elementName, varAttrs) || isQwikStyleElement(elementName, constAttrs);
2034
- if (elementName === "noscript" || elementName === "template" || elementName === "script") {
2584
+ if (NO_SCRIPT_HERE_ELEMENTS.has(elementName)) {
2035
2585
  this.$noScriptHere$++;
2036
2586
  }
2037
2587
  if (
@@ -2129,7 +2679,7 @@ var SSRContainer = class extends _SharedContainer {
2129
2679
  this.write(GT);
2130
2680
  }
2131
2681
  this.lastNode = null;
2132
- if (elementName === "noscript" || elementName === "template" || elementName === "script") {
2682
+ if (NO_SCRIPT_HERE_ELEMENTS.has(elementName)) {
2133
2683
  this.$noScriptHere$--;
2134
2684
  }
2135
2685
  }
@@ -2151,7 +2701,13 @@ var SSRContainer = class extends _SharedContainer {
2151
2701
  this.openFragment(attrs);
2152
2702
  const componentFrame = this.getComponentFrame();
2153
2703
  if (componentFrame) {
2154
- this.serializationCtx.$addRoot$(componentFrame.componentNode);
2704
+ const projectionNode = this.getOrCreateLastNode();
2705
+ this.markVNodeRefForSerialization(projectionNode);
2706
+ if (!this.vnodeSegment) {
2707
+ this.addRoot(componentFrame.componentNode);
2708
+ } else {
2709
+ this.markVNodeRefForSerialization(componentFrame.componentNode);
2710
+ }
2155
2711
  componentFrame.projectionDepth++;
2156
2712
  }
2157
2713
  }
@@ -2200,13 +2756,18 @@ var SSRContainer = class extends _SharedContainer {
2200
2756
  for (let i = 0; i < componentFrame.slots.length; i += 2) {
2201
2757
  const slotName = componentFrame.slots[i];
2202
2758
  const children = componentFrame.slots[i + 1];
2759
+ if (this.vnodeSegment) {
2760
+ this.markVNodeRefForSerialization(componentFrame.componentNode);
2761
+ }
2203
2762
  this.openFragment(
2204
- isDev8 ? { [DEBUG_TYPE]: "P" /* Projection */, [QSlotParent]: componentFrame.componentNode.id } : { [QSlotParent]: componentFrame.componentNode.id }
2763
+ isDev8 ? {
2764
+ [DEBUG_TYPE]: "P" /* Projection */,
2765
+ [QSlotParent]: componentFrame.componentNode.id,
2766
+ [QSlot]: slotName
2767
+ } : { [QSlotParent]: componentFrame.componentNode.id, [QSlot]: slotName }
2205
2768
  );
2206
2769
  const lastNode = this.getOrCreateLastNode();
2207
- if (lastNode.vnodeData) {
2208
- lastNode.vnodeData[0] |= 16 /* SERIALIZE */;
2209
- }
2770
+ lastNode.vnodeData[0] |= 16 /* SERIALIZE */;
2210
2771
  componentFrame.componentNode.setProp(slotName, lastNode.id);
2211
2772
  await this.renderJSX(children, {
2212
2773
  currentStyleScoped: scopedStyleId,
@@ -2230,19 +2791,22 @@ var SSRContainer = class extends _SharedContainer {
2230
2791
  }
2231
2792
  addRoot(obj) {
2232
2793
  if (this.$noMoreRoots$) {
2233
- return this.serializationCtx.$hasRootId$(obj);
2794
+ const rootId = this.serializationCtx.$hasRootId$(obj);
2795
+ return rootId;
2234
2796
  }
2235
2797
  return this.serializationCtx.$addRoot$(obj);
2236
2798
  }
2237
2799
  getOrCreateLastNode() {
2238
2800
  if (!this.lastNode) {
2801
+ const currentFrame = this.currentElementFrame;
2802
+ const elementIndex = currentFrame.depthFirstElementIdx + 1;
2803
+ const refBase = currentFrame.refBase ?? (this.vnodeSegment ? getSegmentVNodeRefId(this.vnodeSegment, elementIndex) : elementIndex + this.vNodeDataOffset);
2239
2804
  this.lastNode = vNodeData_createSsrNodeReference(
2240
2805
  this.currentComponentNode,
2241
- this.currentElementFrame.vNodeData,
2242
- // we start at -1, so we need to add +1
2243
- this.currentElementFrame.depthFirstElementIdx + 1,
2806
+ currentFrame.vNodeData,
2807
+ refBase,
2244
2808
  this.cleanupQueue,
2245
- this.currentElementFrame.currentFile
2809
+ currentFrame.currentFile
2246
2810
  );
2247
2811
  }
2248
2812
  return this.lastNode;
@@ -2297,23 +2861,66 @@ var SSRContainer = class extends _SharedContainer {
2297
2861
  this.write(content);
2298
2862
  this.closeElement();
2299
2863
  }
2864
+ $deferRootPlaceholder$(scriptNode) {
2865
+ if (this.isHtml && this.currentElementFrame?.elementName === "html") {
2866
+ this.additionalHeadNodes.push(scriptNode);
2867
+ return true;
2868
+ }
2869
+ return false;
2870
+ }
2300
2871
  ////////////////////////////////////
2301
2872
  emitContainerData() {
2873
+ const isStreamingDisabled = this.renderOptions.streaming?.inOrder?.strategy === "disabled";
2874
+ const shouldFlushShell = !isStreamingDisabled || __EXPERIMENTAL__.suspense && this.outOfOrderStreaming && this.outOfOrderUsed;
2302
2875
  return maybeThen(
2303
- this.resolvePromiseAttributes(),
2304
- () => maybeThen(this.emitStateData(), () => {
2305
- this.$noMoreRoots$ = true;
2306
- this.emitVNodeData();
2307
- if (!isDev8) {
2308
- preloaderPost(this, this.renderOptions, this.$serverData$?.nonce);
2309
- }
2310
- this.emitSyncFnsData();
2311
- this.emitPatchDataIfNeeded();
2312
- this.emitExecutorIfNeeded();
2313
- this.emitQwikLoaderAtBottomIfNeeded();
2314
- })
2876
+ maybeThen(
2877
+ shouldFlushShell ? this.streamHandler.flush() : void 0,
2878
+ () => this.resolvePromiseAttributes()
2879
+ ),
2880
+ () => {
2881
+ this.$containerState$ = 1 /* DataStreamStarted */;
2882
+ return maybeThen(this.emitStateData(), () => {
2883
+ this.$noMoreRoots$ = true;
2884
+ return maybeThen(this.emitRestStateData(), () => this.emitOutOfOrderSegmentsAndData());
2885
+ });
2886
+ }
2315
2887
  );
2316
2888
  }
2889
+ emitRestStateData() {
2890
+ this.emitVNodeData();
2891
+ this.emitDelayedOutOfOrderSegmentVNodeData();
2892
+ if (!isDev8) {
2893
+ preloaderPost(this, this.renderOptions, this.$serverData$?.nonce);
2894
+ }
2895
+ this.emitSyncFnsData();
2896
+ this.emitPatchDataIfNeeded();
2897
+ this.emitExecutorIfNeeded();
2898
+ this.emitQwikLoaderAtBottomIfNeeded();
2899
+ }
2900
+ emitDelayedOutOfOrderSegmentVNodeData() {
2901
+ if (!__EXPERIMENTAL__.suspense || !this.outOfOrderStreaming || !this.outOfOrderUsed) {
2902
+ return;
2903
+ }
2904
+ for (let i = 0; i < this.outOfOrderSegments.length; i++) {
2905
+ const segment = this.outOfOrderSegments[i];
2906
+ if (segment.$outOfOrderState$ === 1 /* EarlyFinalized */) {
2907
+ segment.$emitDelayedOutOfOrderVNodeData$();
2908
+ i--;
2909
+ }
2910
+ }
2911
+ }
2912
+ emitOutOfOrderSegmentsAndData() {
2913
+ if (!__EXPERIMENTAL__.suspense || !this.outOfOrderStreaming || !this.outOfOrderUsed) {
2914
+ return;
2915
+ }
2916
+ this.emitOutOfOrderExecutorIfNeeded();
2917
+ return maybeThen(this.streamHandler.flush(), async () => {
2918
+ this.$markRootContainerReady$();
2919
+ if (this.outOfOrderPendingSegments.length) {
2920
+ await Promise.all(this.outOfOrderPendingSegments);
2921
+ }
2922
+ });
2923
+ }
2317
2924
  /**
2318
2925
  * Serialize the vNodeData into a string and emit it as a script tag.
2319
2926
  *
@@ -2332,16 +2939,25 @@ var SSRContainer = class extends _SharedContainer {
2332
2939
  * NOTE: Not every element will need vNodeData. So we need to encode how many elements should be
2333
2940
  * skipped. By choosing different separators we can encode different numbers of elements to skip.
2334
2941
  */
2335
- emitVNodeData() {
2336
- if (!this.serializationCtx.$roots$.length) {
2942
+ emitVNodeData(segmentId) {
2943
+ this.$getRootContainer$().markVNodeDataOwnerEmitted(segmentId);
2944
+ if (!segmentId && !this.serializationCtx.$roots$.length && !this.hasVNodeRefsForSerialization) {
2337
2945
  return;
2338
2946
  }
2339
- this.openElement("script", null, { type: "qwik/vnode" });
2947
+ this.emitVNodeDataScript(segmentId, this.vNodeDatas.entries());
2948
+ }
2949
+ emitVNodeDataScript(segmentId, entries, patch = false) {
2950
+ const attrs = { type: "qwik/vnode" };
2951
+ if (__EXPERIMENTAL__.suspense && this.outOfOrderStreaming && segmentId) {
2952
+ attrs[QSuspenseResolved] = segmentId;
2953
+ }
2954
+ if (patch) {
2955
+ attrs[QStatePatchAttr] = true;
2956
+ }
2957
+ this.openScript(attrs);
2340
2958
  const vNodeAttrsStack = [];
2341
- const vNodeData = this.vNodeDatas;
2342
2959
  let lastSerializedIdx = 0;
2343
- for (let elementIdx = 0; elementIdx < vNodeData.length; elementIdx++) {
2344
- const vNode = vNodeData[elementIdx];
2960
+ for (const [elementIdx, vNode] of entries) {
2345
2961
  const flag = vNode[0];
2346
2962
  if (flag & 16 /* SERIALIZE */) {
2347
2963
  lastSerializedIdx = this.emitVNodeSeparators(lastSerializedIdx, elementIdx);
@@ -2391,14 +3007,51 @@ var SSRContainer = class extends _SharedContainer {
2391
3007
  }
2392
3008
  }
2393
3009
  }
2394
- this.closeElement();
3010
+ this.closeScript();
3011
+ if (patch && !segmentId) {
3012
+ this.emitInlineScript(
3013
+ "document.qProcessVNodeDataPatch&&document.qProcessVNodeDataPatch(document.currentScript.previousElementSibling)"
3014
+ );
3015
+ }
3016
+ }
3017
+ markVNodeRefForSerialization(node) {
3018
+ if (node) {
3019
+ this.hasVNodeRefsForSerialization = true;
3020
+ node.vnodeData[0] |= 16 /* SERIALIZE */ | 8 /* REFERENCE */;
3021
+ }
3022
+ }
3023
+ markVNodeDataOwnerEmitted(segmentId) {
3024
+ if (!__EXPERIMENTAL__.suspense || !this.outOfOrderStreaming) {
3025
+ return;
3026
+ }
3027
+ (this.emittedVNodeDataOwners ||= /* @__PURE__ */ new Set()).add(segmentId);
3028
+ }
3029
+ isVNodeDataOwnerEmitted(owner) {
3030
+ return this.emittedVNodeDataOwners?.has(owner) === true;
3031
+ }
3032
+ getVNodeDataOwnerFromNodeId(id) {
3033
+ const refBase = parseInt(id, 10);
3034
+ if (refBase >= 0) {
3035
+ return { owner: void 0, localIndex: refBase };
3036
+ }
3037
+ const pair = -refBase - 1;
3038
+ const diagonal = Math.floor((Math.sqrt(8 * pair + 1) - 1) / 2);
3039
+ const diagonalStart = diagonal * (diagonal + 1) / 2;
3040
+ const localIndex = pair - diagonalStart;
3041
+ const segmentIndex = diagonal - localIndex;
3042
+ return { owner: String(segmentIndex + 1), localIndex };
2395
3043
  }
2396
3044
  writeFragmentAttrs(fragmentAttrs) {
2397
3045
  for (const key in fragmentAttrs) {
2398
- let value = fragmentAttrs[key];
2399
- let encodeValue = false;
2400
- if (typeof value !== "string") {
2401
- const rootId = this.addRoot(value);
3046
+ const rawValue = fragmentAttrs[key];
3047
+ let value = rawValue;
3048
+ let rootId;
3049
+ let encodeValue = null;
3050
+ if (key === ELEMENT_ID && typeof rawValue === "number") {
3051
+ rootId = rawValue;
3052
+ value = String(rawValue);
3053
+ } else if (typeof rawValue !== "string") {
3054
+ rootId = this.addRoot(rawValue);
2402
3055
  if (rootId === void 0) {
2403
3056
  continue;
2404
3057
  }
@@ -2418,7 +3071,7 @@ var SSRContainer = class extends _SharedContainer {
2418
3071
  this.write(VNodeDataChar.PROPS_CHAR);
2419
3072
  break;
2420
3073
  case ELEMENT_KEY:
2421
- encodeValue = true;
3074
+ encodeValue = encodeVNodeDataKey;
2422
3075
  this.write(VNodeDataChar.KEY_CHAR);
2423
3076
  break;
2424
3077
  case ELEMENT_SEQ:
@@ -2441,18 +3094,20 @@ var SSRContainer = class extends _SharedContainer {
2441
3094
  this.write(VNodeDataChar.SLOT_CHAR);
2442
3095
  break;
2443
3096
  default: {
2444
- encodeValue = true;
3097
+ encodeValue = encodeURI;
2445
3098
  this.write(VNodeDataChar.SEPARATOR_CHAR);
2446
3099
  this.write(encodeVNodeDataString(key));
2447
3100
  this.write(VNodeDataChar.SEPARATOR_CHAR);
2448
3101
  }
2449
3102
  }
2450
- const encodedValue = encodeVNodeDataString(encodeValue ? encodeURI(value) : value);
3103
+ const encodedValue = encodeVNodeDataString(encodeValue ? encodeValue(value) : value);
2451
3104
  const isEncoded = encodeValue ? encodedValue !== value : false;
2452
3105
  if (isEncoded) {
2453
3106
  this.write(VNodeDataChar.SEPARATOR_CHAR);
2454
3107
  this.write(encodedValue);
2455
3108
  this.write(VNodeDataChar.SEPARATOR_CHAR);
3109
+ } else if (typeof rootId === "number") {
3110
+ this.writeRootRef(rootId);
2456
3111
  } else {
2457
3112
  this.write(value);
2458
3113
  }
@@ -2463,33 +3118,48 @@ var SSRContainer = class extends _SharedContainer {
2463
3118
  return;
2464
3119
  }
2465
3120
  const attrs = this.stateScriptAttrs();
2466
- this.openElement("script", null, attrs);
3121
+ this.openScript(attrs);
3122
+ this.serializationCtx.$setWriter$(this.writer);
2467
3123
  return maybeThen(this.serializationCtx.$serialize$(), () => {
2468
- this.closeElement();
3124
+ this.closeScript();
2469
3125
  });
2470
3126
  }
2471
3127
  /** Add q-d:qidle attribute to eagerly resume some state if needed */
2472
3128
  stateScriptAttrs() {
2473
- const attrs = { type: "qwik/state" };
3129
+ const attrs = { type: "qwik/state", [QInstanceAttr]: this.$instanceHash$ };
2474
3130
  const eagerResume = this.serializationCtx.$eagerResume$;
2475
3131
  if (eagerResume.size > 0) {
2476
3132
  attrs["q-d:qidle"] = createQRL(null, "_res", _res, null, [...eagerResume]);
2477
3133
  }
2478
3134
  return attrs;
2479
3135
  }
2480
- emitSyncFnsData() {
3136
+ emitSyncFnsData(append = false) {
2481
3137
  const fns = this.serializationCtx.$syncFns$;
2482
- if (fns.length) {
3138
+ const start = append ? this.emittedSyncFnCount : 0;
3139
+ if (fns.length > start) {
2483
3140
  const scriptAttrs = { "q:func": "qwik/json" };
2484
3141
  if (this.renderOptions.serverData?.nonce) {
2485
3142
  scriptAttrs["nonce"] = this.renderOptions.serverData.nonce;
2486
3143
  }
2487
- this.openElement("script", null, scriptAttrs);
2488
- this.write(Q_FUNCS_PREFIX.replace("HASH", this.$instanceHash$));
2489
- this.write(BRACKET_OPEN);
2490
- this.writeArray(fns, COMMA);
2491
- this.write(BRACKET_CLOSE);
2492
- this.closeElement();
3144
+ this.openScript(scriptAttrs);
3145
+ if (append) {
3146
+ const qFuncsExpr = Q_FUNCS_PREFIX.replace("HASH", this.$instanceHash$).slice(0, -1);
3147
+ this.write(`(${qFuncsExpr}||(${qFuncsExpr}=[])).push(`);
3148
+ } else {
3149
+ this.write(Q_FUNCS_PREFIX.replace("HASH", this.$instanceHash$));
3150
+ }
3151
+ if (!append) {
3152
+ this.write(BRACKET_OPEN);
3153
+ }
3154
+ this.writeArray(append ? fns.slice(start) : fns, COMMA);
3155
+ if (!append) {
3156
+ this.write(BRACKET_CLOSE);
3157
+ }
3158
+ if (append) {
3159
+ this.write(")");
3160
+ }
3161
+ this.closeScript();
3162
+ this.emittedSyncFnCount = fns.length;
2493
3163
  }
2494
3164
  }
2495
3165
  emitPatchDataIfNeeded() {
@@ -2511,23 +3181,59 @@ var SSRContainer = class extends _SharedContainer {
2511
3181
  if (this.renderOptions.serverData?.nonce) {
2512
3182
  scriptAttrs["nonce"] = this.renderOptions.serverData.nonce;
2513
3183
  }
2514
- this.openElement("script", null, scriptAttrs);
2515
- this.write(JSON.stringify(patches));
2516
- this.closeElement();
3184
+ this.writeScript(scriptAttrs, JSON.stringify(patches));
2517
3185
  }
2518
3186
  }
3187
+ emitBackpatchDataAndExecutorIfNeeded() {
3188
+ if (this.backpatchMap.size === 0) {
3189
+ return;
3190
+ }
3191
+ this.emitPatchDataIfNeeded();
3192
+ this.emitExecutorIfNeeded();
3193
+ }
2519
3194
  emitExecutorIfNeeded() {
2520
3195
  if (!this.isBackpatchExecutorEmitted) {
2521
3196
  return;
2522
3197
  }
3198
+ this.isBackpatchExecutorEmitted = false;
2523
3199
  const scriptAttrs = { type: "text/javascript" };
2524
3200
  if (this.renderOptions.serverData?.nonce) {
2525
3201
  scriptAttrs["nonce"] = this.renderOptions.serverData.nonce;
2526
3202
  }
2527
- this.openElement("script", null, scriptAttrs);
2528
3203
  const backpatchScript = getQwikBackpatchExecutorScript({ debug: isDev8 });
2529
- this.write(backpatchScript);
2530
- this.closeElement();
3204
+ this.writeScript(scriptAttrs, backpatchScript);
3205
+ }
3206
+ emitOutOfOrderExecutorIfNeeded() {
3207
+ if (!__EXPERIMENTAL__.suspense || !this.outOfOrderStreaming || !this.outOfOrderUsed || this.isOutOfOrderExecutorEmitted) {
3208
+ return;
3209
+ }
3210
+ this.isOutOfOrderExecutorEmitted = true;
3211
+ this.writeScript(
3212
+ { type: "text/javascript", nonce: this.renderOptions.serverData?.nonce },
3213
+ getQwikOutOfOrderExecutorScript({ debug: isDev8 })
3214
+ );
3215
+ }
3216
+ emitInlineScript(script) {
3217
+ const scriptAttrs = { type: "text/javascript" };
3218
+ if (this.renderOptions.serverData?.nonce) {
3219
+ scriptAttrs["nonce"] = this.renderOptions.serverData.nonce;
3220
+ }
3221
+ this.writeScript(scriptAttrs, script);
3222
+ }
3223
+ writeScript(attrs, body) {
3224
+ this.openScript(attrs);
3225
+ if (body) {
3226
+ this.write(body);
3227
+ }
3228
+ this.closeScript();
3229
+ }
3230
+ openScript(attrs) {
3231
+ this.write("<script");
3232
+ this.writeAttrs("script", attrs, true, null, null, true);
3233
+ this.write(GT);
3234
+ }
3235
+ closeScript() {
3236
+ this.write("</script>");
2531
3237
  }
2532
3238
  emitPreloaderPre() {
2533
3239
  if (!isDev8) {
@@ -2535,7 +3241,7 @@ var SSRContainer = class extends _SharedContainer {
2535
3241
  }
2536
3242
  }
2537
3243
  isStatic() {
2538
- return this.serializationCtx.$eventQrls$.size === 0;
3244
+ return !(__EXPERIMENTAL__.suspense && this.outOfOrderStreaming && this.outOfOrderUsed) && this.serializationCtx.$eventQrls$.size === 0;
2539
3245
  }
2540
3246
  emitQwikLoaderAtTopIfNeeded() {
2541
3247
  if (this.qlInclude === 0 /* Module */) {
@@ -2556,8 +3262,7 @@ var SSRContainer = class extends _SharedContainer {
2556
3262
  if (nonce) {
2557
3263
  scriptAttrs["nonce"] = nonce;
2558
3264
  }
2559
- this.openElement("script", null, scriptAttrs);
2560
- this.closeElement();
3265
+ this.writeScript(scriptAttrs);
2561
3266
  }
2562
3267
  }
2563
3268
  emitQwikLoaderInline() {
@@ -2571,30 +3276,41 @@ var SSRContainer = class extends _SharedContainer {
2571
3276
  if (this.renderOptions.serverData?.nonce) {
2572
3277
  scriptAttrs["nonce"] = this.renderOptions.serverData.nonce;
2573
3278
  }
2574
- this.openElement("script", null, scriptAttrs);
2575
- this.write(qwikLoaderScript);
2576
- this.closeElement();
3279
+ this.writeScript(scriptAttrs, qwikLoaderScript);
2577
3280
  }
2578
3281
  emitQwikLoaderAtBottomIfNeeded() {
2579
3282
  if (!this.isStatic()) {
2580
3283
  if (this.qlInclude !== 2 /* Done */) {
2581
3284
  this.emitQwikLoaderInline();
2582
3285
  }
2583
- this.emitQwikEvents(Array.from(this.serializationCtx.$eventNames$, (s) => JSON.stringify(s)));
3286
+ this.emitNewQwikEvents(true);
3287
+ }
3288
+ }
3289
+ emitNewQwikEvents(includeContainerReady = false) {
3290
+ const qwikEventItems = [];
3291
+ for (const eventName of this.serializationCtx.$eventNames$) {
3292
+ if (!this.emittedQwikEventNames.has(eventName)) {
3293
+ this.emittedQwikEventNames.add(eventName);
3294
+ qwikEventItems.push(JSON.stringify(eventName));
3295
+ }
3296
+ }
3297
+ if (includeContainerReady) {
3298
+ qwikEventItems.push(`${QwikEvContainerReady}`, JSON.stringify(this.$instanceHash$));
2584
3299
  }
3300
+ this.emitQwikEvents(qwikEventItems);
2585
3301
  }
2586
- emitQwikEvents(eventNames) {
2587
- if (eventNames.length > 0) {
3302
+ emitQwikEvents(qwikEventItems) {
3303
+ if (qwikEventItems.length > 0) {
2588
3304
  const scriptAttrs = {};
2589
3305
  const nonce = this.renderOptions.serverData?.nonce;
2590
3306
  if (nonce) {
2591
3307
  scriptAttrs["nonce"] = nonce;
2592
3308
  }
2593
- this.openElement("script", null, scriptAttrs);
3309
+ this.openScript(scriptAttrs);
2594
3310
  this.write(`(window._qwikEv||(window._qwikEv=[])).push(`);
2595
- this.writeArray(eventNames, COMMA);
3311
+ this.writeArray(qwikEventItems, COMMA);
2596
3312
  this.write(PAREN_CLOSE);
2597
- this.closeElement();
3313
+ this.closeScript();
2598
3314
  }
2599
3315
  }
2600
3316
  // Keep in sync with process-vnode-data.unit.ts
@@ -2662,7 +3378,7 @@ var SSRContainer = class extends _SharedContainer {
2662
3378
  text.push(
2663
3379
  `${indent}<${elementName}> <= is not allowed as a child of ${allowedContent(previousTagNesting)[0]}.`
2664
3380
  );
2665
- throw newTagError(text.map(escapeHTML).join("\n"));
3381
+ throw newTagError(text.join("\n"));
2666
3382
  }
2667
3383
  }
2668
3384
  }
@@ -2672,7 +3388,8 @@ var SSRContainer = class extends _SharedContainer {
2672
3388
  elementName,
2673
3389
  depthFirstElementIdx,
2674
3390
  vNodeData: [0 /* NONE */],
2675
- currentFile: isDev8 ? currentFile || null : null
3391
+ currentFile: isDev8 ? currentFile || null : null,
3392
+ refBase: null
2676
3393
  };
2677
3394
  this.currentElementFrame = frame;
2678
3395
  this.vNodeDatas.push(frame.vNodeData);
@@ -2687,6 +3404,17 @@ var SSRContainer = class extends _SharedContainer {
2687
3404
  this.size += text.length;
2688
3405
  this.writer.write(text);
2689
3406
  }
3407
+ writeRootRef(id) {
3408
+ this.size += String(id).length;
3409
+ this.writer.writeRootRef(id);
3410
+ }
3411
+ writeRootRefPath(path) {
3412
+ this.size += String(path[0]).length;
3413
+ this.writer.writeRootRefPath(path);
3414
+ for (let i = 1; i < path.length; i++) {
3415
+ this.size += 1 + String(path[i]).length;
3416
+ }
3417
+ }
2690
3418
  writeArray(array, separator) {
2691
3419
  for (let i = 0; i < array.length; i++) {
2692
3420
  const element = array[i];
@@ -2722,7 +3450,11 @@ var SSRContainer = class extends _SharedContainer {
2722
3450
  throw qError(15 /* invalidRefValue */, [currentFile]);
2723
3451
  }
2724
3452
  } else if (key === ITERATION_ITEM_SINGLE || key === ITERATION_ITEM_MULTI) {
2725
- value = this.serializationCtx.$addRoot$(value);
3453
+ const rootId = this.addRoot(value);
3454
+ if (rootId === void 0) {
3455
+ continue;
3456
+ }
3457
+ value = typeof rootId === "number" ? [rootId] : String(rootId);
2726
3458
  } else if (isSignal(value)) {
2727
3459
  const lastNode = this.getOrCreateLastNode();
2728
3460
  const signalData = new SubscriptionData({
@@ -2738,7 +3470,11 @@ var SSRContainer = class extends _SharedContainer {
2738
3470
  const lastNode = this.getOrCreateLastNode();
2739
3471
  this.addPromiseAttribute(value);
2740
3472
  value.then((resolvedValue) => {
2741
- this.addBackpatchEntry(lastNode.id, key, resolvedValue);
3473
+ this.addBackpatchEntry(
3474
+ lastNode.id,
3475
+ key,
3476
+ serializeAttribute(key, resolvedValue, styleScopedId)
3477
+ );
2742
3478
  });
2743
3479
  continue;
2744
3480
  }
@@ -2771,14 +3507,30 @@ var SSRContainer = class extends _SharedContainer {
2771
3507
  this.write(key);
2772
3508
  if (serializedValue !== true) {
2773
3509
  this.write(ATTR_EQUALS_QUOTE);
2774
- const strValue = escapeHTML(String(serializedValue));
2775
- this.write(strValue);
3510
+ if (Array.isArray(serializedValue)) {
3511
+ this.writeEscapedChunks(serializedValue);
3512
+ } else {
3513
+ const strValue = escapeHTML(String(serializedValue));
3514
+ this.write(strValue);
3515
+ }
2776
3516
  this.write(QUOTE);
2777
3517
  }
2778
3518
  }
2779
3519
  }
2780
3520
  return innerHTML;
2781
3521
  }
3522
+ writeEscapedChunks(chunks) {
3523
+ for (let i = 0; i < chunks.length; i++) {
3524
+ const chunk = chunks[i];
3525
+ if (typeof chunk === "string") {
3526
+ this.write(escapeHTML(chunk));
3527
+ } else if (typeof chunk === "number") {
3528
+ this.writeRootRef(chunk);
3529
+ } else {
3530
+ this.writeRootRefPath(chunk.path);
3531
+ }
3532
+ }
3533
+ }
2782
3534
  addPromiseAttribute(promise) {
2783
3535
  this.promiseAttributes ||= [];
2784
3536
  this.promiseAttributes.push(promise);
@@ -2790,6 +3542,277 @@ var SSRContainer = class extends _SharedContainer {
2790
3542
  }
2791
3543
  }
2792
3544
  };
3545
+ var SSRSegmentContainer = class extends SSRContainer {
3546
+ constructor(opts, $rootContainer$) {
3547
+ super(opts);
3548
+ this.$rootContainer$ = $rootContainer$;
3549
+ }
3550
+ $outOfOrderState$ = 0 /* Rendering */;
3551
+ $outOfOrderRootIdMap$ = null;
3552
+ subscriptionPatchRecords = [];
3553
+ pendingVNodeDataPatches = null;
3554
+ nextOutOfOrderId() {
3555
+ return this.$rootContainer$.nextOutOfOrderId();
3556
+ }
3557
+ $runQueuedRender$(render) {
3558
+ return this.$rootContainer$.$runQueuedRender$(render);
3559
+ }
3560
+ queueOutOfOrderSegment(segment) {
3561
+ this.$rootContainer$.queueOutOfOrderSegment(segment);
3562
+ }
3563
+ emitOutOfOrderSegmentScripts(scripts) {
3564
+ this.$rootContainer$.emitOutOfOrderSegmentScripts(scripts);
3565
+ }
3566
+ emitOutOfOrderExecutorIfNeeded() {
3567
+ this.$rootContainer$.emitOutOfOrderExecutorIfNeeded();
3568
+ }
3569
+ $recordExternalRootEffect$(producer, effect, prop, sourceEffects) {
3570
+ recordExternalRootEffect(
3571
+ this.$rootContainer$.serializationCtx,
3572
+ this.serializationCtx,
3573
+ this.$rootContainer$.$storeProxyMap$,
3574
+ this.subscriptionPatchRecords,
3575
+ producer,
3576
+ effect,
3577
+ prop,
3578
+ sourceEffects
3579
+ );
3580
+ }
3581
+ async $finalizeOutOfOrderSegment$(segmentId, segment) {
3582
+ const rootContainer = this.$rootContainer$;
3583
+ const rootReadyAtSegment = rootContainer.$isReadyForOOOS$();
3584
+ const segmentSerializationCtx = this.serializationCtx;
3585
+ try {
3586
+ const commit = this.$commitRoots$(rootContainer, segmentSerializationCtx);
3587
+ this.$mergeSegmentEventData$(rootContainer, segmentSerializationCtx);
3588
+ this.$mergeSegmentSyncFns$(rootContainer, segmentSerializationCtx);
3589
+ const subscriptionPatchRootId = this.$addSubscriptionsToRoots$(
3590
+ rootContainer,
3591
+ rootReadyAtSegment,
3592
+ segmentSerializationCtx
3593
+ );
3594
+ if (rootReadyAtSegment && (commit.newRootLocalIds.length > 0 || subscriptionPatchRootId !== void 0)) {
3595
+ segmentSerializationCtx.$forwardRefOffset$ = rootContainer.serializationCtx.$serializedForwardRefCount$;
3596
+ await this.emitStatePatchData(
3597
+ segmentId,
3598
+ commit.newRootStart,
3599
+ commit.newRootLocalIds,
3600
+ subscriptionPatchRootId
3601
+ );
3602
+ rootContainer.serializationCtx.$serializedRootCount$ = rootContainer.serializationCtx.$roots$.length + (rootContainer.serializationCtx.$hasRootStateForwardRefs$ ? 1 : 0);
3603
+ rootContainer.serializationCtx.$serializedForwardRefCount$ += segmentSerializationCtx.$serializedForwardRefCount$;
3604
+ }
3605
+ this.emitPendingVNodeDataPatches();
3606
+ if (rootReadyAtSegment) {
3607
+ this.$noMoreRoots$ = true;
3608
+ this.emitVNodeData(segmentId);
3609
+ const segmentCtx = this.serializationCtx;
3610
+ this.serializationCtx = rootContainer.serializationCtx;
3611
+ this.emittedSyncFnCount = rootContainer.emittedSyncFnCount;
3612
+ this.emitSyncFnsData(true);
3613
+ rootContainer.emittedSyncFnCount = this.emittedSyncFnCount;
3614
+ this.serializationCtx = segmentCtx;
3615
+ this.emitNewQwikEvents();
3616
+ }
3617
+ this.emitPatchDataIfNeeded();
3618
+ this.drainCleanupQueue();
3619
+ const rootIdMap = commit.rootIdMap;
3620
+ if (rootReadyAtSegment) {
3621
+ this.$outOfOrderState$ = 2 /* Done */;
3622
+ } else {
3623
+ this.$outOfOrderRootIdMap$ = rootIdMap;
3624
+ this.$outOfOrderState$ = 1 /* EarlyFinalized */;
3625
+ }
3626
+ return {
3627
+ html: renderSSRChunks(segment.htmlChunks, rootIdMap),
3628
+ scripts: segment.writer.toString(rootIdMap)
3629
+ };
3630
+ } finally {
3631
+ if (this.$outOfOrderState$ !== 1 /* EarlyFinalized */) {
3632
+ segmentSerializationCtx.$onAddRoot$ = void 0;
3633
+ rootContainer.removeOutOfOrderSegment(this);
3634
+ }
3635
+ rootContainer.serializationCtx.$setWriter$(rootContainer.writer);
3636
+ }
3637
+ }
3638
+ $emitDelayedOutOfOrderVNodeData$() {
3639
+ try {
3640
+ this.emitVNodeData(this.vnodeSegment);
3641
+ this.emitPendingVNodeDataPatches();
3642
+ this.$rootContainer$.emitOutOfOrderSegmentScripts(
3643
+ this.writer.toString(this.$outOfOrderRootIdMap$)
3644
+ );
3645
+ this.$outOfOrderState$ = 2 /* Done */;
3646
+ this.$rootContainer$.removeOutOfOrderSegment(this);
3647
+ } finally {
3648
+ this.serializationCtx.$onAddRoot$ = void 0;
3649
+ }
3650
+ }
3651
+ markVNodeDataForSerialization(node, flags = 16 /* SERIALIZE */) {
3652
+ const previousFlags = node.vnodeData[0];
3653
+ const nextFlags = previousFlags | flags;
3654
+ if (nextFlags !== previousFlags) {
3655
+ node.vnodeData[0] = nextFlags;
3656
+ this.queueLateVNodeDataPatch(node, nextFlags & ~previousFlags);
3657
+ }
3658
+ }
3659
+ queueLateVNodeDataPatch(node, addedFlags) {
3660
+ if (!__EXPERIMENTAL__.suspense || !this.outOfOrderStreaming || !(addedFlags & (16 /* SERIALIZE */ | 8 /* REFERENCE */))) {
3661
+ return;
3662
+ }
3663
+ const owner = this.getVNodeDataOwnerFromNodeId(node.id);
3664
+ if (!this.$getRootContainer$().isVNodeDataOwnerEmitted(owner.owner)) {
3665
+ return;
3666
+ }
3667
+ let ownerPatches = (this.pendingVNodeDataPatches ||= /* @__PURE__ */ new Map()).get(owner.owner);
3668
+ if (!ownerPatches) {
3669
+ this.pendingVNodeDataPatches.set(owner.owner, ownerPatches = /* @__PURE__ */ new Map());
3670
+ }
3671
+ ownerPatches.set(owner.localIndex, node.vnodeData);
3672
+ }
3673
+ emitPendingVNodeDataPatches() {
3674
+ const pendingPatches = this.pendingVNodeDataPatches;
3675
+ this.pendingVNodeDataPatches = null;
3676
+ if (!pendingPatches) {
3677
+ return;
3678
+ }
3679
+ for (const [owner, entries] of pendingPatches) {
3680
+ if (entries.size === 0) {
3681
+ continue;
3682
+ }
3683
+ const sortedEntries = Array.from(entries).sort((a, b) => a[0] - b[0]);
3684
+ this.emitVNodeDataScript(owner, sortedEntries, true);
3685
+ }
3686
+ }
3687
+ $commitRoots$(rootContainer, segmentSerializationCtx) {
3688
+ const commit = this.commitSegmentRoots(rootContainer, segmentSerializationCtx);
3689
+ segmentSerializationCtx.$onAddRoot$ = (localId, root, obj) => {
3690
+ this.commitSegmentRoot(rootContainer, localId, root, obj, commit);
3691
+ };
3692
+ return commit;
3693
+ }
3694
+ $addSubscriptionsToRoots$(rootContainer, rootReadyAtSegment, segmentSerializationCtx) {
3695
+ let subscriptionPatchRootId = void 0;
3696
+ const subscriptionPatches = rootReadyAtSegment ? this.collectSubscriptionPatches(
3697
+ rootContainer,
3698
+ rootContainer.rootContainerSerializedRootCount
3699
+ ) : void 0;
3700
+ if (subscriptionPatches) {
3701
+ subscriptionPatchRootId = segmentSerializationCtx.$addRoot$(subscriptionPatches);
3702
+ }
3703
+ return subscriptionPatchRootId;
3704
+ }
3705
+ commitSegmentRoots(rootContainer, segmentSerializationCtx) {
3706
+ const rootIdMap = [];
3707
+ const newRootStart = rootContainer.$isReadyForOOOS$() ? rootContainer.serializationCtx.$serializedRootCount$ : rootContainer.serializationCtx.$roots$.length;
3708
+ const newRootLocalIds = [];
3709
+ const commit = {
3710
+ rootIdMap,
3711
+ newRootStart,
3712
+ newRootLocalIds
3713
+ };
3714
+ this.promoteSharedSegmentRoots(rootContainer, segmentSerializationCtx, commit);
3715
+ const segmentRoots = segmentSerializationCtx.$roots$;
3716
+ const segmentRootObjs = segmentSerializationCtx.$rootObjs$;
3717
+ for (let i = 0; i < segmentRoots.length; i++) {
3718
+ const rootObj = segmentRootObjs[i];
3719
+ this.commitSegmentRoot(rootContainer, i, segmentRoots[i], rootObj, commit);
3720
+ }
3721
+ return commit;
3722
+ }
3723
+ promoteSharedSegmentRoots(rootContainer, segmentSerializationCtx, commit) {
3724
+ const segmentRoots = segmentSerializationCtx.$roots$;
3725
+ const segmentRootObjs = segmentSerializationCtx.$rootObjs$;
3726
+ for (let i = 0; i < segmentRootObjs.length; i++) {
3727
+ const rootObj = segmentRootObjs[i];
3728
+ if (this.isRootOrUsedByOtherLiveSegment(rootContainer, rootObj)) {
3729
+ this.commitSegmentRoot(rootContainer, i, segmentRoots[i], rootObj, commit);
3730
+ }
3731
+ }
3732
+ }
3733
+ isRootOrUsedByOtherLiveSegment(rootContainer, obj) {
3734
+ if (rootContainer.serializationCtx.$hasRootId$(obj) !== void 0) {
3735
+ return true;
3736
+ }
3737
+ const segments = rootContainer.outOfOrderSegments;
3738
+ for (let i = 0; i < segments.length; i++) {
3739
+ const segment = segments[i];
3740
+ if (segment === this) {
3741
+ continue;
3742
+ }
3743
+ const rootObjs = segment.serializationCtx.$rootObjs$;
3744
+ for (let j = 0; j < rootObjs.length; j++) {
3745
+ if (rootObjs[j] === obj) {
3746
+ return true;
3747
+ }
3748
+ }
3749
+ }
3750
+ return false;
3751
+ }
3752
+ commitSegmentRoot(rootContainer, localId, root, rootObj, commit) {
3753
+ if (commit.rootIdMap[localId] !== void 0) {
3754
+ return;
3755
+ }
3756
+ let rootId = rootContainer.serializationCtx.$hasRootId$(rootObj);
3757
+ if (rootId === void 0) {
3758
+ rootId = rootContainer.serializationCtx.$commitRoot$(root, rootObj);
3759
+ commit.newRootLocalIds.push(localId);
3760
+ this.seedCommittedRootForLiveSegments(rootContainer, rootObj);
3761
+ }
3762
+ const rootCtx = rootContainer.serializationCtx;
3763
+ commit.rootIdMap[localId] = rootContainer.$isReadyForOOOS$() && rootId >= rootCtx.$rootStateRootCount$ ? rootId + (rootCtx.$hasRootStateForwardRefs$ ? 1 : 0) : rootId;
3764
+ }
3765
+ seedCommittedRootForLiveSegments(rootContainer, rootObj) {
3766
+ const segments = rootContainer.outOfOrderSegments;
3767
+ for (let i = 0; i < segments.length; i++) {
3768
+ const segment = segments[i];
3769
+ if (segment !== this && segment.$outOfOrderState$ === 0 /* Rendering */) {
3770
+ segment.serializationCtx.$addRoot$(rootObj);
3771
+ }
3772
+ }
3773
+ }
3774
+ $mergeSegmentEventData$(rootContainer, segmentSerializationCtx) {
3775
+ for (const eventName of segmentSerializationCtx.$eventNames$) {
3776
+ rootContainer.serializationCtx.$eventNames$.add(eventName);
3777
+ }
3778
+ for (const qrl of segmentSerializationCtx.$eventQrls$) {
3779
+ rootContainer.serializationCtx.$eventQrls$.add(qrl);
3780
+ }
3781
+ }
3782
+ $mergeSegmentSyncFns$(rootContainer, segmentSerializationCtx) {
3783
+ rootContainer.serializationCtx.$syncFns$.push(...segmentSerializationCtx.$syncFns$);
3784
+ }
3785
+ collectSubscriptionPatches(rootContainer, rootLimit) {
3786
+ if (!__EXPERIMENTAL__.suspense || !this.outOfOrderStreaming) {
3787
+ return;
3788
+ }
3789
+ return collectSubscriptionPatches(
3790
+ rootContainer.serializationCtx,
3791
+ this.subscriptionPatchRecords,
3792
+ rootLimit
3793
+ );
3794
+ }
3795
+ emitStatePatchData(segmentId, rootStart, rootIds, subscriptionPatchRootId) {
3796
+ const attrs = this.statePatchScriptAttrs(segmentId);
3797
+ this.openScript(attrs);
3798
+ this.serializationCtx.$setWriter$(this.writer);
3799
+ this.serializationCtx.$markSsrNodeForSerialization$ = this.markVNodeDataForSerialization.bind(this);
3800
+ return maybeThen(
3801
+ this.serializationCtx.$serializePatch$(rootStart, rootIds, subscriptionPatchRootId, 0),
3802
+ () => {
3803
+ this.closeScript();
3804
+ }
3805
+ );
3806
+ }
3807
+ statePatchScriptAttrs(segmentId) {
3808
+ const attrs = this.stateScriptAttrs();
3809
+ attrs[QStatePatchAttr] = true;
3810
+ if (segmentId) {
3811
+ attrs[QSuspenseResolved] = segmentId;
3812
+ }
3813
+ return attrs;
3814
+ }
3815
+ };
2793
3816
  var isQwikStyleElement = (tag, attrs) => {
2794
3817
  if (tag === "style" && attrs != null) {
2795
3818
  return Object.prototype.hasOwnProperty.call(attrs, QStyle) || Object.prototype.hasOwnProperty.call(attrs, QScopedStyle);
@@ -2851,58 +3874,43 @@ var StreamHandler = class {
2851
3874
  let stream;
2852
3875
  switch (this.inOrderStreaming.strategy) {
2853
3876
  case "disabled":
2854
- stream = {
2855
- write(chunk) {
2856
- if (chunk === void 0 || chunk === null) {
2857
- return;
2858
- }
2859
- handler.enqueue(chunk);
2860
- },
2861
- waitForDrain() {
2862
- return handler.waitForPendingFlush();
3877
+ stream = createStringStreamWriter((chunk) => {
3878
+ if (chunk === void 0 || chunk === null) {
3879
+ return;
2863
3880
  }
2864
- };
3881
+ handler.enqueue(chunk);
3882
+ });
2865
3883
  break;
2866
3884
  case "direct": {
2867
3885
  const originalStream = this.nativeStream;
2868
- stream = {
2869
- write(chunk) {
2870
- if (chunk === void 0 || chunk === null) {
2871
- return;
2872
- }
2873
- if (handler.pendingFlush) {
2874
- const queued = handler.pendingFlush.then(() => originalStream.write(chunk));
2875
- return handler.trackPendingFlush(queued);
2876
- }
2877
- return handler.trackPendingFlush(originalStream.write(chunk));
2878
- },
2879
- waitForDrain() {
2880
- return handler.waitForPendingFlush();
3886
+ stream = createStringStreamWriter((chunk) => {
3887
+ if (chunk === void 0 || chunk === null) {
3888
+ return;
3889
+ }
3890
+ if (handler.pendingFlush) {
3891
+ const queued = handler.pendingFlush.then(() => originalStream.write(chunk));
3892
+ return handler.trackPendingFlush(queued);
2881
3893
  }
2882
- };
3894
+ return handler.trackPendingFlush(originalStream.write(chunk));
3895
+ });
2883
3896
  break;
2884
3897
  }
2885
3898
  default:
2886
3899
  case "auto": {
2887
3900
  const minimumChunkSize = this.inOrderStreaming.maximumChunk ?? 0;
2888
3901
  const initialChunkSize = this.inOrderStreaming.maximumInitialChunk ?? 0;
2889
- stream = {
2890
- write(chunk) {
2891
- if (chunk === void 0 || chunk === null) {
2892
- return;
2893
- }
2894
- handler.enqueue(chunk);
2895
- if (handler.streamBlockDepth === 0) {
2896
- const maxBufferSize = handler.networkFlushes === 0 ? initialChunkSize : minimumChunkSize;
2897
- if (handler.bufferSize >= maxBufferSize) {
2898
- return handler.flush();
2899
- }
3902
+ stream = createStringStreamWriter((chunk) => {
3903
+ if (chunk === void 0 || chunk === null) {
3904
+ return;
3905
+ }
3906
+ handler.enqueue(chunk);
3907
+ if (handler.streamBlockDepth === 0) {
3908
+ const maxBufferSize = handler.networkFlushes === 0 ? initialChunkSize : minimumChunkSize;
3909
+ if (handler.bufferSize >= maxBufferSize) {
3910
+ return handler.flush();
2900
3911
  }
2901
- },
2902
- waitForDrain() {
2903
- return handler.waitForPendingFlush();
2904
3912
  }
2905
- };
3913
+ });
2906
3914
  break;
2907
3915
  }
2908
3916
  }
@@ -2982,22 +3990,26 @@ var StreamHandler = class {
2982
3990
 
2983
3991
  // packages/qwik/src/server/ssr-render.ts
2984
3992
  var renderToString = async (jsx, opts = {}) => {
2985
- const chunks = [];
2986
- const stream = {
2987
- write(chunk) {
2988
- chunks.push(chunk);
2989
- }
2990
- };
3993
+ const stream = new StringSSRWriter();
2991
3994
  const result = await renderToStream(jsx, { ...opts, stream });
2992
3995
  return {
2993
3996
  isStatic: result.isStatic,
2994
3997
  timing: result.timing,
2995
3998
  manifest: result.manifest,
2996
3999
  snapshotResult: result.snapshotResult,
2997
- html: chunks.join("")
4000
+ html: stream.toString()
2998
4001
  };
2999
4002
  };
3000
4003
  var renderToStream = async (jsx, opts) => {
4004
+ if (__EXPERIMENTAL__.suspense && opts.streaming?.outOfOrder === void 0) {
4005
+ opts = {
4006
+ ...opts,
4007
+ streaming: {
4008
+ ...opts.streaming,
4009
+ outOfOrder: true
4010
+ }
4011
+ };
4012
+ }
3001
4013
  const timing = {
3002
4014
  firstFlush: 0,
3003
4015
  render: 0,