@qwik.dev/core 2.0.0-alpha.8 → 2.0.0-beta.1

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.
Files changed (92) hide show
  1. package/bindings/qwik.darwin-arm64.node +0 -0
  2. package/bindings/qwik.darwin-x64.node +0 -0
  3. package/bindings/qwik.linux-x64-gnu.node +0 -0
  4. package/bindings/qwik.wasm.cjs +27 -27
  5. package/bindings/qwik.wasm.mjs +27 -27
  6. package/bindings/qwik.win32-x64-msvc.node +0 -0
  7. package/bindings/qwik_wasm_bg.wasm +0 -0
  8. package/dist/build/index.cjs +3 -3
  9. package/dist/build/index.d.ts +22 -22
  10. package/dist/build/package.json +1 -1
  11. package/dist/cli.cjs +6 -6
  12. package/dist/core-internal.d.ts +4447 -3941
  13. package/dist/core.cjs +7974 -7742
  14. package/dist/core.cjs.map +1 -1
  15. package/dist/core.min.mjs +1 -1
  16. package/dist/core.mjs +7960 -7738
  17. package/dist/core.mjs.map +1 -1
  18. package/dist/core.prod.cjs +3839 -3777
  19. package/dist/core.prod.mjs +4183 -4168
  20. package/dist/insights/index.qwik.cjs +1 -4260
  21. package/dist/insights/index.qwik.mjs +63 -4251
  22. package/dist/insights/vite/index.cjs +1 -82
  23. package/dist/insights/vite/index.mjs +65 -37
  24. package/dist/insights/vite.d.ts +22 -0
  25. package/dist/{insights/insights.d.ts → insights.d.ts} +33 -22
  26. package/dist/loader/index.cjs +2 -2
  27. package/dist/loader/index.mjs +2 -2
  28. package/dist/loader/package.json +1 -1
  29. package/dist/optimizer.cjs +599 -370
  30. package/dist/optimizer.d.ts +779 -707
  31. package/dist/optimizer.mjs +595 -414
  32. package/dist/preloader.cjs +269 -0
  33. package/dist/preloader.mjs +198 -0
  34. package/dist/qwikloader.debug.js +242 -222
  35. package/dist/qwikloader.js +1 -3
  36. package/dist/server.cjs +676 -574
  37. package/dist/server.d.ts +504 -402
  38. package/dist/server.mjs +647 -549
  39. package/dist/starters/adapters/aws-lambda/serverless.yml +15 -0
  40. package/dist/starters/adapters/aws-lambda/src/entry_aws-lambda.tsx +0 -2
  41. package/dist/starters/adapters/azure-swa/public/staticwebapp.config.json +7 -0
  42. package/dist/starters/adapters/azure-swa/src/entry.azure-swa.tsx +1 -2
  43. package/dist/starters/adapters/bun/src/entry.bun.ts +3 -2
  44. package/dist/starters/adapters/cloud-run/src/entry.cloud-run.tsx +1 -3
  45. package/dist/starters/adapters/cloudflare-pages/public/_headers +2 -0
  46. package/dist/starters/adapters/cloudflare-pages/src/entry.cloudflare-pages.tsx +1 -2
  47. package/dist/starters/adapters/deno/src/entry.deno.ts +3 -2
  48. package/dist/starters/adapters/express/src/entry.express.tsx +5 -2
  49. package/dist/starters/adapters/fastify/src/entry.fastify.tsx +2 -1
  50. package/dist/starters/adapters/fastify/src/plugins/fastify-qwik.ts +9 -1
  51. package/dist/starters/adapters/firebase/firebase.json +12 -1
  52. package/dist/starters/adapters/firebase/functions/index.js +2 -3
  53. package/dist/starters/adapters/firebase/src/entry-firebase.tsx +1 -2
  54. package/dist/starters/adapters/netlify-edge/public/_headers +2 -0
  55. package/dist/starters/adapters/netlify-edge/src/entry.netlify-edge.tsx +1 -2
  56. package/dist/starters/adapters/node-server/src/entry.node-server.tsx +3 -2
  57. package/dist/starters/adapters/static/README.md +4 -0
  58. package/dist/starters/adapters/vercel-edge/src/entry.vercel-edge.tsx +1 -2
  59. package/dist/starters/adapters/vercel-edge/vercel.json +1 -1
  60. package/dist/starters/features/auth/package.json +1 -1
  61. package/dist/starters/features/bootstrap/src/routes/bootstrap/layout.tsx +0 -11
  62. package/dist/starters/features/localize/src/entry.ssr.tsx +0 -2
  63. package/dist/starters/features/localize/src/routes/[locale]/i18n-utils.ts +1 -1
  64. package/dist/starters/features/partytown/package.json +4 -4
  65. package/dist/starters/features/partytown/src/components/partytown/partytown.tsx +2 -2
  66. package/dist/starters/features/postcss/postcss.config.js +1 -1
  67. package/dist/starters/features/service-worker/package.json +13 -0
  68. package/dist/starters/features/service-worker/src/routes/service-worker.ts +14 -0
  69. package/dist/starters/features/styled-vanilla-extract/package.json +2 -1
  70. package/dist/starters/features/tailwind/package.json +4 -3
  71. package/dist/starters/features/tailwind/src/global.css +1 -1
  72. package/dist/starters/features/tailwind-v3/.vscode/settings.json +3 -0
  73. package/dist/starters/features/tailwind-v3/package.json +21 -0
  74. package/dist/starters/features/tailwind-v3/postcss.config.cjs +6 -0
  75. package/dist/starters/features/tailwind-v3/src/global.css +7 -0
  76. package/dist/starters/features/tailwind-v3/tailwind.config.js +8 -0
  77. package/dist/testing/index.cjs +8390 -8048
  78. package/dist/testing/index.d.ts +141 -140
  79. package/dist/testing/index.mjs +8378 -8044
  80. package/dist/testing/package.json +1 -1
  81. package/package.json +19 -11
  82. package/public.d.ts +10 -0
  83. package/server.d.ts +1 -0
  84. package/dist/insights/index.d.ts +0 -1
  85. package/dist/insights/vite/index.d.ts +0 -1
  86. package/dist/insights/vite/insights-plugin.d.ts +0 -10
  87. package/dist/prefetch/index.cjs +0 -4
  88. package/dist/prefetch/index.d.ts +0 -2
  89. package/dist/prefetch/index.mjs +0 -3
  90. package/dist/prefetch/package.json +0 -8
  91. package/dist/qwik-prefetch.debug.js +0 -244
  92. package/dist/qwik-prefetch.js +0 -1
package/dist/server.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * @qwik.dev/core/server 2.0.0-alpha.8-dev+66037b5
3
+ * @qwik.dev/core/server 2.0.0-beta.1-dev+495e8d9
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
@@ -37,7 +37,7 @@ var throwErrorAndStop = (message, ...optionalParams) => {
37
37
  throw error;
38
38
  };
39
39
  var logErrorAndStop = (message, ...optionalParams) => {
40
- const err = createAndLogError(true, message, ...optionalParams);
40
+ const err = createAndLogError(qDev, message, ...optionalParams);
41
41
  debugger;
42
42
  return err;
43
43
  };
@@ -126,99 +126,69 @@ var codeToText = (code, ...parts) => {
126
126
  // 2
127
127
  "Only primitive and object literals can be serialized. {{0}}",
128
128
  // 3
129
- "",
130
- // 4 unused
131
129
  "You can render over a existing q:container. Skipping render().",
132
- // 5
133
- "",
134
- // 6 unused
135
- "",
136
- // 7 unused
137
- "",
138
- // 8 unused
139
- "",
140
- // 9 unused
130
+ // 4
141
131
  "QRL is not a function",
142
- // 10
132
+ // 5
143
133
  "Dynamic import not found",
144
- // 11
134
+ // 6
145
135
  "Unknown type argument",
146
- // 12
136
+ // 7
147
137
  `Actual value for useContext({{0}}) can not be found, make sure some ancestor component has set a value using useContextProvider(). In the browser make sure that the context was used during SSR so its state was serialized.`,
148
- // 13
138
+ // 8
149
139
  "Invoking 'use*()' method outside of invocation context.",
150
- // 14
151
- "",
152
- // 15 unused
153
- "",
154
- // 16 unused
155
- "",
156
- // 17 unused
157
- "",
158
- // 18 unused
159
- "",
160
- // 19 unused
140
+ // 9
161
141
  `Calling a 'use*()' method outside 'component$(() => { HERE })' is not allowed. 'use*()' methods provide hooks to the 'component$' state and lifecycle, ie 'use' hooks can only be called synchronously within the 'component$' function or another 'use' method.
162
142
  See https://qwik.dev/docs/components/tasks/#use-method-rules`,
163
- // 20
164
- "",
165
- // 21 unused
166
- "",
167
- // 22 unused
168
- "",
169
- // 23 unused
170
- "",
171
- // 24 unused
172
- "",
173
- // 25 unused
174
- "",
175
- // 26 unused
176
- "",
177
- // 27 unused
143
+ // 10
178
144
  'The provided Context reference "{{0}}" is not a valid context created by createContextId()',
179
- // 28
145
+ // 11
180
146
  "SsrError(tag): {{0}}",
181
- // 29
147
+ // 12
182
148
  "QRLs can not be resolved because it does not have an attached container. This means that the QRL does not know where it belongs inside the DOM, so it cant dynamically import() from a relative path.",
183
- // 30
149
+ // 13
184
150
  "QRLs can not be dynamically resolved, because it does not have a chunk path",
185
- // 31
151
+ // 14
186
152
  "{{0}}\nThe JSX ref attribute must be a Signal",
187
- // 32
153
+ // 15
188
154
  "Serialization Error: Deserialization of data type {{0}} is not implemented",
189
- // 33
155
+ // 16
190
156
  "Serialization Error: Expected vnode for ref prop, but got {{0}}",
191
- // 34
157
+ // 17
192
158
  "Serialization Error: Cannot allocate data type {{0}}",
193
- // 35
159
+ // 18
194
160
  "Serialization Error: Missing root id for {{0}}",
195
- // 36
161
+ // 19
196
162
  "Serialization Error: Serialization of data type {{0}} is not implemented",
197
- // 37
163
+ // 20
198
164
  "Serialization Error: Unvisited {{0}}",
199
- // 38
165
+ // 21
200
166
  "Serialization Error: Missing QRL chunk for {{0}}",
201
- // 39
167
+ // 22
202
168
  "{{0}}\nThe value of the textarea must be a string found {{1}}",
203
- // 40
169
+ // 23
204
170
  "Unable to find q:container",
205
- // 41
171
+ // 24
206
172
  "Element must have 'q:container' attribute.",
207
- // 42
173
+ // 25
208
174
  "Unknown vnode type {{0}}.",
209
- // 43
175
+ // 26
210
176
  "Materialize error: missing element: {{0}} {{1}} {{2}}",
211
- // 44
177
+ // 27
212
178
  "Cannot coerce a Signal, use `.value` instead",
213
- // 45
214
- "useComputedSignal$ QRL {{0}} {{1}} returned a Promise",
215
- // 46
179
+ // 28
180
+ "useComputed$ QRL {{0}} {{1}} cannot return a Promise",
181
+ // 29
216
182
  "ComputedSignal is read-only",
217
- // 47
183
+ // 30
218
184
  "WrappedSignal is read-only",
219
- // 48
220
- "Attribute value is unsafe for SSR"
221
- // 49
185
+ // 31
186
+ "Attribute value is unsafe for SSR",
187
+ // 32
188
+ "SerializerSymbol function returned rejected promise",
189
+ // 33
190
+ "Serialization Error: Cannot serialize function: {{0}}"
191
+ // 34
222
192
  ];
223
193
  let text = MAP[code] ?? "";
