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

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.36-dev+3268fab
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]";
@@ -607,15 +645,13 @@ var ELEMENT_PROPS = "q:props";
607
645
  var ELEMENT_SEQ = "q:seq";
608
646
  var ELEMENT_SEQ_IDX = "q:seqIdx";
609
647
  var ELEMENT_BACKPATCH_DATA = "qwik/backpatch";
610
- var Q_PREFIX = "q:";
611
648
  var ITERATION_ITEM_SINGLE = "q:p";
612
649
  var ITERATION_ITEM_MULTI = "q:ps";
613
650
  var NON_SERIALIZABLE_MARKER_PREFIX = ":";
614
651
  var USE_ON_LOCAL = NON_SERIALIZABLE_MARKER_PREFIX + "on";
615
652
  var USE_ON_LOCAL_SEQ_IDX = NON_SERIALIZABLE_MARKER_PREFIX + "onIdx";
616
653
  var USE_ON_LOCAL_FLAGS = NON_SERIALIZABLE_MARKER_PREFIX + "onFlags";
617
- var QCursorBoundary = Q_PREFIX + "cursorBoundary";
618
- var QNearestCursorBoundary = NON_SERIALIZABLE_MARKER_PREFIX + "nearestCursorBoundary";
654
+ var NEAREST_CURSOR_BOUNDARY = NON_SERIALIZABLE_MARKER_PREFIX + "nearestCursorBoundary";
619
655
  var Q_PROPS_SEPARATOR = ":";
620
656
  var dangerouslySetInnerHTML = "dangerouslySetInnerHTML";
621
657
 
@@ -878,6 +914,26 @@ var isObjectEmpty = (obj) => {
878
914
  return true;
879
915
  };
880
916
 
917
+ // packages/qwik/src/core/ssr/stream-writer.ts
918
+ var stringifyRootRefPath = (path) => {
919
+ let text = String(path[0]);
920
+ for (let i = 1; i < path.length; i++) {
921
+ text += " " + path[i];
922
+ }
923
+ return text;
924
+ };
925
+ var writeStringRootRef = (writer, id) => writer.write(String(id));
926
+ var writeStringRootRefPath = (writer, path) => writer.write(stringifyRootRefPath(path));
927
+ var createStringStreamWriter = (write) => ({
928
+ write,
929
+ writeRootRef(id) {
930
+ return writeStringRootRef(this, id);
931
+ },
932
+ writeRootRefPath(path) {
933
+ return writeStringRootRefPath(this, path);
934
+ }
935
+ });
936
+
881
937
  // packages/qwik/src/core/shared/ssr-const.ts
882
938
  var LT = "<";
883
939
  var GT = ">";
@@ -978,6 +1034,69 @@ import {
978
1034
  isSignal
979
1035
  } from "@qwik.dev/core/internal";
980
1036
 
1037
+ // packages/qwik/src/server/ooos-utils.ts
1038
+ import { _SubscriptionPatch as SubscriptionPatch } from "@qwik.dev/core/internal";
1039
+ var recordExternalRootEffect = (rootCtx, segmentCtx, storeProxyMap, records, producer, effect, prop, sourceEffects) => {
1040
+ if (!records || prop !== null && !sourceEffects) {
1041
+ return;
1042
+ }
1043
+ let rootObj = producer;
1044
+ if (prop !== null && producer && (typeof producer === "object" || typeof producer === "function")) {
1045
+ rootObj = storeProxyMap.get(producer) || producer;
1046
+ }
1047
+ const rootId = rootCtx.$hasRootId$(rootObj);
1048
+ segmentCtx.$addRoot$(rootObj);
1049
+ segmentCtx.$addRoot$(effect);
1050
+ if (prop !== null && typeof prop !== "string") {
1051
+ segmentCtx.$addRoot$(prop);
1052
+ }
1053
+ records.push({
1054
+ rootObj,
1055
+ rootId,
1056
+ effect,
1057
+ prop
1058
+ });
1059
+ };
1060
+ var collectSubscriptionPatches = (rootCtx, records, rootLimit) => {
1061
+ if (!records?.length) {
1062
+ return;
1063
+ }
1064
+ const patches = [];
1065
+ const patchesByRoot = /* @__PURE__ */ new Map();
1066
+ for (let i = 0; i < records.length; i++) {
1067
+ const entry = records[i];
1068
+ const rootId = entry.rootId === void 0 ? rootCtx.$hasRootId$(entry.rootObj) : entry.rootId;
1069
+ if (rootId === void 0 || rootId >= rootLimit) {
1070
+ continue;
1071
+ }
1072
+ let patch = patchesByRoot.get(rootId);
1073
+ if (!patch) {
1074
+ patch = new SubscriptionPatch(
1075
+ rootId,
1076
+ entry.prop === null ? /* @__PURE__ */ new Set() : /* @__PURE__ */ new Map()
1077
+ );
1078
+ patchesByRoot.set(rootId, patch);
1079
+ patches.push(patch);
1080
+ }
1081
+ const subscriptions = patch.subscriptions;
1082
+ if (entry.prop === null) {
1083
+ if (subscriptions instanceof Set) {
1084
+ subscriptions.add(entry.effect);
1085
+ }
1086
+ } else {
1087
+ if (subscriptions instanceof Map) {
1088
+ let effects = subscriptions.get(entry.prop);
1089
+ if (!effects) {
1090
+ effects = /* @__PURE__ */ new Set();
1091
+ subscriptions.set(entry.prop, effects);
1092
+ }
1093
+ effects.add(entry.effect);
1094
+ }
1095
+ }
1096
+ }
1097
+ return patches.length ? patches : void 0;
1098
+ };
1099
+
981
1100
  // packages/qwik/src/server/preload-impl.ts
982
1101
  import { getPlatform } from "@qwik.dev/core";
