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

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.
@@ -1 +1 @@
1
- import{isServer as e}from"@qwik.dev/core/build";const n=e=>{let n;if(typeof MessageChannel!=="undefined"){const t=new MessageChannel;t.port1.onmessage=()=>e();n=()=>t.port2.postMessage(null)}else n=()=>setTimeout(e);return n};const t=typeof document!=="undefined";const o=!e&&t;const s=o?document:void 0;const c={t:25};const r=o&&s.createElement("link").relList?.supports?.("modulepreload")?"modulePreload":"preload";const i=/\.[mc]?js$/;const f=1e3/60;const l=0;const a=1;const $=2;const u=3;const d=4;const m=/* @__PURE__ */new Map;let p;let b=0;const w=[];const h=n(q);const y=n(S);let M=0;let P=0;let k=0;const v=[];const g=()=>{if(p){w.sort((e,n)=>e.o-n.o);p=0}};function q(){M=0;if(!w.length)return;g();const e=performance.now()+f;let n=0;while(w.length){const t=w[0];const o=t.o;const s=1-o;if(s>=.99||b<c.t){w.shift();T(t);if(performance.now()>=e){n=1;break}}else break}if(n&&w.length&&!M){M=1;h()}}const x=(e,n,t)=>{v.unshift({i:e,o:n,l:t})};const C=()=>{const e=v[v.length-1];const n=e.i;if(e.$){const t=e.u;if(t>=e.$.length){v.pop();return 0}const o=e.$[t];e.u=t+1;const s=R(o.m);if(s.o===0)return 1;const c=1-n.o;let r;if(c===1||c>=.99)r=Math.min(.01,1-o.p);else{const e=1-o.p*c;const n=o.h;const t=e/n;r=Math.max(.02,s.o*t);o.h=t}v.push({i:s,o:r,l:e.l});return 1}if(e.l?.has(n)){v.pop();return 0}const t=n.o;n.o=e.o;if(t-n.o<.01){v.pop();return 0}if(J!=null&&n.M<$){if(n.M===l){n.M=a;w.push(n)}p=1}if(n.$?.length){const t=e.l||/* @__PURE__ */new Set;t.add(n);e.l=t;e.$=n.$;e.u=0;return 0}v.pop();return 0};function S(){if(k||!v.length)return;P=0;k=1;const e=o?performance.now()+f:0;let n=0;while(v.length){n=1;const t=C();if(o&&t&&performance.now()>=e){if(!P){P=1;y()}break}}k=0;if(n&&o)h()}const T=e=>{if(e.M>=$)return;b++;const n=performance.now();e.k=n-e.v;e.M=$;const t=s.createElement("link");t.href=new URL(`${J}${e.m}`,s.baseURI).toString();t.rel=r;t.as="script";t.onload=t.onerror=()=>{b--;const o=performance.now();e.q=o-n;e.M=d;t.remove();h()};s.head.appendChild(t)};const j=(e,n,t)=>{x(e,n,t);if(o)y();else S()};const A=(e,n)=>{const t=R(e);if(t)x(t,n)};const I=(e,n)=>{if(!e?.length)return;const t=n?1-n:.4;if(Array.isArray(e))for(let o=e.length-1;o>=0;o--){const n=e[o];A(n,t)}else A(e,t);if(o)y();else S()};if(o)document.addEventListener("qsymbol",e=>{const{symbol:n,href:t}=e.detail;if(t){const e=n.slice(n.lastIndexOf("_")+1);I(e,1)}});let J;let L;const N=(e,n)=>({m:e,M:i.test(e)?l:u,$:n,o:1,v:performance.now(),k:0,q:0});const O=e=>{const n=/* @__PURE__ */new Map;let t=0;while(t<e.length){const o=e[t++];const s=[];let c;let r=1;while(c=e[t],typeof c==="number"){if(c<0)r=-c/10;else s.push({m:e[c],p:r,h:1});t++}n.set(o,s)}return n};const R=e=>{let n=m.get(e);if(!n){let t;if(L){t=L.get(e);if(!t)return;if(!t.length)t=void 0}n=N(e,t);m.set(e,n)}return n};const U=(e,t,s)=>{if(s)if("P"in s)c.t=s["P"];if(!o||e==null)return;J=e;if(t)t.then(e=>e.text()).then(e=>{L=O(JSON.parse(e));const t=[];for(const[n,c]of L.entries()){const e=R(n);e.$=c;if(e.o<1){t.push([e,e.o]);e.o=1}}if(!t.length){h();return}let o=0;const s=n(()=>{const e=performance.now()+f;while(o<t.length){const[n,c]=t[o];o++;j(n,c);if(o<t.length&&performance.now()>=e){s();return}}h()});s()}).catch(console.warn)};export{O as g,U as l,I as p};
1
+ import{isServer as e}from"@qwik.dev/core/build";const n=e=>{let n;if(typeof MessageChannel!=="undefined"){const t=new MessageChannel;let o=1;t.port1.onmessage=()=>e();n=()=>{if(o)t.port2.postMessage(null)};n.t=()=>{if(o){o=0;t.port1.onmessage=null;t.port1.close();t.port2.close()}}}else n=()=>setTimeout(e);return n};const t=typeof document!=="undefined";const o=!e&&t;const s=o?document:void 0;const c={o:25};const r=o&&s.createElement("link").relList?.supports?.("modulepreload")?"modulePreload":"preload";const i=/\.[mc]?js$/;const f=10;const l=0;const a=1;const $=2;const u=3;const d=4;const m=/* @__PURE__ */new Map;let p;let b=0;const w=[];const h=n(q);const y=n(S);let M=0;let P=0;let k=0;const v=[];const g=()=>{if(p){w.sort((e,n)=>e.i-n.i);p=0}};function q(){M=0;if(!w.length)return;g();const e=performance.now()+f;let n=0;while(w.length){const t=w[0];const o=t.i;const s=1-o;if(s>=.99||b<c.o){w.shift();T(t);if(performance.now()>=e){n=1;break}}else break}if(n&&w.length&&!M){M=1;h()}}const x=(e,n,t)=>{v.unshift({l:e,i:n,$:t})};const C=()=>{const e=v[v.length-1];const n=e.l;if(e.u){const t=e.m;if(t>=e.u.length){v.pop();return 0}const o=e.u[t];e.m=t+1;const s=R(o.p);if(s.i===0)return 1;const c=1-n.i;let r;if(c===1||c>=.99)r=Math.min(.01,1-o.h);else{const e=1-o.h*c;const n=o.M;const t=e/n;r=Math.max(.02,s.i*t);o.M=t}v.push({l:s,i:r,$:e.$});return 1}if(e.$?.has(n)){v.pop();return 0}const t=n.i;n.i=e.i;if(t-n.i<.01){v.pop();return 0}if(J!=null&&n.k<$){if(n.k===l){n.k=a;w.push(n)}p=1}if(n.u?.length){const t=e.$||/* @__PURE__ */new Set;t.add(n);e.$=t;e.u=n.u;e.m=0;return 0}v.pop();return 0};function S(){if(k||!v.length)return;P=0;k=1;const e=o?performance.now()+f:0;let n=0;while(v.length){n=1;const t=C();if(o&&t&&performance.now()>=e){if(!P){P=1;y()}break}}k=0;if(n&&o)h()}const T=e=>{if(e.k>=$)return;b++;const n=performance.now();e.v=n-e.q;e.k=$;const t=s.createElement("link");t.href=new URL(`${J}${e.p}`,s.baseURI).toString();t.rel=r;t.as="script";t.onload=t.onerror=()=>{b--;const o=performance.now();e.C=o-n;e.k=d;t.remove();h()};s.head.appendChild(t)};const j=(e,n,t)=>{x(e,n,t);if(o)y();else S()};const A=(e,n)=>{const t=R(e);if(t)x(t,n)};const I=(e,n)=>{if(!e?.length)return;const t=n?1-n:.4;if(Array.isArray(e))for(let o=e.length-1;o>=0;o--){const n=e[o];A(n,t)}else A(e,t);if(o)y();else S()};if(o)document.addEventListener("qsymbol",e=>{const{symbol:n,href:t}=e.detail;if(t){const e=n.slice(n.lastIndexOf("_")+1);I(e,1)}});let J;let L;const N=(e,n)=>({p:e,k:i.test(e)?l:u,u:n,i:1,q:performance.now(),v:0,C:0});const O=e=>{const n=/* @__PURE__ */new Map;let t=0;while(t<e.length){const o=e[t++];const s=[];let c;let r=1;while(c=e[t],typeof c==="number"){if(c<0)r=-c/10;else s.push({p:e[c],h:r,M:1});t++}n.set(o,s)}return n};const R=e=>{let n=m.get(e);if(!n){let t;if(L){t=L.get(e);if(!t)return;if(!t.length)t=void 0}n=N(e,t);m.set(e,n)}return n};const U=(e,t,s)=>{if(s)if("P"in s)c.o=s["P"];if(!o||e==null)return;J=e;if(t)t.then(e=>e.text()).then(e=>{L=O(JSON.parse(e));const t=[];for(const[n,c]of L.entries()){const e=R(n);e.u=c;if(e.i<1){t.push([e,e.i]);e.i=1}}if(!t.length){h();return}let o=0;const s=n(()=>{const e=performance.now()+f;while(o<t.length){const[n,c]=t[o];o++;j(n,c);if(o<t.length&&performance.now()>=e){s();return}}h()});s()}).catch(console.warn)};export{O as g,U as l,I as p};
package/dist/server.d.ts CHANGED
@@ -177,6 +177,13 @@ export declare interface RenderOptions extends SerializeDocumentOptions {
177
177
  qwikLoader?: QwikLoaderOptions;
178
178
  /** Specifies how preloading is handled. This ensures that code is instantly available when needed. */
179
179
  preloader?: PreloaderOptions | false;
180
+ /**
181
+ * Root-count threshold for eager yielded state prewarm during client resume.
182
+ *
183
+ * Defaults to `false`, keeping state fully lazy. Set to a number to enable eager prewarm when
184
+ * serialized state has at least that many roots.
185
+ */
186
+ statePrewarm?: number | false;
180
187
  /**
181
188
  * When set, the app is serialized into a fragment. And the returned html is not a complete
182
189
  * document. Defaults to `html`
package/dist/server.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * @qwik.dev/core/server 2.0.0-beta.37-dev+82dc74d
3
+ * @qwik.dev/core/server 2.0.0-beta.38-dev+0339f17
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
@@ -189,8 +189,8 @@ See https://qwik.dev/docs/core/tasks/#use-method-rules`,
189
189
  // 27
190
190
  "Cannot coerce a Signal, use `.value` instead",
191
191
  // 28
192
- "useComputed$ QRL {{0}} {{1}} cannot return a Promise",
193
- // 29
192
+ "",
193
+ // 29 (cleared: useComputed$ now supports async functions)
194
194
  `===
195
195
  Qwik version {{0}} already imported while importing {{1}}.
196
196
  This can lead to issues due to duplicated shared structures.
@@ -206,8 +206,14 @@ Verify that the Qwik libraries you're using are in "resolve.noExternal[]" and in
206
206
  // 33
207
207
  "Serialization Error: Cannot serialize function: {{0}}",
208
208
  // 34
209
- "Cannot read .value of a clientOnly async signal during SSR. Use .loading to check state, or provide an initial value."
209
+ "Cannot read .value of a clientOnly async signal during SSR. Use .loading to check state, or provide an initial value.",
210
210
  // 35
211
+ "Invalid element name for SSR {{0}}",
212
+ // 36
213
+ "Invalid serialized Promise dependency",
214
+ // 37
215
+ "Invalid serialized Uint8Array payload"
216
+ // 38
211
217
  ];
212
218
  let text = MAP[code] ?? "";
213
219
  if (parts.length) {
@@ -631,6 +637,7 @@ var QBaseAttr = "q:base";
631
637
  var QLocaleAttr = "q:locale";
632
638
  var QManifestHashAttr = "q:manifest-hash";
633
639
  var QInstanceAttr = "q:instance";
640
+ var QStatePrewarmAttr = "q:prewarm";
634
641
  var QContainerIsland = "q:container-island";
635
642
  var QContainerIslandEnd = "/" + QContainerIsland;
636
643
  var QIgnore = "q:ignore";
@@ -925,6 +932,7 @@ var stringifyRootRefPath = (path) => {
925
932
  };
926
933
  var writeStringRootRef = (writer, id) => writer.write(String(id));
927
934
  var writeStringRootRefPath = (writer, path) => writer.write(stringifyRootRefPath(path));
935
+ var writeStringRootRefDelta = (writer, id, base2) => writer.write(String(id - base2));
928
936
  var createStringStreamWriter = (write) => ({
929
937
  write,
930
938
  writeRootRef(id) {
@@ -932,6 +940,9 @@ var createStringStreamWriter = (write) => ({
932
940
  },
933
941
  writeRootRefPath(path) {
934
942
  return writeStringRootRefPath(this, path);
943
+ },
944
+ writeRootRefDelta(id, base2) {
945
+ return writeStringRootRefDelta(this, id, base2);
935
946
  }
936
947
  });
937
948
 
@@ -1680,6 +1691,10 @@ var renderSSRChunks = (chunks, remap) => {
1680
1691
  const chunk = chunks[i];
1681
1692
  if (typeof chunk === "string") {
1682
1693
  out += chunk;
1694
+ } else if (chunk.type === "root-ref-delta") {
1695
+ const id = remap ? remap[chunk.localId] ?? chunk.localId : chunk.localId;
1696
+ const base2 = remap ? remap[chunk.localBaseId] ?? chunk.localBaseId : chunk.localBaseId;
1697
+ out += String(id - base2);
1683
1698
  } else {
1684
1699
  const localId = chunk.type === "root-ref" ? chunk.localId : chunk.localPath[0];
1685
1700
  out += String(remap ? remap[localId] ?? localId : localId);
@@ -1705,6 +1720,9 @@ var StringSSRWriter = class {
1705
1720
  writeRootRefPath(path) {
1706
1721
  writeStringRootRefPath(this, path);
1707
1722
  }
1723
+ writeRootRefDelta(id, base2) {
1724
+ writeStringRootRefDelta(this, id, base2);
1725
+ }
1708
1726
  clear() {
1709
1727
  this.buffer.length = 0;
1710
1728
  }
@@ -1723,6 +1741,9 @@ var StringBufferSegmentWriter = class {
1723
1741
  writeRootRefPath(path) {
1724
1742
  this.chunks.push({ type: "root-ref-path", localPath: path });
1725
1743
  }
1744
+ writeRootRefDelta(id, base2) {
1745
+ this.chunks.push({ type: "root-ref-delta", localId: id, localBaseId: base2 });
1746
+ }
1726
1747
  clear() {
1727
1748
  this.chunks.length = 0;
1728
1749
  }
@@ -2078,7 +2099,7 @@ function getBuildBase(opts) {
2078
2099
  return `${import.meta.env?.BASE_URL || "/"}build/`;
2079
2100
  }
2080
2101
  var versions = {
2081
- qwik: "2.0.0-beta.37-dev+82dc74d",
2102
+ qwik: "2.0.0-beta.38-dev+0339f17",
2082
2103
  qwikDom: "2.1.19"
2083
2104
  };
2084
2105
 
@@ -2178,6 +2199,7 @@ function encodeAsAlphanumeric(value) {
2178
2199
  }
2179
2200
 
2180
2201
  // packages/qwik/src/server/ssr-container.ts
2202
+ var VALID_ELEMENT_NAME = /^[A-Za-z][A-Za-z0-9._:-]*$/;
2181
2203
  var NO_SCRIPT_HERE_ELEMENTS = /* @__PURE__ */ new Set([
2182
2204
  "script",
2183
2205
  "style",
@@ -2567,6 +2589,12 @@ var SSRContainer = class extends _SharedContainer {
2567
2589
  containerAttributes[QLocaleAttr] = this.$locale$;
2568
2590
  containerAttributes[QManifestHashAttr] = this.resolvedManifest.manifest.manifestHash;
2569
2591
  containerAttributes[QInstanceAttr] = this.$instanceHash$;
2592
+ const statePrewarm = this.renderOptions.statePrewarm;
2593
+ if (typeof statePrewarm === "number") {
2594
+ containerAttributes[QStatePrewarmAttr] = String(statePrewarm);
2595
+ } else {
2596
+ delete containerAttributes[QStatePrewarmAttr];
2597
+ }
2570
2598
  this.$serverData$.containerAttributes = containerAttributes;
2571
2599
  this.openElement(this.tag, null, containerAttributes);
2572
2600
  if (!this.isHtml) {
@@ -2580,6 +2608,9 @@ var SSRContainer = class extends _SharedContainer {
2580
2608
  $noScriptHere$ = 0;
2581
2609
  /** Renders opening tag for DOM element */
2582
2610
  openElement(elementName, key, varAttrs, constAttrs = null, styleScopedId = null, currentFile = null, hasMovedCaptures = true) {
2611
+ if (!VALID_ELEMENT_NAME.test(elementName)) {
2612
+ throw qError(36 /* invalidElementName */, [JSON.stringify(elementName)]);
2613
+ }
2583
2614
  const isQwikStyle = isQwikStyleElement(elementName, varAttrs) || isQwikStyleElement(elementName, constAttrs);
2584
2615
  if (NO_SCRIPT_HERE_ELEMENTS.has(elementName)) {
2585
2616
  this.$noScriptHere$++;
@@ -2618,7 +2649,9 @@ var SSRContainer = class extends _SharedContainer {
2618
2649
  }
2619
2650
  this.write(" " + Q_PROPS_SEPARATOR);
2620
2651
  if (key !== null) {
2621
- this.write(`="${key}"`);
2652
+ this.write(ATTR_EQUALS_QUOTE);
2653
+ this.write(escapeHTML(key));
2654
+ this.write(QUOTE);
2622
2655
  } else if (qTest) {
2623
2656
  this.write(EMPTY_ATTR);
2624
2657
  }
@@ -3091,6 +3124,7 @@ var SSRContainer = class extends _SharedContainer {
3091
3124
  this.write(VNodeDataChar.CONTEXT_CHAR);
3092
3125
  break;
3093
3126
  case QSlot:
3127
+ encodeValue = encodeVNodeDataKey;
3094
3128
  this.write(VNodeDataChar.SLOT_CHAR);
3095
3129
  break;
3096
3130
  default: {
@@ -3114,7 +3148,7 @@ var SSRContainer = class extends _SharedContainer {
3114
3148
  }
3115
3149
  }
3116
3150
  emitStateData() {
3117
- if (!this.serializationCtx.$roots$.length) {
3151
+ if (!this.serializationCtx.$roots$.length && !this.serializationCtx.$eagerResume$.size) {
3118
3152
  return;
3119
3153
  }
3120
3154
  const attrs = this.stateScriptAttrs();
@@ -3181,7 +3215,7 @@ var SSRContainer = class extends _SharedContainer {
3181
3215
  if (this.renderOptions.serverData?.nonce) {
3182
3216
  scriptAttrs["nonce"] = this.renderOptions.serverData.nonce;
3183
3217
  }
3184
- this.writeScript(scriptAttrs, JSON.stringify(patches));
3218
+ this.writeScript(scriptAttrs, JSON.stringify(patches).replaceAll("<", "\\u003C"));
3185
3219
  }
3186
3220
  }
3187
3221
  emitBackpatchDataAndExecutorIfNeeded() {
@@ -3415,6 +3449,11 @@ var SSRContainer = class extends _SharedContainer {
3415
3449
  this.size += 1 + String(path[i]).length;
3416
3450
  }
3417
3451
  }
3452
+ writeRootRefDelta(id, base2) {
3453
+ const delta = id - base2;
3454
+ this.size += String(delta).length;
3455
+ this.writer.writeRootRefDelta(id, base2);
3456
+ }
3418
3457
  writeArray(array, separator) {
3419
3458
  for (let i = 0; i < array.length; i++) {
3420
3459
  const element = array[i];
@@ -3526,6 +3565,8 @@ var SSRContainer = class extends _SharedContainer {
3526
3565
  this.write(escapeHTML(chunk));
3527
3566
  } else if (typeof chunk === "number") {
3528
3567
  this.writeRootRef(chunk);
3568
+ } else if ("base" in chunk) {
3569
+ this.writeRootRefDelta(chunk.id, chunk.base);
3529
3570
  } else {
3530
3571
  this.writeRootRefPath(chunk.path);
3531
3572
  }