224
194
  if (parts.length) {
@@ -246,45 +216,6 @@ var SYNC_QRL = "<sync>";
246
216
 
247
217
  // packages/qwik/src/core/shared/types.ts
248
218
  var DEBUG_TYPE = "q:type";
249
- var START = "\x1B[34m";
250
- var END = "\x1B[0m";
251
- var VirtualTypeName = {
252
- ["V" /* Virtual */]: (
253
- /* ********* */
254
- START + "Virtual" + END
255
- ),
256
- //
257
- ["F" /* Fragment */]: (
258
- /* ******** */
259
- START + "Fragment" + END
260
- ),
261
- //
262
- ["S" /* WrappedSignal */]: (
263
- /* *** */
264
- START + "Signal" + END
265
- ),
266
- //
267
- ["A" /* Awaited */]: (
268
- /* ********* */
269
- START + "Awaited" + END
270
- ),
271
- //
272
- ["C" /* Component */]: (
273
- /* ******* */
274
- START + "Component" + END
275
- ),
276
- //
277
- ["I" /* InlineComponent */]: (
278
- /* * */
279
- START + "InlineComponent" + END
280
- ),
281
- //
282
- ["P" /* Projection */]: (
283
- /* ****** */
284
- START + "Projection" + END
285
- )
286
- //
287
- };
288
219
 
289
220
  // packages/qwik/src/core/shared/utils/character-escaping.ts
290
221
  function escapeHTML(html) {
@@ -359,6 +290,7 @@ var Q_PROPS_SEPARATOR = ":";
359
290
  var dangerouslySetInnerHTML = "dangerouslySetInnerHTML";
360
291
 
361
292
  // packages/qwik/src/core/shared/utils/promises.ts
293
+ import { isDev as isDev2, isServer } from "@qwik.dev/core/build";
362
294
  var isPromise = (value) => {
363
295
  return !!value && typeof value == "object" && typeof value.then === "function";
364
296
  };
@@ -816,12 +748,282 @@ var VNodeDataChar = {
816
748
  )
817
749
  };
818
750
 
819
- // packages/qwik/src/optimizer/src/manifest.ts
820
- function getValidManifest(manifest) {
821
- if (manifest != null && manifest.mapping != null && typeof manifest.mapping === "object" && manifest.symbols != null && typeof manifest.symbols === "object" && manifest.bundles != null && typeof manifest.bundles === "object") {
822
- return manifest;
751
+ // packages/qwik/src/core/preloader/queue.ts
752
+ import { isBrowser as isBrowser3 } from "@qwik.dev/core/build";
753
+
754
+ // packages/qwik/src/core/preloader/bundle-graph.ts
755
+ import { isBrowser as isBrowser2 } from "@qwik.dev/core/build";
756
+
757
+ // packages/qwik/src/core/preloader/constants.ts
758
+ import { isBrowser } from "@qwik.dev/core/build";
759
+ var doc = isBrowser ? document : void 0;
760
+ var config = {
761
+ $DEBUG$: false,
762
+ $maxIdlePreloads$: 25,
763
+ $invPreloadProbability$: 0.65
764
+ };
765
+ var rel = isBrowser && doc.createElement("link").relList.supports("modulepreload") ? "modulePreload" : "preload";
766
+ var loadStart = Date.now();
767
+ var isJSRegex = /\.[mc]?js$/;
768
+
769
+ // packages/qwik/src/core/preloader/types.ts
770
+ var BundleImportState_None = 0;
771
+ var BundleImportState_Queued = 1;
772
+ var BundleImportState_Preload = 2;
773
+ var BundleImportState_Alias = 3;
774
+ var BundleImportState_Loaded = 4;
775
+
776
+ // packages/qwik/src/core/preloader/bundle-graph.ts
777
+ var base;
778
+ var graph;
779
+ var makeBundle = (name, deps) => {
780
+ return {
781
+ $name$: name,
782
+ $state$: isJSRegex.test(name) ? BundleImportState_None : BundleImportState_Alias,
783
+ $deps$: shouldResetFactor ? deps?.map((d) => ({ ...d, $factor$: 1 })) : deps,
784
+ $inverseProbability$: 1,
785
+ $createdTs$: Date.now(),
786
+ $waitedMs$: 0,
787
+ $loadedMs$: 0
788
+ };
789
+ };
790
+ var parseBundleGraph = (serialized) => {
791
+ const graph2 = /* @__PURE__ */ new Map();
792
+ let i = 0;
793
+ while (i < serialized.length) {
794
+ const name = serialized[i++];
795
+ const deps = [];
796
+ let idx;
797
+ let probability = 1;
798
+ while (idx = serialized[i], typeof idx === "number") {
799
+ if (idx < 0) {
800
+ probability = -idx / 10;
801
+ } else {
802
+ deps.push({
803
+ $name$: serialized[idx],
804
+ $importProbability$: probability,
805
+ $factor$: 1
806
+ });
807
+ }
808
+ i++;
809
+ }
810
+ graph2.set(name, deps);
823
811
  }
824
- return void 0;
812
+ return graph2;
813
+ };
814
+ var getBundle = (name) => {
815
+ let bundle = bundles.get(name);
816
+ if (!bundle) {
817
+ let deps;
818
+ if (graph) {
819
+ deps = graph.get(name);
820
+ if (!deps) {
821
+ return;
822
+ }
823
+ if (!deps.length) {
824
+ deps = void 0;
825
+ }
826
+ }
827
+ bundle = makeBundle(name, deps);
828
+ bundles.set(name, bundle);
829
+ }
830
+ return bundle;
831
+ };
832
+ var initPreloader = (serializedBundleGraph, opts) => {
833
+ if (opts) {
834
+ if ("debug" in opts) {
835
+ config.$DEBUG$ = !!opts.debug;
836
+ }
837
+ if (typeof opts.preloadProbability === "number") {
838
+ config.$invPreloadProbability$ = 1 - opts.preloadProbability;
839
+ }
840
+ }
841
+ if (base != null || !serializedBundleGraph) {
842
+ return;
843
+ }
844
+ base = "";
845
+ graph = parseBundleGraph(serializedBundleGraph);
846
+ };
847
+
848
+ // packages/qwik/src/core/preloader/queue.ts
849
+ var bundles = /* @__PURE__ */ new Map();
850
+ var shouldResetFactor;
851
+ var queueDirty;
852
+ var preloadCount = 0;
853
+ var queue = [];
854
+ var log = (...args) => {
855
+ console.log(
856
+ `Preloader ${Date.now() - loadStart}ms ${preloadCount}/${queue.length} queued>`,
857
+ ...args
858
+ );
859
+ };
860
+ var resetQueue = () => {
861
+ bundles.clear();
862
+ queueDirty = false;
863
+ shouldResetFactor = true;
864
+ preloadCount = 0;
865
+ queue.length = 0;
866
+ };
867
+ var sortQueue = () => {
868
+ if (queueDirty) {
869
+ queue.sort((a, b) => a.$inverseProbability$ - b.$inverseProbability$);
870
+ queueDirty = false;
871
+ }
872
+ };
873
+ var getQueue = () => {
874
+ sortQueue();
875
+ let probability = 0.4;
876
+ const result = [];
877
+ for (const b of queue) {
878
+ const nextProbability = Math.round((1 - b.$inverseProbability$) * 10);
879
+ if (nextProbability !== probability) {
880
+ probability = nextProbability;
881
+ result.push(probability);
882
+ }
883
+ result.push(b.$name$);
884
+ }
885
+ return result;
886
+ };
887
+ var trigger = () => {
888
+ if (!queue.length) {
889
+ return;
890
+ }
891
+ sortQueue();
892
+ while (queue.length) {
893
+ const bundle = queue[0];
894
+ const inverseProbability = bundle.$inverseProbability$;
895
+ const probability = 1 - inverseProbability;
896
+ const allowedPreloads = graph ? (
897
+ // The more likely the bundle, the more simultaneous preloads we want to allow
898
+ Math.max(1, config.$maxIdlePreloads$ * probability)
899
+ ) : (
900
+ // While the graph is not available, we limit to 2 preloads
901
+ 2
902
+ );
903
+ if (probability >= 0.99 || preloadCount < allowedPreloads) {
904
+ queue.shift();
905
+ preloadOne(bundle);
906
+ } else {
907
+ break;
908
+ }
909
+ }
910
+ if (config.$DEBUG$ && !queue.length) {
911
+ const loaded = [...bundles.values()].filter((b) => b.$state$ > BundleImportState_None);
912
+ const waitTime = loaded.reduce((acc, b) => acc + b.$waitedMs$, 0);
913
+ const loadTime = loaded.reduce((acc, b) => acc + b.$loadedMs$, 0);
914
+ log(
915
+ `>>>> done ${loaded.length}/${bundles.size} total: ${waitTime}ms waited, ${loadTime}ms loaded`
916
+ );
917
+ }
918
+ };
919
+ var preloadOne = (bundle) => {
920
+ if (bundle.$state$ >= BundleImportState_Preload) {
921
+ return;
922
+ }
923
+ preloadCount++;
924
+ const start = Date.now();
925
+ bundle.$waitedMs$ = start - bundle.$createdTs$;
926
+ bundle.$state$ = BundleImportState_Preload;
927
+ config.$DEBUG$ && log(
928
+ `<< load ${Math.round((1 - bundle.$inverseProbability$) * 100)}% after ${`${bundle.$waitedMs$}ms`}`,
929
+ bundle.$name$
930
+ );
931
+ const link = doc.createElement("link");
932
+ link.href = new URL(`${base}${bundle.$name$}`, doc.baseURI).toString();
933
+ link.rel = rel;
934
+ link.as = "script";
935
+ link.onload = link.onerror = () => {
936
+ preloadCount--;
937
+ const end = Date.now();
938
+ bundle.$loadedMs$ = end - start;
939
+ bundle.$state$ = BundleImportState_Loaded;
940
+ config.$DEBUG$ && log(`>> done after ${bundle.$loadedMs$}ms`, bundle.$name$);
941
+ link.remove();
942
+ trigger();
943
+ };
944
+ doc.head.appendChild(link);
945
+ };
946
+ var adjustProbabilities = (bundle, newInverseProbability, seen) => {
947
+ if (seen?.has(bundle)) {
948
+ return;
949
+ }
950
+ const previousInverseProbability = bundle.$inverseProbability$;
951
+ bundle.$inverseProbability$ = newInverseProbability;
952
+ if (previousInverseProbability - bundle.$inverseProbability$ < 0.01) {
953
+ return;
954
+ }
955
+ if (
956
+ // don't queue until we have initialized the preloader
957
+ base != null && bundle.$state$ < BundleImportState_Preload && bundle.$inverseProbability$ < config.$invPreloadProbability$
958
+ ) {
959
+ if (bundle.$state$ === BundleImportState_None) {
960
+ bundle.$state$ = BundleImportState_Queued;
961
+ queue.push(bundle);
962
+ config.$DEBUG$ && log(`queued ${Math.round((1 - bundle.$inverseProbability$) * 100)}%`, bundle.$name$);
963
+ }
964
+ queueDirty = true;
965
+ }
966
+ if (bundle.$deps$) {
967
+ seen || (seen = /* @__PURE__ */ new Set());
968
+ seen.add(bundle);
969
+ const probability = 1 - bundle.$inverseProbability$;
970
+ for (const dep of bundle.$deps$) {
971
+ const depBundle = getBundle(dep.$name$);
972
+ if (depBundle.$inverseProbability$ === 0) {
973
+ continue;
974
+ }
975
+ let newInverseProbability2;
976
+ if (dep.$importProbability$ > 0.5 && (probability === 1 || probability >= 0.99 && depsCount < 100)) {
977
+ depsCount++;
978
+ newInverseProbability2 = Math.min(0.01, 1 - dep.$importProbability$);
979
+ } else {
980
+ const newInverseImportProbability = 1 - dep.$importProbability$ * probability;
981
+ const prevAdjust = dep.$factor$;
982
+ const factor = newInverseImportProbability / prevAdjust;
983
+ newInverseProbability2 = Math.max(0.02, depBundle.$inverseProbability$ * factor);
984
+ dep.$factor$ = factor;
985
+ }
986
+ adjustProbabilities(depBundle, newInverseProbability2, seen);
987
+ }
988
+ }
989
+ };
990
+ var handleBundle = (name, inverseProbability) => {
991
+ const bundle = getBundle(name);
992
+ if (bundle && bundle.$inverseProbability$ > inverseProbability) {
993
+ adjustProbabilities(bundle, inverseProbability);
994
+ }
995
+ };
996
+ var depsCount;
997
+ var preload = (name, probability) => {
998
+ if (!name?.length) {
999
+ return;
1000
+ }
1001
+ depsCount = 0;
1002
+ let inverseProbability = probability ? 1 - probability : 0.4;
1003
+ if (Array.isArray(name)) {
1004
+ for (let i = name.length - 1; i >= 0; i--) {
1005
+ const item = name[i];
1006
+ if (typeof item === "number") {
1007
+ inverseProbability = 1 - item / 10;
1008
+ } else {
1009
+ handleBundle(item, inverseProbability);
1010
+ }
1011
+ }
1012
+ } else {
1013
+ handleBundle(name, inverseProbability);
1014
+ }
1015
+ if (isBrowser3) {
1016
+ trigger();
1017
+ }
1018
+ };
1019
+ if (isBrowser3) {
1020
+ document.addEventListener("qsymbol", (ev) => {
1021
+ const { symbol, href } = ev.detail;
1022
+ if (href) {
1023
+ const hash2 = symbol.slice(symbol.lastIndexOf("_") + 1);
1024
+ preload(hash2, 1);
1025
+ }
1026
+ });
825
1027
  }
826
1028
 
827
1029
  // packages/qwik/src/server/platform.ts
@@ -907,26 +1109,26 @@ function createTimer() {
907
1109
  };
908
1110
  }
909
1111
  function getBuildBase(opts) {
910
- let base = opts.base;
1112
+ let base2 = opts.base;
911
1113
  if (typeof opts.base === "function") {
912
- base = opts.base(opts);
1114
+ base2 = opts.base(opts);
913
1115
  }
914
- if (typeof base === "string") {
915
- if (!base.endsWith("/")) {
916
- base += "/";
1116
+ if (typeof base2 === "string") {
1117
+ if (!base2.endsWith("/")) {
1118
+ base2 += "/";
917
1119
  }
918
- return base;
1120
+ return base2;
919
1121
  }
920
- return `${import.meta.env.BASE_URL}build/`;
1122
+ return `${import.meta.env.BASE_URL || "/"}build/`;
921
1123
  }
922
- var versions2 = {
923
- qwik: "2.0.0-alpha.8-dev+66037b5",
1124
+ var versions = {
1125
+ qwik: "2.0.0-beta.1-dev+495e8d9",
924
1126
  qwikDom: "2.1.19"
925
1127
  };
926
1128
 
927
1129
  // packages/qwik/src/server/ssr-container.ts
928
1130
  import {
929
- _EffectData as EffectData,
1131
+ _SubscriptionData as SubscriptionData,
930
1132
  _SharedContainer,
931
1133
  _jsxSorted,
932
1134
  _jsxSplit,
@@ -935,237 +1137,16 @@ import {
935
1137
  } from "@qwik.dev/core";
936
1138
  import { isDev as isDev4 } from "@qwik.dev/core/build";
937
1139
 
938
- // packages/qwik/src/server/prefetch-utils.ts
939
- function workerFetchScript() {
940
- const fetch2 = `Promise.all(e.data.map(u=>fetch(u))).finally(()=>{setTimeout(postMessage({}),9999)})`;
941
- const workerBody = `onmessage=(e)=>{${fetch2}}`;
942
- const blob = `new Blob(['${workerBody}'],{type:"text/javascript"})`;
943
- const url = `URL.createObjectURL(${blob})`;
944
- let s = `const w=new Worker(${url});`;
945
- s += `w.postMessage(u.map(u=>new URL(u,origin)+''));`;
946
- s += `w.onmessage=()=>{w.terminate()};`;
947
- return s;
948
- }
949
- function prefetchUrlsEventScript(base, prefetchResources) {
950
- const data = {
951
- bundles: flattenPrefetchResources(prefetchResources).map((u) => u.split("/").pop())
952
- };
953
- const args = JSON.stringify(["prefetch", base, ...data.bundles]);
954
- return `document.dispatchEvent(new CustomEvent("qprefetch",{detail:${JSON.stringify(data)}}));
955
- (window.qwikPrefetchSW||(window.qwikPrefetchSW=[])).push(${args});`;
956
- }
957
- function flattenPrefetchResources(prefetchResources) {
958
- const urls = [];
959
- const addPrefetchResource = (prefetchResources2) => {
960
- if (Array.isArray(prefetchResources2)) {
961
- for (const prefetchResource of prefetchResources2) {
962
- if (!urls.includes(prefetchResource.url)) {
963
- urls.push(prefetchResource.url);
964
- addPrefetchResource(prefetchResource.imports);
965
- }
966
- }
967
- }
968
- };
969
- addPrefetchResource(prefetchResources);
970
- return urls;
971
- }
972
- function getMostReferenced(prefetchResources) {
973
- const common = /* @__PURE__ */ new Map();
974
- let total = 0;
975
- const addPrefetchResource = (prefetchResources2, visited2) => {
976
- if (Array.isArray(prefetchResources2)) {
977
- for (const prefetchResource of prefetchResources2) {
978
- const count = common.get(prefetchResource.url) || 0;
979
- common.set(prefetchResource.url, count + 1);
980
- total++;
981
- if (!visited2.has(prefetchResource.url)) {
982
- visited2.add(prefetchResource.url);
983
- addPrefetchResource(prefetchResource.imports, visited2);
984
- }
985
- }
986
- }
987
- };
988
- const visited = /* @__PURE__ */ new Set();
989
- for (const resource of prefetchResources) {
990
- visited.clear();
991
- addPrefetchResource(resource.imports, visited);
992
- }
993
- const threshold = total / common.size * 2;
994
- const urls = Array.from(common.entries());
995
- urls.sort((a, b) => b[1] - a[1]);
996
- return urls.slice(0, 5).filter((e) => e[1] > threshold).map((e) => e[0]);
997
- }
998
-
999
- // packages/qwik/src/server/prefetch-implementation.ts
1000
- function applyPrefetchImplementation2(container, prefetchStrategy, prefetchResources, nonce) {
1001
- const prefetchImpl = normalizePrefetchImplementation(prefetchStrategy?.implementation);
1002
- if (prefetchImpl.prefetchEvent === "always") {
1003
- prefetchUrlsEvent2(container, prefetchResources, nonce);
1004
- }
1005
- if (prefetchImpl.linkInsert === "html-append") {
1006
- linkHtmlImplementation2(container, prefetchResources, prefetchImpl);
1007
- }
1008
- if (prefetchImpl.linkInsert === "js-append") {
1009
- linkJsImplementation2(container, prefetchResources, prefetchImpl, nonce);
1010
- } else if (prefetchImpl.workerFetchInsert === "always") {
1011
- workerFetchImplementation2(container, prefetchResources, nonce);
1012
- }
1013
- }
1014
- function prefetchUrlsEvent2(container, prefetchResources, nonce) {
1015
- const mostReferenced = getMostReferenced(prefetchResources);
1016
- for (const url of mostReferenced) {
1017
- const attrs = ["rel", "modulepreload", "href", url];
1018
- if (nonce) {
1019
- attrs.push("nonce", nonce);
1020
- }
1021
- container.openElement("link", null, attrs);
1022
- container.closeElement();
1023
- }
1024
- const scriptAttrs = ["q:type", "prefetch-bundles"];
1025
- if (nonce) {
1026
- scriptAttrs.push("nonce", nonce);
1027
- }
1028
- container.openElement("script", null, scriptAttrs);
1029
- container.writer.write(prefetchUrlsEventScript(container.buildBase, prefetchResources));
1030
- container.writer.write(
1031
- `;document.dispatchEvent(new CustomEvent('qprefetch', {detail:{links: [location.pathname]}}))`
1032
- );
1033
- container.closeElement();
1034
- }
1035
- function linkHtmlImplementation2(container, prefetchResources, prefetchImpl) {
1036
- const urls = flattenPrefetchResources(prefetchResources);
1037
- const rel = prefetchImpl.linkRel || "prefetch";
1038
- const priority = prefetchImpl.linkFetchPriority;
1039
- for (const url of urls) {
1040
- const attributes = ["href", url, "rel", rel];
1041
- if (priority) {
1042
- attributes.push("fetchpriority", priority);
1043
- }
1044
- if (rel === "prefetch" || rel === "preload") {
1045
- if (url.endsWith(".js")) {
1046
- attributes.push("as", "script");
1047
- }
1048
- }
1049
- container.openElement("link", null, attributes);
1050
- container.closeElement();
1051
- }
1052
- }
1053
- function linkJsImplementation2(container, prefetchResources, prefetchImpl, nonce) {
1054
- const scriptAttrs = ["type", "module", "q:type", "link-js"];
1055
- if (nonce) {
1056
- scriptAttrs.push("nonce", nonce);
1057
- }
1058
- container.openElement("script", null, scriptAttrs);
1059
- const rel = prefetchImpl.linkRel || "prefetch";
1060
- const priority = prefetchImpl.linkFetchPriority;
1061
- if (prefetchImpl.workerFetchInsert === "no-link-support") {
1062
- container.writer.write(`let supportsLinkRel = true;`);
1063
- }
1064
- container.writer.write(`const u=${JSON.stringify(flattenPrefetchResources(prefetchResources))};`);
1065
- container.writer.write(`u.map((u,i)=>{`);
1066
- container.writer.write(`const l=document.createElement('link');`);
1067
- container.writer.write(`l.setAttribute("href",u);`);
1068
- container.writer.write(`l.setAttribute("rel","${rel}");`);
1069
- if (priority) {
1070
- container.writer.write(`l.setAttribute("fetchpriority","${priority}");`);
1071
- }
1072
- if (prefetchImpl.workerFetchInsert === "no-link-support") {
1073
- container.writer.write(`if(i===0){`);
1074
- container.writer.write(`try{`);
1075
- container.writer.write(`supportsLinkRel=l.relList.supports("${rel}");`);
1076
- container.writer.write(`}catch(e){}`);
1077
- container.writer.write(`}`);
1078
- }
1079
- container.writer.write(`document.body.appendChild(l);`);
1080
- container.writer.write(`});`);
1081
- if (prefetchImpl.workerFetchInsert === "no-link-support") {
1082
- container.writer.write(`if(!supportsLinkRel){`);
1083
- container.writer.write(workerFetchScript());
1084
- container.writer.write(`}`);
1085
- }
1086
- if (prefetchImpl.workerFetchInsert === "always") {
1087
- container.writer.write(workerFetchScript());
1088
- }
1089
- container.closeElement();
1090
- }
1091
- function workerFetchImplementation2(container, prefetchResources, nonce) {
1092
- const scriptAttrs = ["type", "module", "q:type", "prefetch-worker"];
1093
- if (nonce) {
1094
- scriptAttrs.push(nonce, "nonce");
1095
- }
1096
- container.openElement("script", null, scriptAttrs);
1097
- container.writer.write(`const u=${JSON.stringify(flattenPrefetchResources(prefetchResources))};`);
1098
- container.writer.write(workerFetchScript());
1099
- container.closeElement();
1100
- }
1101
- function normalizePrefetchImplementation(input) {
1102
- return { ...PrefetchImplementationDefault, ...input };
1103
- }
1104
- var PrefetchImplementationDefault = {
1105
- linkInsert: null,
1106
- linkRel: null,
1107
- linkFetchPriority: null,
1108
- workerFetchInsert: null,
1109
- prefetchEvent: "always"
1110
- };
1111
-
1112
- // packages/qwik/src/server/prefetch-strategy.ts
1113
- import { isDev as isDev2 } from "@qwik.dev/core/build";
1114
- function getPrefetchResources(qrls, opts, resolvedManifest) {
1115
- if (!resolvedManifest) {
1116
- return [];
1117
- }
1118
- const prefetchStrategy = opts.prefetchStrategy;
1119
- const buildBase = getBuildBase(opts);
1120
- if (prefetchStrategy !== null) {
1121
- if (!prefetchStrategy || !prefetchStrategy.symbolsToPrefetch || prefetchStrategy.symbolsToPrefetch === "auto") {
1122
- return getAutoPrefetch(qrls, resolvedManifest, buildBase);
1123
- }
1124
- if (typeof prefetchStrategy.symbolsToPrefetch === "function") {
1125
- try {
1126
- return prefetchStrategy.symbolsToPrefetch({ manifest: resolvedManifest.manifest });
1127
- } catch (e) {
1128
- console.error("getPrefetchUrls, symbolsToPrefetch()", e);
1129
- }
1130
- }
1131
- }
1132
- return [];
1133
- }
1134
- function getAutoPrefetch(qrls, resolvedManifest, buildBase) {
1135
- const prefetchResources = [];
1136
- const { mapper, manifest } = resolvedManifest;
1137
- const urls = /* @__PURE__ */ new Map();
1138
- if (mapper && manifest) {
1139
- for (const qrl of qrls) {
1140
- const qrlSymbolName = qrl.getHash();
1141
- const resolvedSymbol = mapper[qrlSymbolName];
1142
- if (resolvedSymbol) {
1143
- const bundleFileName = resolvedSymbol[1];
1144
- addBundle(manifest, urls, prefetchResources, buildBase, bundleFileName);
1145
- }
1146
- }
1147
- }
1148
- return prefetchResources;
1140
+ // packages/qwik/src/server/scripts.ts
1141
+ var QWIK_LOADER_DEFAULT_MINIFIED = 'const t=document,e=window,n=new Set,o=new Set([t]);let r;const s=(t,e)=>Array.from(t.querySelectorAll(e)),i=t=>{const e=[];return o.forEach((n=>e.push(...s(n,t)))),e},a=t=>{v(t),s(t,"[q\\\\:shadowroot]").forEach((t=>{const e=t.shadowRoot;e&&a(e)}))},c=t=>t&&"function"==typeof t.then;let l=!0;const f=(t,e,n=e.type)=>{let o=l;i("[on"+t+"\\\\:"+n+"]").forEach((r=>{o=!0,b(r,t,e,n)})),o||window[t.slice(1)].removeEventListener(n,"-window"===t?d:_)},p=e=>{if(void 0===e._qwikjson_){let n=(e===t.documentElement?t.body:e).lastElementChild;for(;n;){if("SCRIPT"===n.tagName&&"qwik/json"===n.getAttribute("type")){e._qwikjson_=JSON.parse(n.textContent.replace(/\\\\x3C(\\/?script)/gi,"<$1"));break}n=n.previousElementSibling}}},u=(t,e)=>new CustomEvent(t,{detail:e}),b=async(e,n,o,r=o.type)=>{const s="on"+n+":"+r;e.hasAttribute("preventdefault:"+r)&&o.preventDefault(),e.hasAttribute("stoppropagation:"+r)&&o.stopPropagation();const i=e._qc_,a=i&&i.li.filter((t=>t[0]===s));if(a&&a.length>0){for(const t of a){const n=t[1].getFn([e,o],(()=>e.isConnected))(o,e),r=o.cancelBubble;c(n)&&await n,r&&o.stopPropagation()}return}const l=e.getAttribute(s),f=e.qDispatchEvent;if(f)return f(o,n);if(l){const n=e.closest("[q\\\\:container]:not([q\\\\:container=html]):not([q\\\\:container=text])"),r=n.getAttribute("q:base"),s=n.getAttribute("q:version")||"unknown",i=n.getAttribute("q:manifest-hash")||"dev",a=new URL(r,t.baseURI);for(const f of l.split("\\n")){const l=new URL(f,a),u=l.href,b=l.hash.replace(/^#?([^?[|]*).*$/,"$1")||"default",h=performance.now();let _,d,w;const m=f.startsWith("#"),y={qBase:r,qManifest:i,qVersion:s,href:u,symbol:b,element:e,reqTime:h};if(m){const e=n.getAttribute("q:instance");_=(t["qFuncs_"+e]||[])[Number.parseInt(b)],_||(d="sync",w=Error("sym:"+b))}else{q("qsymbol",y);const t=l.href.split("#")[0];try{const e=import(t);p(n),_=(await e)[b],_||(d="no-symbol",w=Error(`${b} not in ${t}`))}catch(t){d||(d="async"),w=t}}if(!_){q("qerror",{importError:d,error:w,...y}),console.error(w);break}const v=t.__q_context__;if(e.isConnected)try{t.__q_context__=[e,o,l];const n=_(o,e);c(n)&&await n}catch(t){q("qerror",{error:t,...y})}finally{t.__q_context__=v}}}},q=(e,n)=>{t.dispatchEvent(u(e,n))},h=t=>t.replace(/([A-Z])/g,(t=>"-"+t.toLowerCase())),_=async t=>{let e=h(t.type),n=t.target;for(f("-document",t,e);n&&n.getAttribute;){const o=b(n,"",t,e);let r=t.cancelBubble;c(o)&&await o,r||(r=r||t.cancelBubble||n.hasAttribute("stoppropagation:"+t.type)),n=t.bubbles&&!0!==r?n.parentElement:null}},d=t=>{f("-window",t,h(t.type))},w=()=>{var s;const c=t.readyState;if(!r&&("interactive"==c||"complete"==c)&&(o.forEach(a),r=1,q("qinit"),(null!=(s=e.requestIdleCallback)?s:e.setTimeout).bind(e)((()=>q("qidle"))),n.has("qvisible"))){const t=i("[on\\\\:qvisible]"),e=new IntersectionObserver((t=>{for(const n of t)n.isIntersecting&&(e.unobserve(n.target),b(n.target,"",u("qvisible",n)))}));t.forEach((t=>e.observe(t)))}},m=(t,e,n,o=!1)=>{t.addEventListener(e,n,{capture:o,passive:!1})};let y;const v=(...t)=>{l=!0,clearTimeout(y),y=setTimeout((()=>l=!1),2e4);for(const r of t)"string"==typeof r?n.has(r)||(o.forEach((t=>m(t,r,_,!0))),m(e,r,d,!0),n.add(r)):o.has(r)||(n.forEach((t=>m(r,t,_,!0))),o.add(r))};if(!("__q_context__"in t)){t.__q_context__=0;const r=e.qwikevents;r&&(Array.isArray(r)?v(...r):v("click","input")),e.qwikevents={events:n,roots:o,push:v},m(t,"readystatechange",w),w()}';
1142
+ var QWIK_LOADER_DEFAULT_DEBUG = 'const doc = document;\nconst win = window;\nconst events = /* @__PURE__ */ new Set();\nconst roots = /* @__PURE__ */ new Set([doc]);\nlet hasInitialized;\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 findShadowRoots = (fragment) => {\n processEventOrNode(fragment);\n nativeQuerySelectorAll(fragment, "[q\\\\:shadowroot]").forEach((parent) => {\n const shadowRoot = parent.shadowRoot;\n shadowRoot && findShadowRoots(shadowRoot);\n });\n};\nconst isPromise = (promise) => promise && typeof promise.then === "function";\nlet doNotClean = true;\nconst broadcast = (infix, ev, type = ev.type) => {\n let found = doNotClean;\n querySelectorAll("[on" + infix + "\\\\:" + type + "]").forEach((el) => {\n found = true;\n dispatch(el, infix, ev, type);\n });\n if (!found) {\n window[infix.slice(1)].removeEventListener(\n type,\n infix === "-window" ? processWindowEvent : processDocumentEvent\n );\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, {\n detail\n});\nconst dispatch = async (element, scope, ev, eventName = ev.type) => {\n const attrName = "on" + scope + ":" + eventName;\n if (element.hasAttribute("preventdefault:" + eventName)) {\n ev.preventDefault();\n }\n if (element.hasAttribute("stoppropagation:" + eventName)) {\n ev.stopPropagation();\n }\n const ctx = element._qc_;\n const relevantListeners = ctx && ctx.li.filter((li) => li[0] === attrName);\n if (relevantListeners && relevantListeners.length > 0) {\n for (const listener of relevantListeners) {\n const results = listener[1].getFn([element, ev], () => element.isConnected)(ev, element);\n const cancelBubble = ev.cancelBubble;\n if (isPromise(results)) {\n await results;\n }\n if (cancelBubble) {\n ev.stopPropagation();\n }\n }\n return;\n }\n const attrValue = element.getAttribute(attrName);\n const qDispatchEvent = element.qDispatchEvent;\n if (qDispatchEvent) {\n return qDispatchEvent(ev, scope);\n }\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 qVersion = container.getAttribute("q:version") || "unknown";\n const qManifest = container.getAttribute("q:manifest-hash") || "dev";\n const base = new URL(qBase, doc.baseURI);\n for (const qrl of attrValue.split("\\n")) {\n const url = new URL(qrl, base);\n const href = url.href;\n const symbol = url.hash.replace(/^#?([^?[|]*).*$/, "$1") || "default";\n const reqTime = performance.now();\n let handler;\n let importError;\n let error;\n const isSync = qrl.startsWith("#");\n const eventData = {\n qBase,\n qManifest,\n qVersion,\n href,\n symbol,\n element,\n reqTime\n };\n if (isSync) {\n const hash = container.getAttribute("q:instance");\n handler = (doc["qFuncs_" + hash] || [])[Number.parseInt(symbol)];\n if (!handler) {\n importError = "sync";\n error = new Error("sym:" + symbol);\n }\n } else {\n emitEvent("qsymbol", eventData);\n const uri = url.href.split("#")[0];\n try {\n const module = import(\n uri\n );\n resolveContainer(container);\n handler = (await module)[symbol];\n if (!handler) {\n importError = "no-symbol";\n error = new Error(`${symbol} not in ${uri}`);\n }\n } catch (err) {\n importError || (importError = "async");\n error = err;\n }\n }\n if (!handler) {\n emitEvent("qerror", {\n importError,\n error,\n ...eventData\n });\n console.error(error);\n break;\n }\n const previousCtx = doc.__q_context__;\n if (element.isConnected) {\n try {\n doc.__q_context__ = [element, ev, url];\n const results = handler(ev, element);\n if (isPromise(results)) {\n await results;\n }\n } catch (error2) {\n emitEvent("qerror", { error: error2, ...eventData });\n } finally {\n doc.__q_context__ = previousCtx;\n }\n }\n }\n }\n};\nconst emitEvent = (eventName, detail) => {\n doc.dispatchEvent(createEvent(eventName, detail));\n};\nconst camelToKebab = (str) => str.replace(/([A-Z])/g, (a) => "-" + a.toLowerCase());\nconst processDocumentEvent = async (ev) => {\n let type = camelToKebab(ev.type);\n let element = ev.target;\n broadcast("-document", ev, type);\n while (element && element.getAttribute) {\n const results = dispatch(element, "", ev, type);\n let cancelBubble = ev.cancelBubble;\n if (isPromise(results)) {\n await results;\n }\n cancelBubble || (cancelBubble = cancelBubble || ev.cancelBubble || element.hasAttribute("stoppropagation:" + ev.type));\n element = ev.bubbles && cancelBubble !== true ? element.parentElement : null;\n }\n};\nconst processWindowEvent = (ev) => {\n broadcast("-window", ev, camelToKebab(ev.type));\n};\nconst processReadyStateChange = () => {\n var _a;\n const readyState = doc.readyState;\n if (!hasInitialized && (readyState == "interactive" || readyState == "complete")) {\n roots.forEach(findShadowRoots);\n hasInitialized = 1;\n emitEvent("qinit");\n const riC = (_a = win.requestIdleCallback) != null ? _a : win.setTimeout;\n riC.bind(win)(() => emitEvent("qidle"));\n if (events.has("qvisible")) {\n const results = querySelectorAll("[on\\\\:qvisible]");\n const observer = new IntersectionObserver((entries) => {\n for (const entry of entries) {\n if (entry.isIntersecting) {\n observer.unobserve(entry.target);\n dispatch(entry.target, "", createEvent("qvisible", entry));\n }\n }\n });\n results.forEach((el) => observer.observe(el));\n }\n }\n};\nconst addEventListener = (el, eventName, handler, capture = false) => {\n el.addEventListener(eventName, handler, { capture, passive: false });\n};\nlet cleanTimer;\nconst processEventOrNode = (...eventNames) => {\n doNotClean = true;\n clearTimeout(cleanTimer);\n cleanTimer = setTimeout(() => doNotClean = false, 2e4);\n for (const eventNameOrNode of eventNames) {\n if (typeof eventNameOrNode === "string") {\n if (!events.has(eventNameOrNode)) {\n roots.forEach(\n (root) => addEventListener(root, eventNameOrNode, processDocumentEvent, true)\n );\n addEventListener(win, eventNameOrNode, processWindowEvent, true);\n events.add(eventNameOrNode);\n }\n } else {\n if (!roots.has(eventNameOrNode)) {\n events.forEach(\n (eventName) => addEventListener(eventNameOrNode, eventName, processDocumentEvent, true)\n );\n roots.add(eventNameOrNode);\n }\n }\n }\n};\nif (!("__q_context__" in doc)) {\n doc.__q_context__ = 0;\n const qwikevents = win.qwikevents;\n if (qwikevents) {\n if (Array.isArray(qwikevents)) {\n processEventOrNode(...qwikevents);\n } else {\n processEventOrNode("click", "input");\n }\n }\n win.qwikevents = {\n events,\n roots,\n push: processEventOrNode\n };\n addEventListener(doc, "readystatechange", processReadyStateChange);\n processReadyStateChange();\n}';
1143
+ function getQwikLoaderScript(opts = {}) {
1144
+ return opts.debug ? QWIK_LOADER_DEFAULT_DEBUG : QWIK_LOADER_DEFAULT_MINIFIED;
1149
1145
  }
1150
- function addBundle(manifest, urls, prefetchResources, buildBase, bundleFileName) {
1151
- const url = isDev2 ? bundleFileName : buildBase + bundleFileName;
1152
- let prefetchResource = urls.get(url);
1153
- if (!prefetchResource) {
1154
- prefetchResource = {
1155
- url,
1156
- imports: []
1157
- };
1158
- urls.set(url, prefetchResource);
1159
- const bundle = manifest.bundles[bundleFileName];
1160
- if (bundle) {
1161
- if (Array.isArray(bundle.imports)) {
1162
- for (const importedFilename of bundle.imports) {
1163
- addBundle(manifest, urls, prefetchResource.imports, buildBase, importedFilename);
1164
- }
1165
- }
1166
- }
1167
- }
1168
- prefetchResources.push(prefetchResource);
1146
+ var QWIK_PREFETCH_MINIFIED = globalThis.QWIK_PREFETCH_MINIFIED;
1147
+ var QWIK_PREFETCH_DEBUG = globalThis.QWIK_PREFETCH_DEBUG;
1148
+ function getQwikPrefetchWorkerScript(opts = {}) {
1149
+ return opts.debug ? QWIK_PREFETCH_DEBUG : QWIK_PREFETCH_MINIFIED;
1169
1150
  }
1170
1151
 
1171
1152
  // packages/qwik/src/server/ssr-node.ts
@@ -1176,26 +1157,23 @@ import {
1176
1157
  } from "@qwik.dev/core";
1177
1158
  import { isDev as isDev3 } from "@qwik.dev/core/build";
1178
1159
  var SsrNode = class {
1179
- constructor(currentComponentNode, nodeType, id, attrs, cleanupQueue, vnodeData) {
1160
+ constructor(parentSsrNode, id, attrs, cleanupQueue, vnodeData) {
1180
1161
  this.attrs = attrs;
1181
1162
  this.cleanupQueue = cleanupQueue;
1182
1163
  this.vnodeData = vnodeData;
1183
- __publicField(this, "__brand__");
1184
- /** @param nodeType - Node type: ELEMENT_NODE, TEXT_NODE, DOCUMENT_NODE */
1185
- __publicField(this, "nodeType");
1164
+ __publicField(this, "__brand__", "SsrNode");
1186
1165
  /**
1187
1166
  * ID which the deserialize will use to retrieve the node.
1188
1167
  *
1189
- * @param refId - Unique id for the node.
1168
+ * @param id - Unique id for the node.
1190
1169
  */
1191
1170
  __publicField(this, "id");
1171
+ __publicField(this, "parentSsrNode");
1172
+ __publicField(this, "children", null);
1192
1173
  /** Local props which don't serialize; */
1193
- __publicField(this, "locals", null);
1194
- __publicField(this, "currentComponentNode");
1195
- __publicField(this, "childrenVNodeData", null);
1196
- this.currentComponentNode = currentComponentNode;
1197
- this.currentComponentNode?.addChildVNodeData(this.vnodeData);
1198
- this.nodeType = nodeType;
1174
+ __publicField(this, "localProps", null);
1175
+ this.parentSsrNode = parentSsrNode;
1176
+ this.parentSsrNode?.addChild(this);
1199
1177
  this.id = id;
1200
1178
  if (isDev3 && id.indexOf("undefined") != -1) {
1201
1179
  throw new Error(`Invalid SSR node id: ${id}`);
@@ -1209,7 +1187,7 @@ var SsrNode = class {
1209
1187
  this.attrs = [];
1210
1188
  }
1211
1189
  if (name.startsWith(NON_SERIALIZABLE_MARKER_PREFIX)) {
1212
- mapArray_set(this.locals || (this.locals = []), name, value, 0);
1190
+ mapArray_set(this.localProps || (this.localProps = []), name, value, 0);
1213
1191
  } else {
1214
1192
  mapArray_set(this.attrs, name, value, 0);
1215
1193
  }
@@ -1219,25 +1197,25 @@ var SsrNode = class {
1219
1197
  }
1220
1198
  getProp(name) {
1221
1199
  if (name.startsWith(NON_SERIALIZABLE_MARKER_PREFIX)) {
1222
- return this.locals ? mapArray_get(this.locals, name, 0) : null;
1200
+ return this.localProps ? mapArray_get(this.localProps, name, 0) : null;
1223
1201
  } else {
1224
1202
  return mapArray_get(this.attrs, name, 0);
1225
1203
  }
1226
1204
  }
1227
1205
  removeProp(name) {
1228
1206
  if (name.startsWith(NON_SERIALIZABLE_MARKER_PREFIX)) {
1229
- if (this.locals) {
1230
- mapApp_remove(this.locals, name, 0);
1207
+ if (this.localProps) {
1208
+ mapApp_remove(this.localProps, name, 0);
1231
1209
  }
1232
1210
  } else {
1233
1211
  mapApp_remove(this.attrs, name, 0);
1234
1212
  }
1235
1213
  }
1236
- addChildVNodeData(child) {
1237
- if (!this.childrenVNodeData) {
1238
- this.childrenVNodeData = [];
1214
+ addChild(child) {
1215
+ if (!this.children) {
1216
+ this.children = [];
1239
1217
  }
1240
- this.childrenVNodeData.push(child);
1218
+ this.children.push(child);
1241
1219
  }
1242
1220
  toString() {
1243
1221
  let stringifiedAttrs = "";
@@ -1253,13 +1231,10 @@ var SsrNode = class {
1253
1231
  return `SSRNode [<${this.id}> ${stringifiedAttrs}]`;
1254
1232
  }
1255
1233
  };
1256
- __publicField(SsrNode, "ELEMENT_NODE", 1);
1257
- __publicField(SsrNode, "TEXT_NODE", 3);
1258
- __publicField(SsrNode, "DOCUMENT_NODE", 9);
1259
- __publicField(SsrNode, "DOCUMENT_FRAGMENT_NODE", 11);
1260
1234
  var DomRef = class {
1261
1235
  constructor($ssrNode$) {
1262
1236
  this.$ssrNode$ = $ssrNode$;
1237
+ __publicField(this, "__brand__", "DomRef");
1263
1238
  }
1264
1239
  };
1265
1240
  var SsrComponentFrame = class {
@@ -1641,7 +1616,7 @@ function vNodeData_openElement(vNodeData) {
1641
1616
  function vNodeData_createSsrNodeReference(currentComponentNode, vNodeData, depthFirstElementIdx, cleanupQueue) {
1642
1617
  vNodeData[0] |= 8 /* REFERENCE */;
1643
1618
  let fragmentAttrs = _EMPTY_ARRAY2;
1644
- const stack = [SsrNode.ELEMENT_NODE, -1];
1619
+ const stack = [-1];
1645
1620
  for (let i = 1; i < vNodeData.length; i++) {
1646
1621
  const value = vNodeData[i];
1647
1622
  if (Array.isArray(value)) {
@@ -1649,10 +1624,9 @@ function vNodeData_createSsrNodeReference(currentComponentNode, vNodeData, depth
1649
1624
  i++;
1650
1625
  if (vNodeData[i] !== WRITE_ELEMENT_ATTRS) {
1651
1626
  stack[stack.length - 1]++;
1652
- stack.push(SsrNode.DOCUMENT_FRAGMENT_NODE, -1);
1627
+ stack.push(-1);
1653
1628
  }
1654
1629
  } else if (value === CLOSE_FRAGMENT) {
1655
- stack.pop();
1656
1630
  stack.pop();
1657
1631
  fragmentAttrs = _EMPTY_ARRAY2;
1658
1632
  } else if (value < 0) {
@@ -1664,15 +1638,14 @@ function vNodeData_createSsrNodeReference(currentComponentNode, vNodeData, depth
1664
1638
  }
1665
1639
  let refId = String(depthFirstElementIdx);
1666
1640
  if (vNodeData[0] & (2 /* VIRTUAL_NODE */ | 1 /* TEXT_DATA */)) {
1667
- for (let i = 1; i < stack.length; i += 2) {
1641
+ for (let i = 0; i < stack.length; i++) {
1668
1642
  const childCount = stack[i];
1669
1643
  if (childCount >= 0) {
1670
1644
  refId += encodeAsAlphanumeric(childCount);
1671
1645
  }
1672
1646
  }
1673
1647
  }
1674
- const type = stack[stack.length - 2];
1675
- return new SsrNode(currentComponentNode, type, refId, fragmentAttrs, cleanupQueue, vNodeData);
1648
+ return new SsrNode(currentComponentNode, refId, fragmentAttrs, cleanupQueue, vNodeData);
1676
1649
  }
1677
1650
  var ALPHANUMERIC = [];
1678
1651
  function encodeAsAlphanumeric(value) {
@@ -1694,17 +1667,237 @@ function encodeAsAlphanumeric(value) {
1694
1667
  return ALPHANUMERIC[value];
1695
1668
  }
1696
1669
 
1697
- // packages/qwik/src/server/scripts.ts
1698
- var QWIK_LOADER_DEFAULT_MINIFIED = '(()=>{var e=Object.defineProperty,t=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable,r=(t,o,n)=>o in t?e(t,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[o]=n,s=(e,s)=>{for(var a in s||(s={}))o.call(s,a)&&r(e,a,s[a]);if(t)for(var a of t(s))n.call(s,a)&&r(e,a,s[a]);return e};((e,t)=>{const o="__q_context__",n=window,r=new Set,a=new Set([e]),i="replace",c="forEach",l="target",f="getAttribute",p="isConnected",b="qvisible",u="_qwikjson_",h=(e,t)=>Array.from(e.querySelectorAll(t)),y=e=>{const t=[];return a.forEach((o=>t.push(...h(o,e)))),t},d=e=>{S(e),h(e,"[q\\\\:shadowroot]").forEach((e=>{const t=e.shadowRoot;t&&d(t)}))},q=e=>e&&"function"==typeof e.then,m=(e,t,o=t.type)=>{y("[on"+e+"\\\\:"+o+"]")[c]((n=>g(n,e,t,o)))},w=t=>{if(void 0===t[u]){let o=(t===e.documentElement?e.body:t).lastElementChild;for(;o;){if("SCRIPT"===o.tagName&&"qwik/json"===o[f]("type")){t[u]=JSON.parse(o.textContent[i](/\\\\x3C(\\/?script)/gi,"<$1"));break}o=o.previousElementSibling}}},v=(e,t)=>new CustomEvent(e,{detail:t}),g=async(t,n,r,a=r.type)=>{const c="on"+n+":"+a;t.hasAttribute("preventdefault:"+a)&&r.preventDefault(),t.hasAttribute("stoppropagation:"+a)&&r.stopPropagation();const l=t._qc_,b=l&&l.li.filter((e=>e[0]===c));if(b&&b.length>0){for(const e of b){const o=e[1].getFn([t,r],(()=>t[p]))(r,t),n=r.cancelBubble;q(o)&&await o,n&&r.stopPropagation()}return}const u=t.qDispatchEvent;if(u)return u(r,n);const h=t[f](c);if(h){const n=t.closest("[q\\\\:container]:not([q\\\\:container=html]):not([q\\\\:container=text])"),a=n[f]("q:base"),c=n[f]("q:version")||"unknown",l=n[f]("q:manifest-hash")||"dev",b=new URL(a,e.baseURI);for(const f of h.split("\\n")){const u=new URL(f,b),h=u.href,y=u.hash[i](/^#?([^?[|]*).*$/,"$1")||"default",d=performance.now();let m,v,g;const A=f.startsWith("#"),_={qBase:a,qManifest:l,qVersion:c,href:h,symbol:y,element:t,reqTime:d};if(A){const t=n.getAttribute("q:instance");m=(e["qFuncs_"+t]||[])[Number.parseInt(y)],m||(v="sync",g=Error("sync handler error for symbol: "+y))}else{const e=u.href.split("#")[0];try{const t=import(e);w(n),m=(await t)[y],m||(v="no-symbol",g=Error(`${y} not in ${e}`))}catch(e){v||(v="async"),g=e}}if(!m){E("qerror",s({importError:v,error:g},_)),console.error(g);break}const k=e[o];if(t[p])try{e[o]=[t,r,u],A||E("qsymbol",s({},_));const n=m(r,t);q(n)&&await n}catch(e){E("qerror",s({error:e},_))}finally{e[o]=k}}}},E=(t,o)=>{e.dispatchEvent(v(t,o))},A=e=>e[i](/([A-Z])/g,(e=>"-"+e.toLowerCase())),_=async e=>{let t=A(e.type),o=e[l];for(m("-document",e,t);o&&o[f];){const n=g(o,"",e,t);let r=e.cancelBubble;q(n)&&await n,r=r||e.cancelBubble||o.hasAttribute("stoppropagation:"+e.type),o=e.bubbles&&!0!==r?o.parentElement:null}},k=e=>{m("-window",e,A(e.type))},C=()=>{var o;const s=e.readyState;if(!t&&("interactive"==s||"complete"==s)&&(a.forEach(d),t=1,E("qinit"),(null!=(o=n.requestIdleCallback)?o:n.setTimeout).bind(n)((()=>E("qidle"))),r.has(b))){const e=y("[on\\\\:"+b+"]"),t=new IntersectionObserver((e=>{for(const o of e)o.isIntersecting&&(t.unobserve(o[l]),g(o[l],"",v(b,o)))}));e[c]((e=>t.observe(e)))}},O=(e,t,o,n=!1)=>e.addEventListener(t,o,{capture:n,passive:!1}),S=(...e)=>{for(const t of e)"string"==typeof t?r.has(t)||(a.forEach((e=>O(e,t,_,!0))),O(n,t,k,!0),r.add(t)):a.has(t)||(r.forEach((e=>O(t,e,_,!0))),a.add(t))};if(!(o in e)){e[o]=0;const t=n.qwikevents;Array.isArray(t)&&S(...t),n.qwikevents={events:r,roots:a,push:S},O(e,"readystatechange",C),C()}})(document)})()';
1699
- var QWIK_LOADER_DEFAULT_DEBUG = '(() => {\n var __defProp = Object.defineProperty;\n var __getOwnPropSymbols = Object.getOwnPropertySymbols;\n var __hasOwnProp = Object.prototype.hasOwnProperty;\n var __propIsEnum = Object.prototype.propertyIsEnumerable;\n var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {\n enumerable: !0,\n configurable: !0,\n writable: !0,\n value: value\n }) : obj[key] = value;\n var __spreadValues = (a, b) => {\n for (var prop in b || (b = {})) {\n __hasOwnProp.call(b, prop) && __defNormalProp(a, prop, b[prop]);\n }\n if (__getOwnPropSymbols) {\n for (var prop of __getOwnPropSymbols(b)) {\n __propIsEnum.call(b, prop) && __defNormalProp(a, prop, b[prop]);\n }\n }\n return a;\n };\n ((doc, hasInitialized) => {\n const Q_CONTEXT = "__q_context__";\n const win = window;\n const events = new Set;\n const roots = new Set([ doc ]);\n const nativeQuerySelectorAll = (root, selector) => Array.from(root.querySelectorAll(selector));\n const querySelectorAll = query => {\n const elements = [];\n roots.forEach((root => elements.push(...nativeQuerySelectorAll(root, query))));\n return elements;\n };\n const findShadowRoots = fragment => {\n processEventOrNode(fragment);\n nativeQuerySelectorAll(fragment, "[q\\\\:shadowroot]").forEach((parent => {\n const shadowRoot = parent.shadowRoot;\n shadowRoot && findShadowRoots(shadowRoot);\n }));\n };\n const isPromise = promise => promise && "function" == typeof promise.then;\n const broadcast = (infix, ev, type = ev.type) => {\n querySelectorAll("[on" + infix + "\\\\:" + type + "]").forEach((el => dispatch(el, infix, ev, type)));\n };\n const resolveContainer = containerEl => {\n if (void 0 === containerEl._qwikjson_) {\n let script = (containerEl === doc.documentElement ? doc.body : containerEl).lastElementChild;\n while (script) {\n if ("SCRIPT" === script.tagName && "qwik/json" === script.getAttribute("type")) {\n containerEl._qwikjson_ = JSON.parse(script.textContent.replace(/\\\\x3C(\\/?script)/gi, "<$1"));\n break;\n }\n script = script.previousElementSibling;\n }\n }\n };\n const createEvent = (eventName, detail) => new CustomEvent(eventName, {\n detail: detail\n });\n const dispatch = async (element, scope, ev, eventName = ev.type) => {\n const attrName = "on" + scope + ":" + eventName;\n element.hasAttribute("preventdefault:" + eventName) && ev.preventDefault();\n element.hasAttribute("stoppropagation:" + eventName) && ev.stopPropagation();\n const ctx = element._qc_;\n const relevantListeners = ctx && ctx.li.filter((li => li[0] === attrName));\n if (relevantListeners && relevantListeners.length > 0) {\n for (const listener of relevantListeners) {\n const results = listener[1].getFn([ element, ev ], (() => element.isConnected))(ev, element);\n const cancelBubble = ev.cancelBubble;\n isPromise(results) && await results;\n cancelBubble && ev.stopPropagation();\n }\n return;\n }\n const qDispatchEvent = element.qDispatchEvent;\n if (qDispatchEvent) {\n return qDispatchEvent(ev, scope);\n }\n const attrValue = element.getAttribute(attrName);\n if (attrValue) {\n const container = element.closest("[q\\\\:container]:not([q\\\\:container=html]):not([q\\\\:container=text])");\n const qBase = container.getAttribute("q:base");\n const qVersion = container.getAttribute("q:version") || "unknown";\n const qManifest = container.getAttribute("q:manifest-hash") || "dev";\n const base = new URL(qBase, doc.baseURI);\n for (const qrl of attrValue.split("\\n")) {\n const url = new URL(qrl, base);\n const href = url.href;\n const symbol = url.hash.replace(/^#?([^?[|]*).*$/, "$1") || "default";\n const reqTime = performance.now();\n let handler;\n let importError;\n let error;\n const isSync = qrl.startsWith("#");\n const eventData = {\n qBase: qBase,\n qManifest: qManifest,\n qVersion: qVersion,\n href: href,\n symbol: symbol,\n element: element,\n reqTime: reqTime\n };\n if (isSync) {\n const hash = container.getAttribute("q:instance");\n handler = (doc["qFuncs_" + hash] || [])[Number.parseInt(symbol)];\n if (!handler) {\n importError = "sync";\n error = new Error("sync handler error for symbol: " + symbol);\n }\n } else {\n const uri = url.href.split("#")[0];\n try {\n const module = import(\n uri);\n resolveContainer(container);\n handler = (await module)[symbol];\n if (!handler) {\n importError = "no-symbol";\n error = new Error(`${symbol} not in ${uri}`);\n }\n } catch (err) {\n importError || (importError = "async");\n error = err;\n }\n }\n if (!handler) {\n emitEvent("qerror", __spreadValues({\n importError: importError,\n error: error\n }, eventData));\n console.error(error);\n break;\n }\n const previousCtx = doc[Q_CONTEXT];\n if (element.isConnected) {\n try {\n doc[Q_CONTEXT] = [ element, ev, url ];\n isSync || emitEvent("qsymbol", __spreadValues({}, eventData));\n const results = handler(ev, element);\n isPromise(results) && await results;\n } catch (error2) {\n emitEvent("qerror", __spreadValues({\n error: error2\n }, eventData));\n } finally {\n doc[Q_CONTEXT] = previousCtx;\n }\n }\n }\n }\n };\n const emitEvent = (eventName, detail) => {\n doc.dispatchEvent(createEvent(eventName, detail));\n };\n const camelToKebab = str => str.replace(/([A-Z])/g, (a => "-" + a.toLowerCase()));\n const processDocumentEvent = async ev => {\n let type = camelToKebab(ev.type);\n let element = ev.target;\n broadcast("-document", ev, type);\n while (element && element.getAttribute) {\n const results = dispatch(element, "", ev, type);\n let cancelBubble = ev.cancelBubble;\n isPromise(results) && await results;\n cancelBubble = cancelBubble || ev.cancelBubble || element.hasAttribute("stoppropagation:" + ev.type);\n element = ev.bubbles && !0 !== cancelBubble ? element.parentElement : null;\n }\n };\n const processWindowEvent = ev => {\n broadcast("-window", ev, camelToKebab(ev.type));\n };\n const processReadyStateChange = () => {\n var _a;\n const readyState = doc.readyState;\n if (!hasInitialized && ("interactive" == readyState || "complete" == readyState)) {\n roots.forEach(findShadowRoots);\n hasInitialized = 1;\n emitEvent("qinit");\n (null != (_a = win.requestIdleCallback) ? _a : win.setTimeout).bind(win)((() => emitEvent("qidle")));\n if (events.has("qvisible")) {\n const results = querySelectorAll("[on\\\\:qvisible]");\n const observer = new IntersectionObserver((entries => {\n for (const entry of entries) {\n if (entry.isIntersecting) {\n observer.unobserve(entry.target);\n dispatch(entry.target, "", createEvent("qvisible", entry));\n }\n }\n }));\n results.forEach((el => observer.observe(el)));\n }\n }\n };\n const addEventListener = (el, eventName, handler, capture = !1) => el.addEventListener(eventName, handler, {\n capture: capture,\n passive: !1\n });\n const processEventOrNode = (...eventNames) => {\n for (const eventNameOrNode of eventNames) {\n if ("string" == typeof eventNameOrNode) {\n if (!events.has(eventNameOrNode)) {\n roots.forEach((root => addEventListener(root, eventNameOrNode, processDocumentEvent, !0)));\n addEventListener(win, eventNameOrNode, processWindowEvent, !0);\n events.add(eventNameOrNode);\n }\n } else if (!roots.has(eventNameOrNode)) {\n events.forEach((eventName => addEventListener(eventNameOrNode, eventName, processDocumentEvent, !0)));\n roots.add(eventNameOrNode);\n }\n }\n };\n if (!(Q_CONTEXT in doc)) {\n doc[Q_CONTEXT] = 0;\n const qwikevents = win.qwikevents;\n Array.isArray(qwikevents) && processEventOrNode(...qwikevents);\n win.qwikevents = {\n events: events,\n roots: roots,\n push: processEventOrNode\n };\n addEventListener(doc, "readystatechange", processReadyStateChange);\n processReadyStateChange();\n }\n })(document);\n})()';
1700
- function getQwikLoaderScript(opts = {}) {
1701
- return opts.debug ? QWIK_LOADER_DEFAULT_DEBUG : QWIK_LOADER_DEFAULT_MINIFIED;
1670
+ // packages/qwik/src/server/preload-strategy.ts
1671
+ import { getPlatform } from "@qwik.dev/core";
1672
+
1673
+ // packages/qwik/src/server/preload-utils.ts
1674
+ function flattenPrefetchResources(prefetchResources) {
1675
+ const urls = [];
1676
+ const addPrefetchResource = (prefetchResources2) => {
1677
+ if (prefetchResources2) {
1678
+ for (const prefetchResource of prefetchResources2) {
1679
+ if (!urls.includes(prefetchResource.url)) {
1680
+ urls.push(prefetchResource.url);
1681
+ if (prefetchResource.imports) {
1682
+ addPrefetchResource(prefetchResource.imports);
1683
+ }
1684
+ }
1685
+ }
1686
+ }
1687
+ };
1688
+ addPrefetchResource(prefetchResources);
1689
+ return urls;
1702
1690
  }
1703
- var QWIK_PREFETCH_MINIFIED = globalThis.QWIK_PREFETCH_MINIFIED;
1704
- var QWIK_PREFETCH_DEBUG = globalThis.QWIK_PREFETCH_DEBUG;
1705
- function getQwikPrefetchWorkerScript(opts = {}) {
1706
- return opts.debug ? QWIK_PREFETCH_DEBUG : QWIK_PREFETCH_MINIFIED;
1691
+
1692
+ // packages/qwik/src/server/preload-strategy.ts
1693
+ var getBundles = (qrls) => {
1694
+ const platform = getPlatform();
1695
+ return qrls?.map((qrl) => {
1696
+ const symbol = qrl.$symbol$;
1697
+ const chunk = qrl.$chunk$;
1698
+ const result = platform.chunkForSymbol(symbol, chunk, qrl.dev?.file);
1699
+ if (result) {
1700
+ return result[1];
1701
+ }
1702
+ return chunk;
1703
+ }).filter(Boolean);
1704
+ };
1705
+ function getPreloadPaths(qrls, opts, resolvedManifest) {
1706
+ const prefetchStrategy = opts.prefetchStrategy;
1707
+ if (prefetchStrategy === null) {
1708
+ return [];
1709
+ }
1710
+ if (!resolvedManifest?.manifest.bundleGraph) {
1711
+ return getBundles(qrls);
1712
+ }
1713
+ if (typeof prefetchStrategy?.symbolsToPrefetch === "function") {
1714
+ try {
1715
+ const prefetchResources = prefetchStrategy.symbolsToPrefetch({
1716
+ manifest: resolvedManifest.manifest
1717
+ });
1718
+ return flattenPrefetchResources(prefetchResources);
1719
+ } catch (e) {
1720
+ console.error("getPrefetchUrls, symbolsToPrefetch()", e);
1721
+ }
1722
+ }
1723
+ const symbols = /* @__PURE__ */ new Set();
1724
+ for (const qrl of qrls) {
1725
+ const symbol = getSymbolHash(qrl.$symbol$);
1726
+ if (symbol && symbol.length >= 10) {
1727
+ symbols.add(symbol);
1728
+ }
1729
+ }
1730
+ return [...symbols];
1731
+ }
1732
+ var expandBundles = (names, resolvedManifest) => {
1733
+ if (!resolvedManifest?.manifest.bundleGraph) {
1734
+ return [...new Set(names)];
1735
+ }
1736
+ resetQueue();
1737
+ let probability = 0.99;
1738
+ for (const name of names) {
1739
+ preload(name, probability);
1740
+ probability *= 0.95;
1741
+ }
1742
+ return getQueue();
1743
+ };
1744
+
1745
+ // packages/qwik/src/server/preload-impl.ts
1746
+ var simplifyPath = (base2, path) => {
1747
+ if (path == null) {
1748
+ return null;
1749
+ }
1750
+ const segments = `${base2}${path}`.split("/");
1751
+ const simplified = [];
1752
+ for (const segment of segments) {
1753
+ if (segment === ".." && simplified.length > 0) {
1754
+ simplified.pop();
1755
+ } else {
1756
+ simplified.push(segment);
1757
+ }
1758
+ }
1759
+ return simplified.join("/");
1760
+ };
1761
+ var getBase = (container) => {
1762
+ let base2 = container.$buildBase$;
1763
+ if (import.meta.env.DEV && !import.meta.env.TEST) {
1764
+ base2 = import.meta.env.BASE_URL;
1765
+ }
1766
+ return base2;
1767
+ };
1768
+ var preloaderPre = (container, options, nonce) => {
1769
+ const { resolvedManifest } = container;
1770
+ const base2 = getBase(container);
1771
+ const preloaderBundle = simplifyPath(base2, resolvedManifest?.manifest?.preloader);
1772
+ let bundleGraphPath = resolvedManifest?.manifest.bundleGraphAsset;
1773
+ if (bundleGraphPath) {
1774
+ bundleGraphPath = (import.meta.env.BASE_URL || "/") + bundleGraphPath;
1775
+ }
1776
+ if (preloaderBundle && bundleGraphPath && options !== false) {
1777
+ const preloaderOpts = typeof options === "object" ? {
1778
+ debug: options.debug,
1779
+ preloadProbability: options.ssrPreloadProbability
1780
+ } : void 0;
1781
+ const bundleGraph = container.resolvedManifest?.manifest.bundleGraph;
1782
+ initPreloader(bundleGraph, preloaderOpts);
1783
+ const opts = [];
1784
+ if (options) {
1785
+ if (options.debug) {
1786
+ opts.push("d:1");
1787
+ }
1788
+ if (options.maxIdlePreloads) {
1789
+ opts.push(`P:${options.maxIdlePreloads}`);
1790
+ }
1791
+ if (options.preloadProbability) {
1792
+ opts.push(`Q:${options.preloadProbability}`);
1793
+ }
1794
+ }
1795
+ const optsStr = opts.length ? `,{${opts.join(",")}}` : "";
1796
+ container.openElement("link", null, ["rel", "modulepreload", "href", preloaderBundle]);
1797
+ container.closeElement();
1798
+ container.openElement("link", null, [
1799
+ "rel",
1800
+ "preload",
1801
+ "href",
1802
+ bundleGraphPath,
1803
+ "as",
1804
+ "fetch",
1805
+ "crossorigin",
1806
+ "anonymous"
1807
+ ]);
1808
+ container.closeElement();
1809
+ const script = `let b=fetch("${bundleGraphPath}");import("${preloaderBundle}").then(({l})=>l(${JSON.stringify(base2)},b${optsStr}));`;
1810
+ const scriptAttrs = ["type", "module", "async", true];
1811
+ if (nonce) {
1812
+ scriptAttrs.push("nonce", nonce);
1813
+ }
1814
+ container.openElement("script", null, scriptAttrs);
1815
+ container.writer.write(script);
1816
+ container.closeElement();
1817
+ }
1818
+ const corePath = simplifyPath(base2, resolvedManifest?.manifest.core);
1819
+ if (corePath) {
1820
+ container.openElement("link", null, ["rel", "modulepreload", "href", corePath]);
1821
+ container.closeElement();
1822
+ }
1823
+ };
1824
+ var includePreloader = (container, options, referencedBundles, nonce) => {
1825
+ if (referencedBundles.length === 0 || options === false) {
1826
+ return null;
1827
+ }
1828
+ const { ssrPreloads, ssrPreloadProbability } = normalizePreLoaderOptions(
1829
+ typeof options === "boolean" ? void 0 : options
1830
+ );
1831
+ let allowed = ssrPreloads;
1832
+ const base2 = getBase(container);
1833
+ const links = [];
1834
+ const { resolvedManifest } = container;
1835
+ if (allowed) {
1836
+ const preloaderBundle2 = resolvedManifest?.manifest.preloader;
1837
+ const coreBundle = resolvedManifest?.manifest.core;
1838
+ const expandedBundles = expandBundles(referencedBundles, resolvedManifest);
1839
+ let probability = 4;
1840
+ const tenXMinProbability = ssrPreloadProbability * 10;
1841
+ for (const hrefOrProbability of expandedBundles) {
1842
+ if (typeof hrefOrProbability === "string") {
1843
+ if (probability < tenXMinProbability) {
1844
+ break;
1845
+ }
1846
+ if (hrefOrProbability === preloaderBundle2 || hrefOrProbability === coreBundle) {
1847
+ continue;
1848
+ }
1849
+ links.push(hrefOrProbability);
1850
+ if (--allowed === 0) {
1851
+ break;
1852
+ }
1853
+ } else {
1854
+ probability = hrefOrProbability;
1855
+ }
1856
+ }
1857
+ }
1858
+ const preloaderBundle = simplifyPath(base2, resolvedManifest?.manifest.preloader);
1859
+ const insertLinks = links.length ? (
1860
+ /**
1861
+ * We only use modulepreload links because they behave best. Older browsers can rely on the
1862
+ * preloader which does feature detection and which will be available soon after inserting these
1863
+ * links.
1864
+ */
1865
+ `${JSON.stringify(links)}.map((l,e)=>{e=document.createElement('link');e.rel='modulepreload';e.href=${JSON.stringify(base2)}+l;document.head.appendChild(e)});`
1866
+ ) : "";
1867
+ let script = insertLinks;
1868
+ if (preloaderBundle) {
1869
+ script += `window.addEventListener('load',f=>{f=_=>import("${preloaderBundle}").then(({p})=>p(${JSON.stringify(referencedBundles)}));try{requestIdleCallback(f,{timeout:2000})}catch(e){setTimeout(f,200)}})`;
1870
+ }
1871
+ if (script) {
1872
+ const attrs = ["type", "module", "async", true, "q:type", "preload"];
1873
+ if (nonce) {
1874
+ attrs.push("nonce", nonce);
1875
+ }
1876
+ container.openElement("script", null, attrs);
1877
+ container.writer.write(script);
1878
+ container.closeElement();
1879
+ }
1880
+ return null;
1881
+ };
1882
+ var preloaderPost = (ssrContainer, opts, nonce) => {
1883
+ if (opts.preloader !== false) {
1884
+ const qrls = Array.from(ssrContainer.serializationCtx.$eventQrls$);
1885
+ const preloadBundles = getPreloadPaths(qrls, opts, ssrContainer.resolvedManifest);
1886
+ if (preloadBundles.length > 0) {
1887
+ includePreloader(ssrContainer, opts.preloader, preloadBundles, nonce);
1888
+ }
1889
+ }
1890
+ };
1891
+ function normalizePreLoaderOptions(input) {
1892
+ return { ...preLoaderOptionsDefault, ...input };
1707
1893
  }
1894
+ var preLoaderOptionsDefault = {
1895
+ ssrPreloads: 7,
1896
+ ssrPreloadProbability: 0.5,
1897
+ debug: false,
1898
+ maxIdlePreloads: 25,
1899
+ preloadProbability: 0.35
1900
+ };
1708
1901
 
1709
1902
  // packages/qwik/src/server/ssr-container.ts
1710
1903
  function ssrCreateContainer(opts) {
@@ -1723,10 +1916,7 @@ function ssrCreateContainer(opts) {
1723
1916
  mapper: {},
1724
1917
  manifest: {
1725
1918
  manifestHash: "dev",
1726
- mapping: {},
1727
- bundles: {},
1728
- symbols: {},
1729
- version: "dev-mode"
1919
+ mapping: {}
1730
1920
  }
1731
1921
  },
1732
1922
  renderOptions: opts.renderOptions
@@ -1759,13 +1949,12 @@ var SSRContainer = class extends _SharedContainer {
1759
1949
  opts.locale
1760
1950
  );
1761
1951
  __publicField(this, "tag");
1952
+ __publicField(this, "isHtml");
1762
1953
  __publicField(this, "writer");
1763
1954
  __publicField(this, "timing");
1764
- __publicField(this, "buildBase");
1765
1955
  __publicField(this, "resolvedManifest");
1766
1956
  __publicField(this, "symbolToChunkResolver");
1767
1957
  __publicField(this, "renderOptions");
1768
- __publicField(this, "prefetchResources", []);
1769
1958
  __publicField(this, "serializationCtx");
1770
1959
  /**
1771
1960
  * We use this to append additional nodes in the head node
@@ -1809,14 +1998,14 @@ var SSRContainer = class extends _SharedContainer {
1809
1998
  SsrNode,
1810
1999
  DomRef,
1811
2000
  this.symbolToChunkResolver,
1812
- opts.writer,
1813
- (vNodeData) => this.addVNodeToSerializationRoots(vNodeData)
2001
+ opts.writer
1814
2002
  );
1815
2003
  this.renderTimer = createTimer();
1816
2004
  this.tag = opts.tagName;
2005
+ this.isHtml = opts.tagName === "html";
1817
2006
  this.writer = opts.writer;
1818
2007
  this.timing = opts.timing;
1819
- this.buildBase = opts.buildBase;
2008
+ this.$buildBase$ = opts.buildBase;
1820
2009
  this.resolvedManifest = opts.resolvedManifest;
1821
2010
  this.renderOptions = opts.renderOptions;
1822
2011
  this.$processInjectionsFromManifest$();
@@ -1853,13 +2042,13 @@ var SSRContainer = class extends _SharedContainer {
1853
2042
  return value;
1854
2043
  }
1855
2044
  }
1856
- ssrNode = ssrNode.currentComponentNode;
2045
+ ssrNode = ssrNode.parentSsrNode;
1857
2046
  }
1858
2047
  return void 0;
1859
2048
  }
1860
2049
  getParentHost(host) {
1861
2050
  const ssrNode = host;
1862
- return ssrNode.currentComponentNode;
2051
+ return ssrNode.parentSsrNode;
1863
2052
  }
1864
2053
  setHostProp(host, name, value) {
1865
2054
  const ssrNode = host;
@@ -1883,7 +2072,7 @@ var SSRContainer = class extends _SharedContainer {
1883
2072
  containerAttributes[QRuntimeAttr] = "2";
1884
2073
  containerAttributes[QVersionAttr] = this.$version$ ?? "dev";
1885
2074
  containerAttributes[QRenderAttr] = (qRender ? qRender + "-" : "") + (isDev4 ? "ssr-dev" : "ssr");
1886
- containerAttributes[QBaseAttr] = this.buildBase || "";
2075
+ containerAttributes[QBaseAttr] = this.$buildBase$ || "";
1887
2076
  containerAttributes[QLocaleAttr] = this.$locale$;
1888
2077
  containerAttributes[QManifestHashAttr] = this.resolvedManifest.manifest.manifestHash;
1889
2078
  containerAttributes[QInstanceAttr] = this.$instanceHash$;
@@ -1980,18 +2169,13 @@ var SSRContainer = class extends _SharedContainer {
1980
2169
  openFragment(attrs) {
1981
2170
  this.lastNode = null;
1982
2171
  vNodeData_openFragment(this.currentElementFrame.vNodeData, attrs);
2172
+ this.getOrCreateLastNode();
1983
2173
  }
1984
2174
  /** Writes closing data to vNodeData for fragment boundaries */
1985
2175
  closeFragment() {
1986
2176
  vNodeData_closeFragment(this.currentElementFrame.vNodeData);
1987
2177
  this.lastNode = null;
1988
2178
  }
1989
- addCurrentElementFrameAsComponentChild() {
1990
- const vNode = this.currentElementFrame?.vNodeData;
1991
- if (vNode) {
1992
- this.currentComponentNode?.addChildVNodeData(vNode);
1993
- }
1994
- }
1995
2179
  openProjection(attrs) {
1996
2180
  this.openFragment(attrs);
1997
2181
  const componentFrame = this.getComponentFrame();
@@ -2010,7 +2194,7 @@ var SSRContainer = class extends _SharedContainer {
2010
2194
  /** Writes opening data to vNodeData for component boundaries */
2011
2195
  openComponent(attrs) {
2012
2196
  this.openFragment(attrs);
2013
- this.currentComponentNode = this.getLastNode();
2197
+ this.currentComponentNode = this.getOrCreateLastNode();
2014
2198
  this.componentStack.push(new SsrComponentFrame(this.currentComponentNode));
2015
2199
  }
2016
2200
  /**
@@ -2034,7 +2218,7 @@ var SSRContainer = class extends _SharedContainer {
2034
2218
  const componentFrame = this.componentStack.pop();
2035
2219
  componentFrame.releaseUnclaimedProjections(this.unclaimedProjections);
2036
2220
  this.closeFragment();
2037
- this.currentComponentNode = this.currentComponentNode?.currentComponentNode || null;
2221
+ this.currentComponentNode = this.currentComponentNode?.parentSsrNode || null;
2038
2222
  }
2039
2223
  /** Write a text node with correct escaping. Save the length of the text node in the vNodeData. */
2040
2224
  textNode(text) {
@@ -2054,7 +2238,7 @@ var SSRContainer = class extends _SharedContainer {
2054
2238
  }
2055
2239
  return this.serializationCtx.$addRoot$(obj);
2056
2240
  }
2057
- getLastNode() {
2241
+ getOrCreateLastNode() {
2058
2242
  if (!this.lastNode) {
2059
2243
  this.lastNode = vNodeData_createSsrNodeReference(
2060
2244
  this.currentComponentNode,
@@ -2121,7 +2305,7 @@ var SSRContainer = class extends _SharedContainer {
2121
2305
  () => maybeThen(this.emitStateData(), () => {
2122
2306
  this.$noMoreRoots$ = true;
2123
2307
  this.emitVNodeData();
2124
- this.emitPrefetchResourcesData();
2308
+ preloaderPost(this, this.renderOptions, this.$serverData$?.nonce);
2125
2309
  this.emitSyncFnsData();
2126
2310
  this.emitQwikLoaderAtBottomIfNeeded();
2127
2311
  })
@@ -2258,55 +2442,12 @@ var SSRContainer = class extends _SharedContainer {
2258
2442
  }
2259
2443
  this.closeElement();
2260
2444
  }
2261
- /** This adds the vnode's data to the serialization roots */
2262
- addVNodeToSerializationRoots(vNodeData) {
2263
- const vNodeAttrsStack = [];
2264
- const flag = vNodeData[0];
2265
- if (flag !== 0 /* NONE */) {
2266
- if (flag & (1 /* TEXT_DATA */ | 2 /* VIRTUAL_NODE */)) {
2267
- let fragmentAttrs = null;
2268
- let depth = 0;
2269
- for (let i = 1; i < vNodeData.length; i++) {
2270
- const value = vNodeData[i];
2271
- if (Array.isArray(value)) {
2272
- vNodeAttrsStack.push(fragmentAttrs);
2273
- fragmentAttrs = value;
2274
- } else if (value === OPEN_FRAGMENT) {
2275
- depth++;
2276
- } else if (value === CLOSE_FRAGMENT) {
2277
- if (fragmentAttrs) {
2278
- for (let i2 = 1; i2 < fragmentAttrs.length; i2 += 2) {
2279
- const value2 = fragmentAttrs[i2];
2280
- if (typeof value2 !== "string") {
2281
- fragmentAttrs[i2] = String(this.addRoot(value2));
2282
- }
2283
- }
2284
- fragmentAttrs = vNodeAttrsStack.pop();
2285
- }
2286
- depth--;
2287
- }
2288
- }
2289
- while (depth-- > 0) {
2290
- if (fragmentAttrs) {
2291
- for (let i = 0; i < fragmentAttrs.length; i++) {
2292
- const value = fragmentAttrs[i];
2293
- if (typeof value !== "string") {
2294
- fragmentAttrs[i] = String(this.addRoot(value));
2295
- }
2296
- }
2297
- fragmentAttrs = vNodeAttrsStack.pop();
2298
- }
2299
- }
2300
- }
2301
- }
2302
- }
2303
2445
  emitStateData() {
2304
2446
  if (!this.serializationCtx.$roots$.length) {
2305
2447
  return;
2306
2448
  }
2307
2449
  this.openElement("script", ["type", "qwik/state"]);
2308
- return maybeThen(this.serializationCtx.$breakCircularDepsAndAwaitPromises$(), () => {
2309
- this.serializationCtx.$serialize$();
2450
+ return maybeThen(this.serializationCtx.$serialize$(), () => {
2310
2451
  this.closeElement();
2311
2452
  });
2312
2453
  }
@@ -2325,83 +2466,56 @@ var SSRContainer = class extends _SharedContainer {
2325
2466
  this.closeElement();
2326
2467
  }
2327
2468
  }
2328
- emitPrefetchResourcesData() {
2329
- const qrls = Array.from(this.serializationCtx.$eventQrls$);
2330
- if (this.renderOptions.prefetchStrategy !== null && qrls.length) {
2331
- const prefetchResources = getPrefetchResources(
2332
- qrls,
2333
- this.renderOptions,
2334
- this.resolvedManifest
2335
- );
2336
- if (prefetchResources.length > 0) {
2337
- applyPrefetchImplementation2(this, this.renderOptions.prefetchStrategy, prefetchResources);
2338
- this.prefetchResources = prefetchResources;
2339
- }
2340
- }
2469
+ emitPreloaderPre() {
2470
+ preloaderPre(this, this.renderOptions.preloader, this.renderOptions.serverData?.nonce);
2341
2471
  }
2342
2472
  isStatic() {
2343
2473
  return this.serializationCtx.$eventQrls$.size === 0;
2344
2474
  }
2345
- getQwikLoaderPositionMode() {
2346
- return this.renderOptions.qwikLoader?.position ?? "bottom";
2347
- }
2348
2475
  getQwikLoaderIncludeMode() {
2349
2476
  return this.renderOptions.qwikLoader?.include ?? "auto";
2350
2477
  }
2351
2478
  emitQwikLoaderAtTopIfNeeded() {
2352
- const positionMode = this.getQwikLoaderPositionMode();
2353
- if (positionMode === "top") {
2354
- const includeMode = this.getQwikLoaderIncludeMode();
2355
- const includeLoader = includeMode !== "never";
2356
- if (includeLoader) {
2357
- this.emitQwikLoader();
2358
- this.emitQwikEvents(['"click"'], {
2359
- includeLoader: true,
2360
- includeNonce: false
2361
- });
2479
+ const includeMode = this.getQwikLoaderIncludeMode();
2480
+ const includeLoader = includeMode !== "never";
2481
+ if (includeLoader) {
2482
+ let qwikLoaderBundle = this.resolvedManifest.manifest.qwikLoader;
2483
+ if (qwikLoaderBundle) {
2484
+ qwikLoaderBundle = this.$buildBase$ + qwikLoaderBundle;
2485
+ this.openElement("link", ["rel", "modulepreload", "href", qwikLoaderBundle]);
2486
+ this.closeElement();
2487
+ this.openElement("script", ["type", "module", "async", true, "src", qwikLoaderBundle]);
2488
+ this.closeElement();
2362
2489
  }
2363
2490
  }
2364
2491
  }
2365
2492
  emitQwikLoaderAtBottomIfNeeded() {
2366
- const positionMode = this.getQwikLoaderPositionMode();
2367
- let includeLoader = true;
2368
- if (positionMode === "bottom") {
2493
+ const qwikLoaderBundle = this.resolvedManifest.manifest.qwikLoader;
2494
+ if (!qwikLoaderBundle) {
2369
2495
  const needLoader = !this.isStatic();
2370
2496
  const includeMode = this.getQwikLoaderIncludeMode();
2371
- includeLoader = includeMode === "always" || includeMode === "auto" && needLoader;
2497
+ const includeLoader = includeMode === "always" || includeMode === "auto" && needLoader;
2372
2498
  if (includeLoader) {
2373
- this.emitQwikLoader();
2374
- }
2375
- }
2376
- this.emitQwikEvents(
2377
- Array.from(this.serializationCtx.$eventNames$, (s) => JSON.stringify(s)),
2378
- {
2379
- includeLoader,
2380
- includeNonce: true
2499
+ const qwikLoaderScript = getQwikLoaderScript({
2500
+ debug: this.renderOptions.debug
2501
+ });
2502
+ const scriptAttrs = ["id", "qwikloader", "async", true];
2503
+ const nonce = this.renderOptions.serverData?.nonce;
2504
+ if (nonce) {
2505
+ scriptAttrs.push("nonce", nonce);
2506
+ }
2507
+ this.openElement("script", scriptAttrs);
2508
+ this.write(qwikLoaderScript);
2509
+ this.closeElement();
2381
2510
  }
2382
- );
2383
- }
2384
- emitQwikLoader() {
2385
- const qwikLoaderScript = getQwikLoaderScript({
2386
- debug: this.renderOptions.debug
2387
- });
2388
- const scriptAttrs = ["id", "qwikloader"];
2389
- if (this.renderOptions.serverData?.nonce) {
2390
- scriptAttrs.push("nonce", this.renderOptions.serverData.nonce);
2391
2511
  }
2392
- this.openElement("script", scriptAttrs);
2393
- this.write(qwikLoaderScript);
2394
- this.closeElement();
2512
+ this.emitQwikEvents(Array.from(this.serializationCtx.$eventNames$, (s) => JSON.stringify(s)));
2395
2513
  }
2396
- emitQwikEvents(eventNames, opts) {
2514
+ emitQwikEvents(eventNames) {
2397
2515
  if (eventNames.length > 0) {
2398
- const scriptAttrs = [];
2399
- if (this.renderOptions.serverData?.nonce && opts.includeNonce) {
2400
- scriptAttrs.push("nonce", this.renderOptions.serverData.nonce);
2401
- }
2516
+ const scriptAttrs = this.renderOptions.serverData?.nonce ? ["nonce", this.renderOptions.serverData.nonce] : null;
2402
2517
  this.openElement("script", scriptAttrs);
2403
- this.write(opts.includeLoader ? `window.qwikevents` : `(window.qwikevents||=[])`);
2404
- this.write(".push(");
2518
+ this.write(`(window.qwikevents||(window.qwikevents=[])).push(`);
2405
2519
  this.writeArray(eventNames, ", ");
2406
2520
  this.write(")");
2407
2521
  this.closeElement();
@@ -2438,7 +2552,7 @@ var SSRContainer = class extends _SharedContainer {
2438
2552
  this.openFragment(
2439
2553
  isDev4 ? [DEBUG_TYPE, "P" /* Projection */, QSlotParent, ssrComponentNode.id] : [QSlotParent, ssrComponentNode.id]
2440
2554
  );
2441
- const lastNode = this.getLastNode();
2555
+ const lastNode = this.getOrCreateLastNode();
2442
2556
  if (lastNode.vnodeData) {
2443
2557
  lastNode.vnodeData[0] |= 16 /* SERIALIZE */;
2444
2558
  }
@@ -2562,7 +2676,7 @@ var SSRContainer = class extends _SharedContainer {
2562
2676
  let styleScopedId = null;
2563
2677
  if (isSSRUnsafeAttr(key)) {
2564
2678
  if (isDev4) {
2565
- throw qError(49 /* unsafeAttr */);
2679
+ throw qError(32 /* unsafeAttr */);
2566
2680
  }
2567
2681
  continue;
2568
2682
  }
@@ -2572,9 +2686,9 @@ var SSRContainer = class extends _SharedContainer {
2572
2686
  styleScopedId = styleId;
2573
2687
  }
2574
2688
  if (key === "ref") {
2575
- const lastNode = this.getLastNode();
2689
+ const lastNode = this.getOrCreateLastNode();
2576
2690
  if (isSignal(value)) {
2577
- value.value = new DomRef(lastNode);
2691
+ value.$untrackedValue$ = new DomRef(lastNode);
2578
2692
  continue;
2579
2693
  } else if (typeof value === "function") {
2580
2694
  value(new DomRef(lastNode));
@@ -2582,12 +2696,12 @@ var SSRContainer = class extends _SharedContainer {
2582
2696
  } else if (value == null) {
2583
2697
  continue;
2584
2698
  } else {
2585
- throw qError(32 /* invalidRefValue */, [currentFile]);
2699
+ throw qError(15 /* invalidRefValue */, [currentFile]);
2586
2700
  }
2587
2701
  }
2588
2702
  if (isSignal(value)) {
2589
- const lastNode = this.getLastNode();
2590
- const signalData = new EffectData({
2703
+ const lastNode = this.getOrCreateLastNode();
2704
+ const signalData = new SubscriptionData({
2591
2705
  $scopedStyleIdPrefix$: styleScopedId,
2592
2706
  $isConst$: isConst
2593
2707
  });
@@ -2604,7 +2718,7 @@ var SSRContainer = class extends _SharedContainer {
2604
2718
  if (tag === "textarea" && key === "value") {
2605
2719
  if (value && typeof value !== "string") {
2606
2720
  if (isDev4) {
2607
- throw qError(40 /* wrongTextareaValue */, [currentFile, value]);
2721
+ throw qError(23 /* wrongTextareaValue */, [currentFile, value]);
2608
2722
  }
2609
2723
  continue;
2610
2724
  }
@@ -2640,7 +2754,7 @@ var isQwikStyleElement = (tag, attrs) => {
2640
2754
  return false;
2641
2755
  };
2642
2756
  function newTagError(text) {
2643
- return qError(29 /* tagError */, [text]);
2757
+ return qError(12 /* tagError */, [text]);
2644
2758
  }
2645
2759
  function hasDestroy(obj) {
2646
2760
  return obj && typeof obj === "object" && typeof obj.$destroy$ === "function";
@@ -2659,6 +2773,7 @@ function hash() {
2659
2773
  }
2660
2774
 
2661
2775
  // packages/qwik/src/server/ssr-render.ts
2776
+ import { manifest as builtManifest } from "@qwik-client-manifest";
2662
2777
  var renderToString = async (jsx, opts = {}) => {
2663
2778
  const chunks = [];
2664
2779
  const stream = {
@@ -2666,22 +2781,9 @@ var renderToString = async (jsx, opts = {}) => {
2666
2781
  chunks.push(chunk);
2667
2782
  }
2668
2783
  };
2669
- const result = await renderToStream(jsx, {
2670
- base: opts.base,
2671
- containerAttributes: opts.containerAttributes,
2672
- containerTagName: opts.containerTagName,
2673
- locale: opts.locale,
2674
- manifest: opts.manifest,
2675
- symbolMapper: opts.symbolMapper,
2676
- qwikLoader: opts.qwikLoader,
2677
- serverData: opts.serverData,
2678
- prefetchStrategy: opts.prefetchStrategy,
2679
- debug: opts.debug,
2680
- stream
2681
- });
2784
+ const result = await renderToStream(jsx, { ...opts, stream });
2682
2785
  return {
2683
2786
  isStatic: result.isStatic,
2684
- prefetchResources: result.prefetchResources,
2685
2787
  timing: result.timing,
2686
2788
  manifest: result.manifest,
2687
2789
  snapshotResult: result.snapshotResult,
@@ -2714,14 +2816,12 @@ var renderToStream = async (jsx, opts) => {
2714
2816
  const snapshotResult = getSnapshotResult(ssrContainer);
2715
2817
  const isDynamic = snapshotResult.resources.some((r) => r._cache !== Infinity);
2716
2818
  const result = {
2717
- prefetchResources: ssrContainer.prefetchResources,
2718
2819
  snapshotResult,
2719
2820
  flushes: networkFlushes,
2720
2821
  manifest: resolvedManifest?.manifest,
2721
2822
  size: totalSize,
2722
2823
  isStatic: !isDynamic,
2723
- timing,
2724
- _symbols: Array.from(ssrContainer.serializationCtx.$renderSymbols$)
2824
+ timing
2725
2825
  };
2726
2826
  return result;
2727
2827
  };
@@ -2833,21 +2933,19 @@ function shouldSkipChunk(chunk) {
2833
2933
  return chunk === void 0 || chunk === null || chunk === "<!--" + FLUSH_COMMENT + "-->" || chunk === "<!--" + STREAM_BLOCK_START_COMMENT + "-->" || chunk === "<!--" + STREAM_BLOCK_END_COMMENT + "-->";
2834
2934
  }
2835
2935
  function resolveManifest(manifest) {
2836
- if (!manifest) {
2837
- return void 0;
2838
- }
2839
- if ("mapper" in manifest) {
2840
- return manifest;
2936
+ const mergedManifest = manifest ? { ...builtManifest, ...manifest } : builtManifest;
2937
+ if (!mergedManifest || "mapper" in mergedManifest) {
2938
+ return mergedManifest;
2841
2939
  }
2842
- manifest = getValidManifest(manifest);
2843
- if (manifest) {
2940
+ if (mergedManifest.mapping) {
2844
2941
  const mapper = {};
2845
- Object.entries(manifest.mapping).forEach(([key, value]) => {
2846
- mapper[getSymbolHash(key)] = [key, value];
2942
+ Object.entries(mergedManifest.mapping).forEach(([symbol, bundleFilename]) => {
2943
+ mapper[getSymbolHash(symbol)] = [symbol, bundleFilename];
2847
2944
  });
2848
2945
  return {
2849
2946
  mapper,
2850
- manifest
2947
+ manifest: mergedManifest,
2948
+ injections: mergedManifest.injections || []
2851
2949
  };
2852
2950
  }
2853
2951
  return void 0;
@@ -2866,5 +2964,5 @@ export {
2866
2964
  renderToString,
2867
2965
  resolveManifest,
2868
2966
  setServerPlatform2 as setServerPlatform,
2869
- versions2 as versions
2967
+ versions
2870
2968
  };