983
1102
  var simplifyPath = (base2, path) => {
@@ -1048,9 +1167,7 @@ var preloaderPre = (container, options, nonce) => {
1048
1167
  if (nonce) {
1049
1168
  scriptAttrs["nonce"] = nonce;
1050
1169
  }
1051
- container.openElement("script", null, scriptAttrs, null, null, null);
1052
- container.write(script);
1053
- container.closeElement();
1170
+ container.writeScript(scriptAttrs, script);
1054
1171
  }
1055
1172
  const corePath = simplifyPath(base2, resolvedManifest?.manifest.core);
1056
1173
  if (corePath) {
@@ -1105,9 +1222,7 @@ var includePreloader = (container, options, referencedBundles, nonce) => {
1105
1222
  if (nonce) {
1106
1223
  attrs["nonce"] = nonce;
1107
1224
  }
1108
- container.openElement("script", null, attrs, null, null, null);
1109
- container.write(script);
1110
- container.closeElement();
1225
+ container.writeScript(attrs, script);
1111
1226
  }
1112
1227
  return null;
1113
1228
  };
@@ -1143,14 +1258,15 @@ var preLoaderOptionsDefault = {
1143
1258
  };
1144
1259
 
1145
1260
  // 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)}`;
1261
+ var QWIK_LOADER_DEFAULT_MINIFIED = 'const e=document,t=window,n="w",r="wp",o="d",s="dp",i="e",c="ep",a="capture:",l="readystatechange",p="qready",u=new Set,q=new Set([e]),d=new Map;let h,f,b;const g=(e,t)=>Array.from(e.querySelectorAll(t)),m=e=>{const t=[];return q.forEach(n=>t.push(...g(n,e))),t},v=(e,t,n,r=!1,o=!1)=>e.addEventListener(t,n,{capture:r,passive:o}),y=e=>{z(e);const t=g(e,"[q\\\\:shadowroot]");for(let e=0;e<t.length;e++){const n=t[e].shadowRoot;n&&y(n)}},w=e=>e&&"function"==typeof e.then,E=async e=>{for(let t=0;t<e.length;t++)await e[t]()},A=e=>{if(e.length){const t=()=>E(e);b=b?b.then(t,t):t()}},C=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}}},_=t=>{const n=t.getAttribute("q:instance");return"paused"===t.getAttribute("q:container")&&"loading"===e.readyState&&!e[p]?.[n]&&new Promise(t=>{const r=o=>{o.detail===n&&(e.removeEventListener(p,r),t())};v(e,l,t),v(e,p,r)})},k=(e,t)=>new CustomEvent(e,{detail:t}),S=(t,n)=>{e.dispatchEvent(k(t,n))},$=e=>e.replace(/([A-Z-])/g,e=>"-"+e.toLowerCase()),I=e=>e.replace(/-./g,e=>e[1].toUpperCase()),L=e=>{const t=e.indexOf(":");return{scope:e.slice(0,t),eventName:I(e.slice(t+1))}},N=e=>2===e.length,R=e=>e.charAt(0),T=e=>!!e&&1===e.nodeType,x=(e,t,n)=>e.hasAttribute(n)&&(!!e._qDispatch?.[t]||e.hasAttribute("q-"+t)),B=(t,n,r,o,s,i,c,a=!0)=>{const l={qBase:r,symbol:i,element:n,reqTime:c};if(!s){const n=(e["qFuncs_"+t.getAttribute("q:instance")]||[])[+i];if(!n&&a){const e=Error("sym:"+i);S("qerror",{importError:"sync",error:e,...l}),console.error(e)}return n}const p=`${i}|${r}|${s}`,u=d.get(p);if(u)return u;const q=new URL(s,o).href,h=import(q);return C(t),h.then(e=>{const t=e[i];if(t)d.set(p,t),S("qsymbol",l);else{const e=Error(`${i} not in ${q}`);S("qerror",{importError:"no-symbol",error:e,...l}),console.error(e)}return t},e=>{S("qerror",{importError:"async",error:e,...l}),console.error(e)})},U=(t,n,r,o,s,i=!0)=>{let c=!1;s&&(i&&t.hasAttribute("preventdefault:"+s)&&n.preventDefault(),t.hasAttribute("stoppropagation:"+s)&&n.stopPropagation());const a=t._qDispatch?.[r];if(a){if("function"==typeof a){const e=()=>a(n,t);if(c)o.push(async()=>{const t=e();w(t)&&await t});else{const t=e();w(t)&&(c=!0,o.push(()=>t))}}else if(a.length)for(let e=0;e<a.length;e++){const r=a[e];if(r){const e=()=>r(n,t);if(c)o.push(async()=>{const t=e();w(t)&&await t});else{const t=e();w(t)&&(c=!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),a=l.split("|"),p=_(r);for(let e=0;e<a.length;e++){const l=a[e],u=performance.now(),[q,d,h]=l.split("#"),f=e=>{if(e&&t.isConnected){const o=n=>{const o=_(r);if(o)return o.then(()=>f(e));S("qerror",{error:n,qBase:s,symbol:d,element:t,reqTime:u})};try{const r=e.call(h,n,t);if(w(r))return r.catch(o)}catch(e){return o(e)}}},b=(e=!0)=>B(r,t,s,i,q,d,u,e),g=p&&!q?b(!1):b();if(w(g))c=!0,o.push(()=>g.then(f));else if(c||p&&!q&&!g)c=!0,o.push(async()=>{let e=g;!e&&p&&(await p,e=b(!1)),await f(e||await b())});else{const e=f(g);w(e)&&(c=!0,o.push(()=>e))}}}},j=(e,t=i,n=!0)=>{const r=$(e.type),o=t+":"+r,s=a+r,c=[],l=[],p=[];let u=e.target;for(;u;)T(u)?(c.push(u),l.push(x(u,o,s)),u=u.parentElement):u=u.parentElement;for(let t=c.length-1;t>=0;t--)if(l[t]&&(U(c[t],e,o,p,r,n),e.cancelBubble))return void A(p);for(let t=0;t<c.length;t++)if(!l[t]&&(U(c[t],e,o,p,r,n),!e.bubbles||e.cancelBubble))return void A(p);A(p)},D=e=>j(e,c,!1),O=(e,t,n=!0)=>{const r=$(t.type),o=e+":"+r,s=m("[q-"+e+"\\\\:"+r+"]"),i=[];for(let e=0;e<s.length;e++){const c=s[e];U(c,t,o,i,r,n)}A(i)},P=e=>{O(o,e)},F=e=>{O(s,e,!1)},J=e=>{O(n,e)},M=e=>{O(r,e,!1)},Z=()=>{const n=e.readyState;if("interactive"==n||"complete"==n){if(f=1,q.forEach(y),u.has("d:qinit")){u.delete("d:qinit");const e=k("qinit"),t=m("[q-d\\\\:qinit]"),n=[];for(let r=0;r<t.length;r++){const o=t[r];U(o,e,"d:qinit",n),o.removeAttribute("q-d:qinit")}A(n)}if(u.has("d:qidle")&&(u.delete("d:qidle"),(t.requestIdleCallback??t.setTimeout).bind(t)(()=>{const e=k("qidle"),t=m("[q-d\\\\:qidle]"),n=[];for(let r=0;r<t.length;r++){const o=t[r];U(o,e,"d:qidle",n),o.removeAttribute("q-d:qidle")}A(n)})),u.has("e:qvisible")){h||(h=new IntersectionObserver(e=>{const t=[];for(let n=0;n<e.length;n++){const r=e[n];r.isIntersecting&&(h.unobserve(r.target),U(r.target,k("qvisible",r),"e:qvisible",t))}A(t)}));const e=m("[q-e\\\\:qvisible]:not([q\\\\:observed])");for(let t=0;t<e.length;t++){const n=e[t];h.observe(n),n.setAttribute("q:observed","true")}}}},z=(...e)=>{for(let r=0;r<e.length;r++){const s=e[r];if("string"==typeof s){if(!u.has(s)){u.add(s);const{scope:e,eventName:r}=L(s),i=N(e),c=R(e);c===n?v(t,r,i?M:J,!0,i):q.forEach(e=>v(e,r,c===o?i?F:P:i?D:j,!0,i)),1!==f||"e:qvisible"!==s&&"d:qinit"!==s&&"d:qidle"!==s||Z()}}else q.has(s)||(u.forEach(e=>{const{scope:t,eventName:r}=L(e),i=N(t),c=R(t);c!==n&&v(s,r,c===o?i?F:P:i?D:j,!0,i)}),q.add(s))}},G=t._qwikEv;G?.roots||(Array.isArray(G)?z(...G):z("e:click","e:input"),t._qwikEv={events:u,roots:q,push:z},v(e,l,Z),Z())';
1262
+ 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 containerReady = "qready";\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 waitForContainerReady = (container) => {\n const hash = container.getAttribute("q:instance");\n return container.getAttribute("q:container") === "paused" && doc.readyState === "loading" && !doc[containerReady]?.[hash] && new Promise((resolve) => {\n const ready = (ev) => {\n if (ev.detail === hash) {\n doc.removeEventListener(containerReady, ready);\n resolve();\n }\n };\n addEventListener(doc, readyStateChange, resolve);\n addEventListener(doc, containerReady, 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 const retry = waitForContainerReady(container);\n if (retry) {\n return retry.then(() => run(handler2));\n }\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 && !chunk ? resolve(false) : resolve();\n if (isPromise(handler)) {\n defer = true;\n tasks.push(() => handler.then(run));\n } else if (defer || waitForReady && !chunk && !handler) {\n defer = true;\n tasks.push(async () => {\n let retryHandler = handler;\n if (!retryHandler && waitForReady) {\n await waitForReady;\n retryHandler = resolve(false);\n }\n await run(retryHandler || 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 (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}';
1263
+ 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
1264
  var QWIK_BACKPATCH_EXECUTOR_DEBUG = `const BACKPATCH_DATA_SELECTOR = 'script[type="qwik/backpatch"]';
1150
1265
  function executeBackpatch(doc, containerElement) {
1151
1266
  const container = containerElement || doc.querySelector("[q\\\\:container]:not([q\\\\:container=html]):not([q\\\\:container=text])");
1152
1267
  if (container) {
1153
- const script = container.querySelector(BACKPATCH_DATA_SELECTOR);
1268
+ const scripts = container.querySelectorAll(BACKPATCH_DATA_SELECTOR);
1269
+ const script = scripts[scripts.length - 1];
1154
1270
  if (script) {
1155
1271
  const data = JSON.parse(script.textContent || "[]");
1156
1272
  const walker = doc.createTreeWalker(container, NodeFilter.SHOW_ELEMENT);
@@ -1191,6 +1307,170 @@ if (executorScript) {
1191
1307
  executeBackpatch(document, container);
1192
1308
  }
1193
1309
  }`;
1310
+ 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)`;
1311
+ var QWIK_OUT_OF_ORDER_EXECUTOR_DEBUG = `const Q_RESOLVED_SELECTOR = 'template[q\\\\:r="';
1312
+ const Q_RESOLVED_ATTR = "q:r";
1313
+ const Q_RESULT_PARENT_SELECTOR = '[q\\\\:rp="';
1314
+ const Q_GROUP_ATTR = "q:g";
1315
+ const Q_INDEX_ATTR = "q:i";
1316
+ const Q_ORDER_ATTR = "q:o";
1317
+ const Q_CONTAINER_SELECTOR = "[q\\\\:container]:not([q\\\\:container=html]):not([q\\\\:container=text])";
1318
+ const installOutOfOrderExecutor = (doc) => {
1319
+ const groups = /* @__PURE__ */ new WeakMap();
1320
+ const process = (boundaryId, content) => {
1321
+ var _a;
1322
+ const executorDoc = doc;
1323
+ (_a = executorDoc.qProcessOOOS) == null ? void 0 : _a.call(executorDoc, boundaryId, content);
1324
+ };
1325
+ const getScope = () => {
1326
+ const script = doc.currentScript;
1327
+ return script ? script.closest(Q_CONTAINER_SELECTOR) || doc : doc;
1328
+ };
1329
+ const group = (scope, groupId, total, order) => {
1330
+ let scopedGroups = groups.get(scope);
1331
+ if (!scopedGroups) {
1332
+ groups.set(scope, scopedGroups = {});
1333
+ }
1334
+ return scopedGroups[groupId] || (scopedGroups[groupId] = {
1335
+ r: {},
1336
+ n: 0,
1337
+ t: total,
1338
+ o: order
1339
+ });
1340
+ };
1341
+ const getResolvedTemplate = (scope, boundaryId) => {
1342
+ const currentScript = doc.currentScript;
1343
+ const previousElement = currentScript ? currentScript.previousElementSibling : null;
1344
+ if (previousElement && previousElement.localName === "template" && previousElement.getAttribute(Q_RESOLVED_ATTR) === String(boundaryId)) {
1345
+ return previousElement;
1346
+ }
1347
+ const templates = scope.querySelectorAll(Q_RESOLVED_SELECTOR + boundaryId + '"]');
1348
+ return templates.length ? templates[templates.length - 1] : null;
1349
+ };
1350
+ const getPlaceholderTemplate = (content, boundaryId) => {
1351
+ return content.querySelector(Q_RESOLVED_SELECTOR + boundaryId + '"]');
1352
+ };
1353
+ const getResultParent = (scope, boundaryId) => {
1354
+ return scope.querySelector(Q_RESULT_PARENT_SELECTOR + boundaryId + '"]');
1355
+ };
1356
+ const reveal = (content, fallback) => {
1357
+ if (!content) {
1358
+ return 0;
1359
+ }
1360
+ if (fallback && fallback.style) {
1361
+ fallback.style.display = "none";
1362
+ }
1363
+ if (content.style) {
1364
+ content.style.display = "contents";
1365
+ }
1366
+ return 1;
1367
+ };
1368
+ const move = (scope, boundaryId, resolved) => {
1369
+ if (!resolved) {
1370
+ return null;
1371
+ }
1372
+ const content = getResultParent(scope, boundaryId);
1373
+ const placeholder = content ? getPlaceholderTemplate(content, boundaryId) : null;
1374
+ const parent = placeholder ? placeholder.parentNode : null;
1375
+ if (!placeholder || !content || !parent) {
1376
+ return null;
1377
+ }
1378
+ parent.insertBefore(resolved.content, placeholder);
1379
+ placeholder.remove();
1380
+ resolved.remove();
1381
+ return [content, content.previousElementSibling];
1382
+ };
1383
+ const flush = (group2) => {
1384
+ const order = group2.o;
1385
+ let entry;
1386
+ let index;
1387
+ let swapped = 0;
1388
+ if (order === "p") {
1389
+ for (const key in group2.r) {
1390
+ entry = group2.r[key];
1391
+ if (entry[0] && reveal(entry[0], entry[1])) {
1392
+ entry[0] = 0;
1393
+ swapped++;
1394
+ }
1395
+ }
1396
+ } else if (order === "s") {
1397
+ for (index = group2.n; (entry = group2.r[index]) && entry[0]; index++) {
1398
+ if (!reveal(entry[0], entry[1])) {
1399
+ break;
1400
+ }
1401
+ entry[0] = 0;
1402
+ swapped++;
1403
+ group2.n = index + 1;
1404
+ }
1405
+ } else if (order === "r") {
1406
+ if (group2.t < 0) {
1407
+ return 0;
1408
+ }
1409
+ if (group2.n < 0) {
1410
+ group2.n = group2.t - 1;
1411
+ }
1412
+ for (index = group2.n; (entry = group2.r[index]) && entry[0]; index--) {
1413
+ if (!reveal(entry[0], entry[1])) {
1414
+ break;
1415
+ }
1416
+ entry[0] = 0;
1417
+ swapped++;
1418
+ group2.n = index - 1;
1419
+ }
1420
+ } else {
1421
+ if (group2.t < 0) {
1422
+ return 0;
1423
+ }
1424
+ for (index = 0; index < group2.t; index++) {
1425
+ entry = group2.r[index];
1426
+ if (!entry) {
1427
+ return 0;
1428
+ }
1429
+ }
1430
+ for (index = 0; index < group2.t; index++) {
1431
+ entry = group2.r[index];
1432
+ if (entry[0] && reveal(entry[0], entry[1])) {
1433
+ entry[0] = 0;
1434
+ swapped++;
1435
+ }
1436
+ }
1437
+ }
1438
+ return swapped;
1439
+ };
1440
+ const qO = ((boundaryId) => {
1441
+ const scope = getScope();
1442
+ const resolved = getResolvedTemplate(scope, boundaryId);
1443
+ if (!resolved) {
1444
+ return;
1445
+ }
1446
+ const entry = move(scope, boundaryId, resolved);
1447
+ if (!entry) {
1448
+ return;
1449
+ }
1450
+ process(boundaryId, entry[0] || null);
1451
+ const groupId = resolved.getAttribute(Q_GROUP_ATTR);
1452
+ if (groupId) {
1453
+ const index = +(resolved.getAttribute(Q_INDEX_ATTR) || 0);
1454
+ const currentGroup = group(scope, groupId, -1, resolved.getAttribute(Q_ORDER_ATTR) || "p");
1455
+ currentGroup.r[index] = entry;
1456
+ flush(currentGroup);
1457
+ return;
1458
+ }
1459
+ reveal(entry[0] || null, entry[1]);
1460
+ });
1461
+ qO.g = (groupId, total, order) => {
1462
+ const currentGroup = group(getScope(), groupId, total, order);
1463
+ currentGroup.t = total;
1464
+ currentGroup.o = order;
1465
+ if (currentGroup.o === "r" && currentGroup.n === 0) {
1466
+ currentGroup.n = total - 1;
1467
+ }
1468
+ flush(currentGroup);
1469
+ };
1470
+ qO.d = doc;
1471
+ globalThis.qO = qO;
1472
+ };
1473
+ installOutOfOrderExecutor(document)`;
1194
1474
  function getQwikLoaderScript(opts = {}) {
1195
1475
  return opts.debug ? QWIK_LOADER_DEFAULT_DEBUG : QWIK_LOADER_DEFAULT_MINIFIED;
1196
1476
  }
@@ -1202,6 +1482,13 @@ function getQwikPrefetchWorkerScript(opts = {}) {
1202
1482
  function getQwikBackpatchExecutorScript(opts = {}) {
1203
1483
  return opts.debug ? QWIK_BACKPATCH_EXECUTOR_DEBUG : QWIK_BACKPATCH_EXECUTOR_MINIFIED;
1204
1484
  }
1485
+ function getQwikOutOfOrderExecutorScript(opts = {}) {
1486
+ if (!__EXPERIMENTAL__.suspense) {
1487
+ return "";
1488
+ }
1489
+ const script = opts.debug ? QWIK_OUT_OF_ORDER_EXECUTOR_DEBUG : QWIK_OUT_OF_ORDER_EXECUTOR_MINIFIED;
1490
+ return `if(!globalThis.qO||globalThis.qO.d!==document){${script}}`;
1491
+ }
1205
1492
 
1206
1493
  // packages/qwik/src/server/ssr-node.ts
1207
1494
  import {
@@ -1374,14 +1661,80 @@ var SsrComponentFrame = class {
1374
1661
  hasSlot(slotName) {
1375
1662
  return mapArray_has(this.slots, slotName, 0);
1376
1663
  }
1664
+ claimChildrenForSlot(slotName) {
1665
+ return mapApp_remove(this.slots, slotName, 0);
1666
+ }
1377
1667
  consumeChildrenForSlot(projectionNode, slotName) {
1378
- const children = mapApp_remove(this.slots, slotName, 0);
1668
+ const children = this.claimChildrenForSlot(slotName);
1379
1669
  this.componentNode.setProp(slotName, projectionNode.id);
1380
1670
  projectionNode.setProp(QSlotParent, this.componentNode.id);
1381
1671
  return children;
1382
1672
  }
1383
1673
  };
1384
1674
 
1675
+ // packages/qwik/src/server/ssr-stream-writer.ts
1676
+ var renderSSRChunks = (chunks, remap) => {
1677
+ let out = "";
1678
+ for (let i = 0; i < chunks.length; i++) {
1679
+ const chunk = chunks[i];
1680
+ if (typeof chunk === "string") {
1681
+ out += chunk;
1682
+ } else {
1683
+ const localId = chunk.type === "root-ref" ? chunk.localId : chunk.localPath[0];
1684
+ out += String(remap ? remap[localId] ?? localId : localId);
1685
+ if (chunk.type !== "root-ref-path") {
1686
+ continue;
1687
+ }
1688
+ const path = chunk.localPath;
1689
+ for (let j = 1; j < path.length; j++) {
1690
+ out += " " + path[j];
1691
+ }
1692
+ }
1693
+ }
1694
+ return out;
1695
+ };
1696
+ var StringSSRWriter = class {
1697
+ buffer = [];
1698
+ write(text) {
1699
+ this.buffer.push(text);
1700
+ }
1701
+ writeRootRef(id) {
1702
+ writeStringRootRef(this, id);
1703
+ }
1704
+ writeRootRefPath(path) {
1705
+ writeStringRootRefPath(this, path);
1706
+ }
1707
+ clear() {
1708
+ this.buffer.length = 0;
1709
+ }
1710
+ toString(_) {
1711
+ return this.buffer.join("");
1712
+ }
1713
+ };
1714
+ var StringBufferSegmentWriter = class {
1715
+ chunks = [];
1716
+ write(text) {
1717
+ this.chunks.push(text);
1718
+ }
1719
+ writeRootRef(id) {
1720
+ this.chunks.push({ type: "root-ref", localId: id });
1721
+ }
1722
+ writeRootRefPath(path) {
1723
+ this.chunks.push({ type: "root-ref-path", localPath: path });
1724
+ }
1725
+ clear() {
1726
+ this.chunks.length = 0;
1727
+ }
1728
+ extract() {
1729
+ const chunks = this.chunks;
1730
+ this.chunks = [];
1731
+ return chunks;
1732
+ }
1733
+ toString(remap) {
1734
+ return renderSSRChunks(this.chunks, remap);
1735
+ }
1736
+ };
1737
+
1385
1738
  // packages/qwik/src/server/tag-nesting.ts
1386
1739
  var allowedContent = (state) => {
1387
1740
  switch (state) {
@@ -1724,7 +2077,7 @@ function getBuildBase(opts) {
1724
2077
  return `${import.meta.env?.BASE_URL || "/"}build/`;
1725
2078
  }
1726
2079
  var versions = {
1727
- qwik: "2.0.0-beta.35-dev+4603135",
2080
+ qwik: "2.0.0-beta.36-dev+3268fab",
1728
2081
  qwikDom: "2.1.19"
1729
2082
  };
1730
2083
 
@@ -1785,7 +2138,7 @@ function vNodeData_createSsrNodeReference(currentComponentNode, vNodeData, depth
1785
2138
  stack[stack.length - 1]++;
1786
2139
  }
1787
2140
  }
1788
- let refId = depthFirstElementIdx + "";
2141
+ let refId = String(depthFirstElementIdx);
1789
2142
  if (vNodeData[0] & (2 /* VIRTUAL_NODE */ | 1 /* TEXT_DATA */)) {
1790
2143
  for (let i = 0; i < stack.length; i++) {
1791
2144
  const childCount = stack[i];
@@ -1824,11 +2177,24 @@ function encodeAsAlphanumeric(value) {
1824
2177
  }
1825
2178
 
1826
2179
  // packages/qwik/src/server/ssr-container.ts
2180
+ var NO_SCRIPT_HERE_ELEMENTS = /* @__PURE__ */ new Set([
2181
+ "script",
2182
+ "style",
2183
+ "textarea",
2184
+ "title",
2185
+ "iframe",
2186
+ "noframes",
2187
+ "noscript",
2188
+ "xmp",
2189
+ "template",
2190
+ "svg",
2191
+ "math"
2192
+ ]);
1827
2193
  function ssrCreateContainer(opts) {
1828
2194
  opts.renderOptions ||= {};
1829
2195
  return new SSRContainer({
1830
2196
  tagName: opts.tagName || "div",
1831
- writer: opts.writer || new StringBufferWriter(),
2197
+ writer: opts.writer || new StringSSRWriter(),
1832
2198
  streamHandler: opts.streamHandler,
1833
2199
  locale: opts.locale || "",
1834
2200
  timing: opts.timing || {
@@ -1847,16 +2213,16 @@ function ssrCreateContainer(opts) {
1847
2213
  renderOptions: opts.renderOptions
1848
2214
  });
1849
2215
  }
1850
- var StringBufferWriter = class {
1851
- buffer = [];
1852
- write(text) {
1853
- this.buffer.push(text);
1854
- }
1855
- toString() {
1856
- return this.buffer.join("");
2216
+ var noopStreamHandler = {
2217
+ flush() {
2218
+ },
2219
+ waitForPendingFlush() {
2220
+ },
2221
+ streamBlockStart() {
2222
+ },
2223
+ streamBlockEnd() {
1857
2224
  }
1858
2225
  };
1859
- var EMPTY_OBJ = {};
1860
2226
  var QTemplateProps = {
1861
2227
  hidden: true,
1862
2228
  "aria-hidden": true
@@ -1871,7 +2237,12 @@ var SSRContainer = class extends _SharedContainer {
1871
2237
  resolvedManifest;
1872
2238
  symbolToChunkResolver;
1873
2239
  renderOptions;
2240
+ outOfOrderStreaming;
1874
2241
  serializationCtx;
2242
+ // Sometimes there is no app state, but framework metadata still points to a vnode id.
2243
+ // For example, an OOOS segment can point outside the segment to a root vnode through
2244
+ // q:sparent, so root vnode data must still be emitted for the client ref table.
2245
+ hasVNodeRefsForSerialization = false;
1875
2246
  /**
1876
2247
  * We use this to append additional nodes in the head node
1877
2248
  *
@@ -1889,6 +2260,7 @@ var SSRContainer = class extends _SharedContainer {
1889
2260
  currentComponentNode = null;
1890
2261
  styleIds = /* @__PURE__ */ new Set();
1891
2262
  isBackpatchExecutorEmitted = false;
2263
+ isOutOfOrderExecutorEmitted = false;
1892
2264
  backpatchMap = /* @__PURE__ */ new Map();
1893
2265
  currentElementFrame = null;
1894
2266
  renderTimer;
@@ -1900,6 +2272,7 @@ var SSRContainer = class extends _SharedContainer {
1900
2272
  */
1901
2273
  depthFirstElementCount = -1;
1902
2274
  vNodeDatas = [];
2275
+ vNodeDataOffset = 0;
1903
2276
  componentStack = [];
1904
2277
  cleanupQueue = [];
1905
2278
  emitContainerDataFrame = null;
@@ -1908,8 +2281,22 @@ var SSRContainer = class extends _SharedContainer {
1908
2281
  $noMoreRoots$ = false;
1909
2282
  qlInclude;
1910
2283
  promiseAttributes = null;
2284
+ vnodeSegment = null;
2285
+ $containerState$ = 0 /* NotReady */;
2286
+ // OOOS related fields
2287
+ outOfOrderId = 0;
2288
+ outOfOrderUsed = false;
2289
+ outOfOrderPendingSegments = [];
2290
+ outOfOrderSegments = [];
2291
+ rootContainerReadyPromise = null;
2292
+ resolveRootContainerReady = null;
2293
+ renderQueue = Promise.resolve();
2294
+ emittedQwikEventNames = /* @__PURE__ */ new Set();
2295
+ emittedSyncFnCount = 0;
2296
+ rootContainerSerializedRootCount = 0;
2297
+ emittedVNodeDataOwners = null;
1911
2298
  constructor(opts) {
1912
- super(opts.renderOptions.serverData ?? EMPTY_OBJ, opts.locale);
2299
+ super(opts.renderOptions.serverData ?? {}, opts.locale);
1913
2300
  this.symbolToChunkResolver = (symbol) => {
1914
2301
  const idx = symbol.lastIndexOf("_");
1915
2302
  const chunk = this.resolvedManifest.mapper[idx == -1 ? symbol : symbol.substring(idx + 1)];
@@ -1930,6 +2317,17 @@ var SSRContainer = class extends _SharedContainer {
1930
2317
  this.$buildBase$ = opts.buildBase;
1931
2318
  this.resolvedManifest = opts.resolvedManifest;
1932
2319
  this.renderOptions = opts.renderOptions;
2320
+ const outOfOrderStreaming = this.renderOptions.streaming?.outOfOrder === true;
2321
+ if (!__EXPERIMENTAL__.suspense) {
2322
+ if (outOfOrderStreaming) {
2323
+ throw new Error(
2324
+ 'Out-of-order Suspense streaming requires `experimental: ["suspense"]` in the `qwikVite` plugin.'
2325
+ );
2326
+ }
2327
+ this.outOfOrderStreaming = false;
2328
+ } else {
2329
+ this.outOfOrderStreaming = outOfOrderStreaming;
2330
+ }
1933
2331
  this.$currentUniqueId$ = 1e5;
1934
2332
  const qlOpt = this.renderOptions.qwikLoader;
1935
2333
  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 +2365,157 @@ var SSRContainer = class extends _SharedContainer {
1967
2365
  async renderJSX(jsx, options) {
1968
2366
  await _walkJSX(this, jsx, options);
1969
2367
  }
2368
+ $isReadyForOOOS$() {
2369
+ return this.$containerState$ === 2 /* OOOSReady */;
2370
+ }
2371
+ /** Queue OOOS serialization/write work that must not overlap with root state serialization. */
2372
+ $runQueuedRender$(render) {
2373
+ if (!__EXPERIMENTAL__.suspense || !this.outOfOrderStreaming) {
2374
+ return render();
2375
+ }
2376
+ if (this.$containerState$ === 0 /* NotReady */) {
2377
+ return render();
2378
+ }
2379
+ const result = this.$containerState$ === 1 /* DataStreamStarted */ ? this.renderQueue.then(() => this.$waitForRootContainerReady$()).then(render) : this.renderQueue.then(render);
2380
+ this.renderQueue = result.catch(() => {
2381
+ });
2382
+ return result;
2383
+ }
2384
+ $waitForRootContainerReady$() {
2385
+ if (!__EXPERIMENTAL__.suspense || !this.outOfOrderStreaming || this.$isReadyForOOOS$()) {
2386
+ return;
2387
+ }
2388
+ return this.rootContainerReadyPromise ||= new Promise((resolve) => {
2389
+ this.resolveRootContainerReady = resolve;
2390
+ });
2391
+ }
2392
+ $markRootContainerReady$() {
2393
+ if (!__EXPERIMENTAL__.suspense || !this.outOfOrderStreaming || this.$isReadyForOOOS$()) {
2394
+ return;
2395
+ }
2396
+ this.rootContainerSerializedRootCount = this.serializationCtx.$roots$.length;
2397
+ this.$containerState$ = 2 /* OOOSReady */;
2398
+ this.resolveRootContainerReady?.();
2399
+ this.resolveRootContainerReady = null;
2400
+ this.rootContainerReadyPromise = null;
2401
+ }
2402
+ nextOutOfOrderId() {
2403
+ if (!__EXPERIMENTAL__.suspense || !this.outOfOrderStreaming) {
2404
+ return 0;
2405
+ }
2406
+ this.outOfOrderUsed = true;
2407
+ return ++this.outOfOrderId;
2408
+ }
2409
+ emitOutOfOrderSegmentScripts(scripts) {
2410
+ if (!__EXPERIMENTAL__.suspense || !this.outOfOrderStreaming || !scripts) {
2411
+ return;
2412
+ }
2413
+ this.write(scripts);
2414
+ }
2415
+ async segment(segmentId, jsx, options) {
2416
+ if (!__EXPERIMENTAL__.suspense) {
2417
+ throw new Error(
2418
+ 'Out-of-order Suspense streaming requires `experimental: ["suspense"]` in the `qwikVite` plugin.'
2419
+ );
2420
+ }
2421
+ if (!this.outOfOrderStreaming) {
2422
+ throw new Error(
2423
+ "Out-of-order Suspense streaming requires `streaming.outOfOrder` to be `true`."
2424
+ );
2425
+ }
2426
+ this.markVNodeRefForSerialization(options.parentComponentFrame?.componentNode);
2427
+ const writer = new StringBufferSegmentWriter();
2428
+ const segmentContainer = this.createSegmentContainer(segmentId, writer);
2429
+ this.outOfOrderSegments.push(segmentContainer);
2430
+ try {
2431
+ await segmentContainer.renderJSX(jsx, options);
2432
+ await segmentContainer.resolvePromiseAttributes();
2433
+ const htmlChunks = writer.extract();
2434
+ return {
2435
+ container: segmentContainer,
2436
+ writer,
2437
+ htmlChunks
2438
+ };
2439
+ } catch (error) {
2440
+ this.removeOutOfOrderSegment(segmentContainer);
2441
+ throw error;
2442
+ }
2443
+ }
2444
+ $getRootContainer$() {
2445
+ let rootContainer = this;
2446
+ while (rootContainer instanceof SSRSegmentContainer) {
2447
+ rootContainer = rootContainer.$rootContainer$;
2448
+ }
2449
+ return rootContainer;
2450
+ }
2451
+ createSegmentContainer(segmentId, writer) {
2452
+ const rootContainer = this.$getRootContainer$();
2453
+ const contentHostNode = this.getOrCreateLastNode();
2454
+ this.addRoot(contentHostNode);
2455
+ this.markVNodeRefForSerialization(contentHostNode);
2456
+ const rootFrame = {
2457
+ tagNesting: 10 /* ANYTHING */,
2458
+ parent: null,
2459
+ elementName: "#segment",
2460
+ depthFirstElementIdx: -1,
2461
+ // OOOS inserts this synthetic root under the Suspense content host on the client.
2462
+ vNodeData: [16 /* SERIALIZE */],
2463
+ currentFile: null,
2464
+ refBase: contentHostNode.id
2465
+ };
2466
+ const segmentContainer = new SSRSegmentContainer(
2467
+ {
2468
+ tagName: this.tag,
2469
+ writer,
2470
+ streamHandler: noopStreamHandler,
2471
+ locale: this.$locale$,
2472
+ timing: this.timing,
2473
+ buildBase: this.$buildBase$ || "/build/",
2474
+ resolvedManifest: this.resolvedManifest,
2475
+ renderOptions: this.renderOptions
2476
+ },
2477
+ rootContainer
2478
+ );
2479
+ const innerSegmentContainer = segmentContainer;
2480
+ innerSegmentContainer.$isOutOfOrderSegment$ = true;
2481
+ innerSegmentContainer.$storeProxyMap$ = this.$storeProxyMap$;
2482
+ segmentContainer.serializationCtx = segmentContainer.serializationCtxFactory(
2483
+ SsrNode,
2484
+ DomRef,
2485
+ this.symbolToChunkResolver,
2486
+ writer
2487
+ );
2488
+ segmentContainer.serializationCtx.$addSyncFn$ = this.serializationCtx.$addSyncFn$.bind(
2489
+ this.serializationCtx
2490
+ );
2491
+ segmentContainer.currentElementFrame = rootFrame;
2492
+ segmentContainer.currentComponentNode = this.currentComponentNode;
2493
+ segmentContainer.depthFirstElementCount = 0;
2494
+ segmentContainer.vNodeDatas = [rootFrame.vNodeData];
2495
+ segmentContainer.componentStack = this.componentStack.slice();
2496
+ segmentContainer.vnodeSegment = segmentId;
2497
+ segmentContainer.styleIds = this.styleIds;
2498
+ segmentContainer.emittedQwikEventNames = this.emittedQwikEventNames;
2499
+ segmentContainer.qlInclude = 2 /* Done */;
2500
+ segmentContainer.$instanceHash$ = this.$instanceHash$;
2501
+ innerSegmentContainer._didAddQwikLoader = true;
2502
+ return segmentContainer;
2503
+ }
2504
+ queueOutOfOrderSegment(segment) {
2505
+ if (!__EXPERIMENTAL__.suspense || !this.outOfOrderStreaming) {
2506
+ return;
2507
+ }
2508
+ this.outOfOrderPendingSegments.push(segment);
2509
+ }
2510
+ removeOutOfOrderSegment(segment) {
2511
+ const segments = this.outOfOrderSegments;
2512
+ for (let i = 0; i < segments.length; i++) {
2513
+ if (segments[i] === segment) {
2514
+ segments.splice(i, 1);
2515
+ return;
2516
+ }
2517
+ }
2518
+ }
1970
2519
  setContext(host, context, value) {
1971
2520
  const ssrNode = host;
1972
2521
  let ctx = ssrNode.getProp(QCtxAttr);
@@ -2031,7 +2580,7 @@ var SSRContainer = class extends _SharedContainer {
2031
2580
  /** Renders opening tag for DOM element */
2032
2581
  openElement(elementName, key, varAttrs, constAttrs = null, styleScopedId = null, currentFile = null, hasMovedCaptures = true) {
2033
2582
  const isQwikStyle = isQwikStyleElement(elementName, varAttrs) || isQwikStyleElement(elementName, constAttrs);
2034
- if (elementName === "noscript" || elementName === "template" || elementName === "script") {
2583
+ if (NO_SCRIPT_HERE_ELEMENTS.has(elementName)) {
2035
2584
  this.$noScriptHere$++;
2036
2585
  }
2037
2586
  if (
@@ -2129,7 +2678,7 @@ var SSRContainer = class extends _SharedContainer {
2129
2678
  this.write(GT);
2130
2679
  }
2131
2680
  this.lastNode = null;
2132
- if (elementName === "noscript" || elementName === "template" || elementName === "script") {
2681
+ if (NO_SCRIPT_HERE_ELEMENTS.has(elementName)) {
2133
2682
  this.$noScriptHere$--;
2134
2683
  }
2135
2684
  }
@@ -2151,7 +2700,13 @@ var SSRContainer = class extends _SharedContainer {
2151
2700
  this.openFragment(attrs);
2152
2701
  const componentFrame = this.getComponentFrame();
2153
2702
  if (componentFrame) {
2154
- this.serializationCtx.$addRoot$(componentFrame.componentNode);
2703
+ const projectionNode = this.getOrCreateLastNode();
2704
+ this.markVNodeRefForSerialization(projectionNode);
2705
+ if (!this.vnodeSegment) {
2706
+ this.addRoot(componentFrame.componentNode);
2707
+ } else {
2708
+ this.markVNodeRefForSerialization(componentFrame.componentNode);
2709
+ }
2155
2710
  componentFrame.projectionDepth++;
2156
2711
  }
2157
2712
  }
@@ -2200,13 +2755,18 @@ var SSRContainer = class extends _SharedContainer {
2200
2755
  for (let i = 0; i < componentFrame.slots.length; i += 2) {
2201
2756
  const slotName = componentFrame.slots[i];
2202
2757
  const children = componentFrame.slots[i + 1];
2758
+ if (this.vnodeSegment) {
2759
+ this.markVNodeRefForSerialization(componentFrame.componentNode);
2760
+ }
2203
2761
  this.openFragment(
2204
- isDev8 ? { [DEBUG_TYPE]: "P" /* Projection */, [QSlotParent]: componentFrame.componentNode.id } : { [QSlotParent]: componentFrame.componentNode.id }
2762
+ isDev8 ? {
2763
+ [DEBUG_TYPE]: "P" /* Projection */,
2764
+ [QSlotParent]: componentFrame.componentNode.id,
2765
+ [QSlot]: slotName
2766
+ } : { [QSlotParent]: componentFrame.componentNode.id, [QSlot]: slotName }
2205
2767
  );
2206
2768
  const lastNode = this.getOrCreateLastNode();
2207
- if (lastNode.vnodeData) {
2208
- lastNode.vnodeData[0] |= 16 /* SERIALIZE */;
2209
- }
2769
+ lastNode.vnodeData[0] |= 16 /* SERIALIZE */;
2210
2770
  componentFrame.componentNode.setProp(slotName, lastNode.id);
2211
2771
  await this.renderJSX(children, {
2212
2772
  currentStyleScoped: scopedStyleId,
@@ -2230,19 +2790,22 @@ var SSRContainer = class extends _SharedContainer {
2230
2790
  }
2231
2791
  addRoot(obj) {
2232
2792
  if (this.$noMoreRoots$) {
2233
- return this.serializationCtx.$hasRootId$(obj);
2793
+ const rootId = this.serializationCtx.$hasRootId$(obj);
2794
+ return rootId;
2234
2795
  }
2235
2796
  return this.serializationCtx.$addRoot$(obj);
2236
2797
  }
2237
2798
  getOrCreateLastNode() {
2238
2799
  if (!this.lastNode) {
2800
+ const currentFrame = this.currentElementFrame;
2801
+ const elementIndex = currentFrame.depthFirstElementIdx + 1;
2802
+ const refBase = currentFrame.refBase ?? (this.vnodeSegment ? getSegmentVNodeRefId(this.vnodeSegment, elementIndex) : elementIndex + this.vNodeDataOffset);
2239
2803
  this.lastNode = vNodeData_createSsrNodeReference(
2240
2804
  this.currentComponentNode,
2241
- this.currentElementFrame.vNodeData,
2242
- // we start at -1, so we need to add +1
2243
- this.currentElementFrame.depthFirstElementIdx + 1,
2805
+ currentFrame.vNodeData,
2806
+ refBase,
2244
2807
  this.cleanupQueue,
2245
- this.currentElementFrame.currentFile
2808
+ currentFrame.currentFile
2246
2809
  );
2247
2810
  }
2248
2811
  return this.lastNode;
@@ -2297,23 +2860,67 @@ var SSRContainer = class extends _SharedContainer {
2297
2860
  this.write(content);
2298
2861
  this.closeElement();
2299
2862
  }
2863
+ $deferRootPlaceholder$(scriptNode) {
2864
+ if (this.isHtml && this.currentElementFrame?.elementName === "html") {
2865
+ this.additionalHeadNodes.push(scriptNode);
2866
+ return true;
2867
+ }
2868
+ return false;
2869
+ }
2300
2870
  ////////////////////////////////////
2301
2871
  emitContainerData() {
2872
+ const isStreamingDisabled = this.renderOptions.streaming?.inOrder?.strategy === "disabled";
2873
+ const shouldFlushShell = !isStreamingDisabled || __EXPERIMENTAL__.suspense && this.outOfOrderStreaming && this.outOfOrderUsed;
2302
2874
  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
- })
2875
+ maybeThen(
2876
+ shouldFlushShell ? this.streamHandler.flush() : void 0,
2877
+ () => this.resolvePromiseAttributes()
2878
+ ),
2879
+ () => {
2880
+ this.$containerState$ = 1 /* DataStreamStarted */;
2881
+ return maybeThen(this.emitStateData(), () => {
2882
+ this.$noMoreRoots$ = true;
2883
+ return maybeThen(this.emitRestStateData(), () => this.emitOutOfOrderSegmentsAndData());
2884
+ });
2885
+ }
2315
2886
  );
2316
2887
  }
2888
+ emitRestStateData() {
2889
+ this.emitVNodeData();
2890
+ this.emitDelayedOutOfOrderSegmentVNodeData();
2891
+ if (!isDev8) {
2892
+ preloaderPost(this, this.renderOptions, this.$serverData$?.nonce);
2893
+ }
2894
+ this.emitSyncFnsData();
2895
+ this.emitPatchDataIfNeeded();
2896
+ this.emitExecutorIfNeeded();
2897
+ this.emitQwikLoaderAtBottomIfNeeded();
2898
+ this.emitContainerReadyEventIfNeeded();
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,67 @@ 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
+ emitContainerReadyEventIfNeeded() {
3224
+ if (!__EXPERIMENTAL__.suspense || !this.outOfOrderStreaming || !this.outOfOrderUsed) {
3225
+ return;
3226
+ }
3227
+ this.emitInlineScript(
3228
+ `document.qready||(document.qready={});document.qready["${this.$instanceHash$}"]=1;try{document.dispatchEvent(new CustomEvent("qready",{detail:"${this.$instanceHash$}"}))}catch(e){}`
3229
+ );
3230
+ }
3231
+ writeScript(attrs, body) {
3232
+ this.openScript(attrs);
3233
+ if (body) {
3234
+ this.write(body);
3235
+ }
3236
+ this.closeScript();
3237
+ }
3238
+ openScript(attrs) {
3239
+ this.write("<script");
3240
+ this.writeAttrs("script", attrs, true, null, null, true);
3241
+ this.write(GT);
3242
+ }
3243
+ closeScript() {
3244
+ this.write("</script>");
2531
3245
  }
2532
3246
  emitPreloaderPre() {
2533
3247
  if (!isDev8) {
@@ -2535,7 +3249,7 @@ var SSRContainer = class extends _SharedContainer {
2535
3249
  }
2536
3250
  }
2537
3251
  isStatic() {
2538
- return this.serializationCtx.$eventQrls$.size === 0;
3252
+ return !(__EXPERIMENTAL__.suspense && this.outOfOrderStreaming && this.outOfOrderUsed) && this.serializationCtx.$eventQrls$.size === 0;
2539
3253
  }
2540
3254
  emitQwikLoaderAtTopIfNeeded() {
2541
3255
  if (this.qlInclude === 0 /* Module */) {
@@ -2556,8 +3270,7 @@ var SSRContainer = class extends _SharedContainer {
2556
3270
  if (nonce) {
2557
3271
  scriptAttrs["nonce"] = nonce;
2558
3272
  }
2559
- this.openElement("script", null, scriptAttrs);
2560
- this.closeElement();
3273
+ this.writeScript(scriptAttrs);
2561
3274
  }
2562
3275
  }
2563
3276
  emitQwikLoaderInline() {
@@ -2571,17 +3284,25 @@ var SSRContainer = class extends _SharedContainer {
2571
3284
  if (this.renderOptions.serverData?.nonce) {
2572
3285
  scriptAttrs["nonce"] = this.renderOptions.serverData.nonce;
2573
3286
  }
2574
- this.openElement("script", null, scriptAttrs);
2575
- this.write(qwikLoaderScript);
2576
- this.closeElement();
3287
+ this.writeScript(scriptAttrs, qwikLoaderScript);
2577
3288
  }
2578
3289
  emitQwikLoaderAtBottomIfNeeded() {
2579
3290
  if (!this.isStatic()) {
2580
3291
  if (this.qlInclude !== 2 /* Done */) {
2581
3292
  this.emitQwikLoaderInline();
2582
3293
  }
2583
- this.emitQwikEvents(Array.from(this.serializationCtx.$eventNames$, (s) => JSON.stringify(s)));
3294
+ this.emitNewQwikEvents();
3295
+ }
3296
+ }
3297
+ emitNewQwikEvents() {
3298
+ const eventNames = [];
3299
+ for (const eventName of this.serializationCtx.$eventNames$) {
3300
+ if (!this.emittedQwikEventNames.has(eventName)) {
3301
+ this.emittedQwikEventNames.add(eventName);
3302
+ eventNames.push(JSON.stringify(eventName));
3303
+ }
2584
3304
  }
3305
+ this.emitQwikEvents(eventNames);
2585
3306
  }
2586
3307
  emitQwikEvents(eventNames) {
2587
3308
  if (eventNames.length > 0) {
@@ -2590,11 +3311,11 @@ var SSRContainer = class extends _SharedContainer {
2590
3311
  if (nonce) {
2591
3312
  scriptAttrs["nonce"] = nonce;
2592
3313
  }
2593
- this.openElement("script", null, scriptAttrs);
3314
+ this.openScript(scriptAttrs);
2594
3315
  this.write(`(window._qwikEv||(window._qwikEv=[])).push(`);
2595
3316
  this.writeArray(eventNames, COMMA);
2596
3317
  this.write(PAREN_CLOSE);
2597
- this.closeElement();
3318
+ this.closeScript();
2598
3319
  }
2599
3320
  }
2600
3321
  // Keep in sync with process-vnode-data.unit.ts
@@ -2662,7 +3383,7 @@ var SSRContainer = class extends _SharedContainer {
2662
3383
  text.push(
2663
3384
  `${indent}<${elementName}> <= is not allowed as a child of ${allowedContent(previousTagNesting)[0]}.`
2664
3385
  );
2665
- throw newTagError(text.map(escapeHTML).join("\n"));
3386
+ throw newTagError(text.join("\n"));
2666
3387
  }
2667
3388
  }
2668
3389
  }
@@ -2672,7 +3393,8 @@ var SSRContainer = class extends _SharedContainer {
2672
3393
  elementName,
2673
3394
  depthFirstElementIdx,
2674
3395
  vNodeData: [0 /* NONE */],
2675
- currentFile: isDev8 ? currentFile || null : null
3396
+ currentFile: isDev8 ? currentFile || null : null,
3397
+ refBase: null
2676
3398
  };
2677
3399
  this.currentElementFrame = frame;
2678
3400
  this.vNodeDatas.push(frame.vNodeData);
@@ -2687,6 +3409,17 @@ var SSRContainer = class extends _SharedContainer {
2687
3409
  this.size += text.length;
2688
3410
  this.writer.write(text);
2689
3411
  }
3412
+ writeRootRef(id) {
3413
+ this.size += String(id).length;
3414
+ this.writer.writeRootRef(id);
3415
+ }
3416
+ writeRootRefPath(path) {
3417
+ this.size += String(path[0]).length;
3418
+ this.writer.writeRootRefPath(path);
3419
+ for (let i = 1; i < path.length; i++) {
3420
+ this.size += 1 + String(path[i]).length;
3421
+ }
3422
+ }
2690
3423
  writeArray(array, separator) {
2691
3424
  for (let i = 0; i < array.length; i++) {
2692
3425
  const element = array[i];
@@ -2722,7 +3455,11 @@ var SSRContainer = class extends _SharedContainer {
2722
3455
  throw qError(15 /* invalidRefValue */, [currentFile]);
2723
3456
  }
2724
3457
  } else if (key === ITERATION_ITEM_SINGLE || key === ITERATION_ITEM_MULTI) {
2725
- value = this.serializationCtx.$addRoot$(value);
3458
+ const rootId = this.addRoot(value);
3459
+ if (rootId === void 0) {
3460
+ continue;
3461
+ }
3462
+ value = typeof rootId === "number" ? [rootId] : String(rootId);
2726
3463
  } else if (isSignal(value)) {
2727
3464
  const lastNode = this.getOrCreateLastNode();
2728
3465
  const signalData = new SubscriptionData({
@@ -2738,7 +3475,11 @@ var SSRContainer = class extends _SharedContainer {
2738
3475
  const lastNode = this.getOrCreateLastNode();
2739
3476
  this.addPromiseAttribute(value);
2740
3477
  value.then((resolvedValue) => {
2741
- this.addBackpatchEntry(lastNode.id, key, resolvedValue);
3478
+ this.addBackpatchEntry(
3479
+ lastNode.id,
3480
+ key,
3481
+ serializeAttribute(key, resolvedValue, styleScopedId)
3482
+ );
2742
3483
  });
2743
3484
  continue;
2744
3485
  }
@@ -2771,14 +3512,30 @@ var SSRContainer = class extends _SharedContainer {
2771
3512
  this.write(key);
2772
3513
  if (serializedValue !== true) {
2773
3514
  this.write(ATTR_EQUALS_QUOTE);
2774
- const strValue = escapeHTML(String(serializedValue));
2775
- this.write(strValue);
3515
+ if (Array.isArray(serializedValue)) {
3516
+ this.writeEscapedChunks(serializedValue);
3517
+ } else {
3518
+ const strValue = escapeHTML(String(serializedValue));
3519
+ this.write(strValue);
3520
+ }
2776
3521
  this.write(QUOTE);
2777
3522
  }
2778
3523
  }
2779
3524
  }
2780
3525
  return innerHTML;
2781
3526
  }
3527
+ writeEscapedChunks(chunks) {
3528
+ for (let i = 0; i < chunks.length; i++) {
3529
+ const chunk = chunks[i];
3530
+ if (typeof chunk === "string") {
3531
+ this.write(escapeHTML(chunk));
3532
+ } else if (typeof chunk === "number") {
3533
+ this.writeRootRef(chunk);
3534
+ } else {
3535
+ this.writeRootRefPath(chunk.path);
3536
+ }
3537
+ }
3538
+ }
2782
3539
  addPromiseAttribute(promise) {
2783
3540
  this.promiseAttributes ||= [];
2784
3541
  this.promiseAttributes.push(promise);
@@ -2790,6 +3547,277 @@ var SSRContainer = class extends _SharedContainer {
2790
3547
  }
2791
3548
  }
2792
3549
  };
3550
+ var SSRSegmentContainer = class extends SSRContainer {
3551
+ constructor(opts, $rootContainer$) {
3552
+ super(opts);
3553
+ this.$rootContainer$ = $rootContainer$;
3554
+ }
3555
+ $outOfOrderState$ = 0 /* Rendering */;
3556
+ $outOfOrderRootIdMap$ = null;
3557
+ subscriptionPatchRecords = [];
3558
+ pendingVNodeDataPatches = null;
3559
+ nextOutOfOrderId() {
3560
+ return this.$rootContainer$.nextOutOfOrderId();
3561
+ }
3562
+ $runQueuedRender$(render) {
3563
+ return this.$rootContainer$.$runQueuedRender$(render);
3564
+ }
3565
+ queueOutOfOrderSegment(segment) {
3566
+ this.$rootContainer$.queueOutOfOrderSegment(segment);
3567
+ }
3568
+ emitOutOfOrderSegmentScripts(scripts) {
3569
+ this.$rootContainer$.emitOutOfOrderSegmentScripts(scripts);
3570
+ }
3571
+ emitOutOfOrderExecutorIfNeeded() {
3572
+ this.$rootContainer$.emitOutOfOrderExecutorIfNeeded();
3573
+ }
3574
+ $recordExternalRootEffect$(producer, effect, prop, sourceEffects) {
3575
+ recordExternalRootEffect(
3576
+ this.$rootContainer$.serializationCtx,
3577
+ this.serializationCtx,
3578
+ this.$rootContainer$.$storeProxyMap$,
3579
+ this.subscriptionPatchRecords,
3580
+ producer,
3581
+ effect,
3582
+ prop,
3583
+ sourceEffects
3584
+ );
3585
+ }
3586
+ async $finalizeOutOfOrderSegment$(segmentId, segment) {
3587
+ const rootContainer = this.$rootContainer$;
3588
+ const rootReadyAtSegment = rootContainer.$isReadyForOOOS$();
3589
+ const segmentSerializationCtx = this.serializationCtx;
3590
+ try {
3591
+ const commit = this.$commitRoots$(rootContainer, segmentSerializationCtx);
3592
+ this.$mergeSegmentEventData$(rootContainer, segmentSerializationCtx);
3593
+ this.$mergeSegmentSyncFns$(rootContainer, segmentSerializationCtx);
3594
+ const subscriptionPatchRootId = this.$addSubscriptionsToRoots$(
3595
+ rootContainer,
3596
+ rootReadyAtSegment,
3597
+ segmentSerializationCtx
3598
+ );
3599
+ if (rootReadyAtSegment && (commit.newRootLocalIds.length > 0 || subscriptionPatchRootId !== void 0)) {
3600
+ segmentSerializationCtx.$forwardRefOffset$ = rootContainer.serializationCtx.$serializedForwardRefCount$;
3601
+ await this.emitStatePatchData(
3602
+ segmentId,
3603
+ commit.newRootStart,
3604
+ commit.newRootLocalIds,
3605
+ subscriptionPatchRootId
3606
+ );
3607
+ rootContainer.serializationCtx.$serializedRootCount$ = rootContainer.serializationCtx.$roots$.length + (rootContainer.serializationCtx.$hasRootStateForwardRefs$ ? 1 : 0);
3608
+ rootContainer.serializationCtx.$serializedForwardRefCount$ += segmentSerializationCtx.$serializedForwardRefCount$;
3609
+ }
3610
+ this.emitPendingVNodeDataPatches();
3611
+ if (rootReadyAtSegment) {
3612
+ this.$noMoreRoots$ = true;
3613
+ this.emitVNodeData(segmentId);
3614
+ const segmentCtx = this.serializationCtx;
3615
+ this.serializationCtx = rootContainer.serializationCtx;
3616
+ this.emittedSyncFnCount = rootContainer.emittedSyncFnCount;
3617
+ this.emitSyncFnsData(true);
3618
+ rootContainer.emittedSyncFnCount = this.emittedSyncFnCount;
3619
+ this.serializationCtx = segmentCtx;
3620
+ this.emitNewQwikEvents();
3621
+ }
3622
+ this.emitPatchDataIfNeeded();
3623
+ this.drainCleanupQueue();
3624
+ const rootIdMap = commit.rootIdMap;
3625
+ if (rootReadyAtSegment) {
3626
+ this.$outOfOrderState$ = 2 /* Done */;
3627
+ } else {
3628
+ this.$outOfOrderRootIdMap$ = rootIdMap;
3629
+ this.$outOfOrderState$ = 1 /* EarlyFinalized */;
3630
+ }
3631
+ return {
3632
+ html: renderSSRChunks(segment.htmlChunks, rootIdMap),
3633
+ scripts: segment.writer.toString(rootIdMap)
3634
+ };
3635
+ } finally {
3636
+ if (this.$outOfOrderState$ !== 1 /* EarlyFinalized */) {
3637
+ segmentSerializationCtx.$onAddRoot$ = void 0;
3638
+ rootContainer.removeOutOfOrderSegment(this);
3639
+ }
3640
+ rootContainer.serializationCtx.$setWriter$(rootContainer.writer);
3641
+ }
3642
+ }
3643
+ $emitDelayedOutOfOrderVNodeData$() {
3644
+ try {
3645
+ this.emitVNodeData(this.vnodeSegment);
3646
+ this.emitPendingVNodeDataPatches();
3647
+ this.$rootContainer$.emitOutOfOrderSegmentScripts(
3648
+ this.writer.toString(this.$outOfOrderRootIdMap$)
3649
+ );
3650
+ this.$outOfOrderState$ = 2 /* Done */;
3651
+ this.$rootContainer$.removeOutOfOrderSegment(this);
3652
+ } finally {
3653
+ this.serializationCtx.$onAddRoot$ = void 0;
3654
+ }
3655
+ }
3656
+ markVNodeDataForSerialization(node, flags = 16 /* SERIALIZE */) {
3657
+ const previousFlags = node.vnodeData[0];
3658
+ const nextFlags = previousFlags | flags;
3659
+ if (nextFlags !== previousFlags) {
3660
+ node.vnodeData[0] = nextFlags;
3661
+ this.queueLateVNodeDataPatch(node, nextFlags & ~previousFlags);
3662
+ }
3663
+ }
3664
+ queueLateVNodeDataPatch(node, addedFlags) {
3665
+ if (!__EXPERIMENTAL__.suspense || !this.outOfOrderStreaming || !(addedFlags & (16 /* SERIALIZE */ | 8 /* REFERENCE */))) {
3666
+ return;
3667
+ }
3668
+ const owner = this.getVNodeDataOwnerFromNodeId(node.id);
3669
+ if (!this.$getRootContainer$().isVNodeDataOwnerEmitted(owner.owner)) {
3670
+ return;
3671
+ }
3672
+ let ownerPatches = (this.pendingVNodeDataPatches ||= /* @__PURE__ */ new Map()).get(owner.owner);
3673
+ if (!ownerPatches) {
3674
+ this.pendingVNodeDataPatches.set(owner.owner, ownerPatches = /* @__PURE__ */ new Map());
3675
+ }
3676
+ ownerPatches.set(owner.localIndex, node.vnodeData);
3677
+ }
3678
+ emitPendingVNodeDataPatches() {
3679
+ const pendingPatches = this.pendingVNodeDataPatches;
3680
+ this.pendingVNodeDataPatches = null;
3681
+ if (!pendingPatches) {
3682
+ return;
3683
+ }
3684
+ for (const [owner, entries] of pendingPatches) {
3685
+ if (entries.size === 0) {
3686
+ continue;
3687
+ }
3688
+ const sortedEntries = Array.from(entries).sort((a, b) => a[0] - b[0]);
3689
+ this.emitVNodeDataScript(owner, sortedEntries, true);
3690
+ }
3691
+ }
3692
+ $commitRoots$(rootContainer, segmentSerializationCtx) {
3693
+ const commit = this.commitSegmentRoots(rootContainer, segmentSerializationCtx);
3694
+ segmentSerializationCtx.$onAddRoot$ = (localId, root, obj) => {
3695
+ this.commitSegmentRoot(rootContainer, localId, root, obj, commit);
3696
+ };
3697
+ return commit;
3698
+ }
3699
+ $addSubscriptionsToRoots$(rootContainer, rootReadyAtSegment, segmentSerializationCtx) {
3700
+ let subscriptionPatchRootId = void 0;
3701
+ const subscriptionPatches = rootReadyAtSegment ? this.collectSubscriptionPatches(
3702
+ rootContainer,
3703
+ rootContainer.rootContainerSerializedRootCount
3704
+ ) : void 0;
3705
+ if (subscriptionPatches) {
3706
+ subscriptionPatchRootId = segmentSerializationCtx.$addRoot$(subscriptionPatches);
3707
+ }
3708
+ return subscriptionPatchRootId;
3709
+ }
3710
+ commitSegmentRoots(rootContainer, segmentSerializationCtx) {
3711
+ const rootIdMap = [];
3712
+ const newRootStart = rootContainer.$isReadyForOOOS$() ? rootContainer.serializationCtx.$serializedRootCount$ : rootContainer.serializationCtx.$roots$.length;
3713
+ const newRootLocalIds = [];
3714
+ const commit = {
3715
+ rootIdMap,
3716
+ newRootStart,
3717
+ newRootLocalIds
3718
+ };
3719
+ this.promoteSharedSegmentRoots(rootContainer, segmentSerializationCtx, commit);
3720
+ const segmentRoots = segmentSerializationCtx.$roots$;
3721
+ const segmentRootObjs = segmentSerializationCtx.$rootObjs$;
3722
+ for (let i = 0; i < segmentRoots.length; i++) {
3723
+ const rootObj = segmentRootObjs[i];
3724
+ this.commitSegmentRoot(rootContainer, i, segmentRoots[i], rootObj, commit);
3725
+ }
3726
+ return commit;
3727
+ }
3728
+ promoteSharedSegmentRoots(rootContainer, segmentSerializationCtx, commit) {
3729
+ const segmentRoots = segmentSerializationCtx.$roots$;
3730
+ const segmentRootObjs = segmentSerializationCtx.$rootObjs$;
3731
+ for (let i = 0; i < segmentRootObjs.length; i++) {
3732
+ const rootObj = segmentRootObjs[i];
3733
+ if (this.isRootOrUsedByOtherLiveSegment(rootContainer, rootObj)) {
3734
+ this.commitSegmentRoot(rootContainer, i, segmentRoots[i], rootObj, commit);
3735
+ }
3736
+ }
3737
+ }
3738
+ isRootOrUsedByOtherLiveSegment(rootContainer, obj) {
3739
+ if (rootContainer.serializationCtx.$hasRootId$(obj) !== void 0) {
3740
+ return true;
3741
+ }
3742
+ const segments = rootContainer.outOfOrderSegments;
3743
+ for (let i = 0; i < segments.length; i++) {
3744
+ const segment = segments[i];
3745
+ if (segment === this) {
3746
+ continue;
3747
+ }
3748
+ const rootObjs = segment.serializationCtx.$rootObjs$;
3749
+ for (let j = 0; j < rootObjs.length; j++) {
3750
+ if (rootObjs[j] === obj) {
3751
+ return true;
3752
+ }
3753
+ }
3754
+ }
3755
+ return false;
3756
+ }
3757
+ commitSegmentRoot(rootContainer, localId, root, rootObj, commit) {
3758
+ if (commit.rootIdMap[localId] !== void 0) {
3759
+ return;
3760
+ }
3761
+ let rootId = rootContainer.serializationCtx.$hasRootId$(rootObj);
3762
+ if (rootId === void 0) {
3763
+ rootId = rootContainer.serializationCtx.$commitRoot$(root, rootObj);
3764
+ commit.newRootLocalIds.push(localId);
3765
+ this.seedCommittedRootForLiveSegments(rootContainer, rootObj);
3766
+ }
3767
+ const rootCtx = rootContainer.serializationCtx;
3768
+ commit.rootIdMap[localId] = rootContainer.$isReadyForOOOS$() && rootId >= rootCtx.$rootStateRootCount$ ? rootId + (rootCtx.$hasRootStateForwardRefs$ ? 1 : 0) : rootId;
3769
+ }
3770
+ seedCommittedRootForLiveSegments(rootContainer, rootObj) {
3771
+ const segments = rootContainer.outOfOrderSegments;
3772
+ for (let i = 0; i < segments.length; i++) {
3773
+ const segment = segments[i];
3774
+ if (segment !== this && segment.$outOfOrderState$ === 0 /* Rendering */) {
3775
+ segment.serializationCtx.$addRoot$(rootObj);
3776
+ }
3777
+ }
3778
+ }
3779
+ $mergeSegmentEventData$(rootContainer, segmentSerializationCtx) {
3780
+ for (const eventName of segmentSerializationCtx.$eventNames$) {
3781
+ rootContainer.serializationCtx.$eventNames$.add(eventName);
3782
+ }
3783
+ for (const qrl of segmentSerializationCtx.$eventQrls$) {
3784
+ rootContainer.serializationCtx.$eventQrls$.add(qrl);
3785
+ }
3786
+ }
3787
+ $mergeSegmentSyncFns$(rootContainer, segmentSerializationCtx) {
3788
+ rootContainer.serializationCtx.$syncFns$.push(...segmentSerializationCtx.$syncFns$);
3789
+ }
3790
+ collectSubscriptionPatches(rootContainer, rootLimit) {
3791
+ if (!__EXPERIMENTAL__.suspense || !this.outOfOrderStreaming) {
3792
+ return;
3793
+ }
3794
+ return collectSubscriptionPatches(
3795
+ rootContainer.serializationCtx,
3796
+ this.subscriptionPatchRecords,
3797
+ rootLimit
3798
+ );
3799
+ }
3800
+ emitStatePatchData(segmentId, rootStart, rootIds, subscriptionPatchRootId) {
3801
+ const attrs = this.statePatchScriptAttrs(segmentId);
3802
+ this.openScript(attrs);
3803
+ this.serializationCtx.$setWriter$(this.writer);
3804
+ this.serializationCtx.$markSsrNodeForSerialization$ = this.markVNodeDataForSerialization.bind(this);
3805
+ return maybeThen(
3806
+ this.serializationCtx.$serializePatch$(rootStart, rootIds, subscriptionPatchRootId, 0),
3807
+ () => {
3808
+ this.closeScript();
3809
+ }
3810
+ );
3811
+ }
3812
+ statePatchScriptAttrs(segmentId) {
3813
+ const attrs = this.stateScriptAttrs();
3814
+ attrs[QStatePatchAttr] = true;
3815
+ if (segmentId) {
3816
+ attrs[QSuspenseResolved] = segmentId;
3817
+ }
3818
+ return attrs;
3819
+ }
3820
+ };
2793
3821
  var isQwikStyleElement = (tag, attrs) => {
2794
3822
  if (tag === "style" && attrs != null) {
2795
3823
  return Object.prototype.hasOwnProperty.call(attrs, QStyle) || Object.prototype.hasOwnProperty.call(attrs, QScopedStyle);
@@ -2851,58 +3879,43 @@ var StreamHandler = class {
2851
3879
  let stream;
2852
3880
  switch (this.inOrderStreaming.strategy) {
2853
3881
  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();
3882
+ stream = createStringStreamWriter((chunk) => {
3883
+ if (chunk === void 0 || chunk === null) {
3884
+ return;
2863
3885
  }
2864
- };
3886
+ handler.enqueue(chunk);
3887
+ });
2865
3888
  break;
2866
3889
  case "direct": {
2867
3890
  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();
3891
+ stream = createStringStreamWriter((chunk) => {
3892
+ if (chunk === void 0 || chunk === null) {
3893
+ return;
3894
+ }
3895
+ if (handler.pendingFlush) {
3896
+ const queued = handler.pendingFlush.then(() => originalStream.write(chunk));
3897
+ return handler.trackPendingFlush(queued);
2881
3898
  }
2882
- };
3899
+ return handler.trackPendingFlush(originalStream.write(chunk));
3900
+ });
2883
3901
  break;
2884
3902
  }
2885
3903
  default:
2886
3904
  case "auto": {
2887
3905
  const minimumChunkSize = this.inOrderStreaming.maximumChunk ?? 0;
2888
3906
  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
- }
3907
+ stream = createStringStreamWriter((chunk) => {
3908
+ if (chunk === void 0 || chunk === null) {
3909
+ return;
3910
+ }
3911
+ handler.enqueue(chunk);
3912
+ if (handler.streamBlockDepth === 0) {
3913
+ const maxBufferSize = handler.networkFlushes === 0 ? initialChunkSize : minimumChunkSize;
3914
+ if (handler.bufferSize >= maxBufferSize) {
3915
+ return handler.flush();
2900
3916
  }
2901
- },
2902
- waitForDrain() {
2903
- return handler.waitForPendingFlush();
2904
3917
  }
2905
- };
3918
+ });
2906
3919
  break;
2907
3920
  }
2908
3921
  }
@@ -2982,22 +3995,26 @@ var StreamHandler = class {
2982
3995
 
2983
3996
  // packages/qwik/src/server/ssr-render.ts
2984
3997
  var renderToString = async (jsx, opts = {}) => {
2985
- const chunks = [];
2986
- const stream = {
2987
- write(chunk) {
2988
- chunks.push(chunk);
2989
- }
2990
- };
3998
+ const stream = new StringSSRWriter();
2991
3999
  const result = await renderToStream(jsx, { ...opts, stream });
2992
4000
  return {
2993
4001
  isStatic: result.isStatic,
2994
4002
  timing: result.timing,
2995
4003
  manifest: result.manifest,
2996
4004
  snapshotResult: result.snapshotResult,
2997
- html: chunks.join("")
4005
+ html: stream.toString()
2998
4006
  };
2999
4007
  };
3000
4008
  var renderToStream = async (jsx, opts) => {
4009
+ if (__EXPERIMENTAL__.suspense && opts.streaming?.outOfOrder === void 0) {
4010
+ opts = {
4011
+ ...opts,
4012
+ streaming: {
4013
+ ...opts.streaming,
4014
+ outOfOrder: true
4015
+ }
4016
+ };
4017
+ }
3001
4018
  const timing = {
3002
4019
  firstFlush: 0,
3003
4020
  render: 0,