@qwik.dev/core 2.0.0-alpha.5 → 2.0.0-alpha.7

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 (53) 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.win32-x64-msvc.node +0 -0
  5. package/bindings/qwik_wasm_bg.wasm +0 -0
  6. package/dist/build/package.json +1 -1
  7. package/dist/cli.cjs +65 -63
  8. package/dist/core-internal.d.ts +78 -77
  9. package/dist/core.cjs +1770 -1517
  10. package/dist/core.cjs.map +1 -1
  11. package/dist/core.min.mjs +1 -1
  12. package/dist/core.mjs +1768 -1517
  13. package/dist/core.mjs.map +1 -1
  14. package/dist/core.prod.cjs +985 -848
  15. package/dist/core.prod.mjs +1210 -1032
  16. package/dist/insights/index.qwik.cjs +3658 -160
  17. package/dist/insights/index.qwik.mjs +3658 -160
  18. package/dist/loader/index.cjs +2 -2
  19. package/dist/loader/index.mjs +2 -2
  20. package/dist/loader/package.json +1 -1
  21. package/dist/optimizer.cjs +230 -5691
  22. package/dist/optimizer.mjs +192 -5992
  23. package/dist/prefetch/package.json +1 -1
  24. package/dist/qwikloader.debug.js +12 -15
  25. package/dist/qwikloader.js +2 -2
  26. package/dist/server.cjs +754 -7067
  27. package/dist/server.mjs +771 -7062
  28. package/dist/starters/adapters/fastify/src/plugins/fastify-qwik.ts +2 -0
  29. package/dist/starters/features/cypress/package.json +1 -1
  30. package/dist/starters/features/drizzle/drizzle/schema.ts +6 -18
  31. package/dist/starters/features/drizzle/drizzle.config.ts +5 -4
  32. package/dist/starters/features/drizzle/package.json +14 -11
  33. package/dist/starters/features/pandacss/package.json +1 -1
  34. package/dist/starters/features/partytown/package.json +1 -1
  35. package/dist/starters/features/postcss/package.json +1 -1
  36. package/dist/starters/features/prisma/package.json +1 -1
  37. package/dist/starters/features/react/package.json +1 -1
  38. package/dist/starters/features/storybook/package.json +1 -1
  39. package/dist/starters/features/styled-vanilla-extract/package.json +2 -1
  40. package/dist/starters/features/tailwind/package.json +15 -9
  41. package/dist/starters/features/tailwind/src/global.css +1 -7
  42. package/dist/starters/features/turso/package.json +1 -1
  43. package/dist/starters/features/turso/src/utils/turso.ts +1 -1
  44. package/dist/starters/features/vitest/package.json +1 -1
  45. package/dist/testing/index.cjs +1445 -1252
  46. package/dist/testing/index.mjs +1455 -1256
  47. package/dist/testing/package.json +1 -1
  48. package/handlers.mjs +9 -0
  49. package/package.json +7 -5
  50. package/public.d.ts +2 -0
  51. package/dist/starters/features/tailwind/.vscode/settings.json +0 -3
  52. package/dist/starters/features/tailwind/postcss.config.cjs +0 -6
  53. package/dist/starters/features/tailwind/tailwind.config.js +0 -8
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * @license
3
- * @qwik.dev/core 2.0.0-alpha.5-dev+cb53bbd
3
+ * @qwik.dev/core 2.0.0-alpha.7-dev+a26598a
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
7
7
  */
8
- import { isServer, isDev } from "@qwik.dev/core/build";
8
+ import { isDev, isServer } from "@qwik.dev/core/build";
9
9
 
10
10
  export { isBrowser, isDev, isServer } from "@qwik.dev/core/build";
11
11
 
@@ -80,8 +80,8 @@ const codeToText = code => `Code(Q${code}) https://github.com/QwikDev/qwik/blob/
80
80
  var QError;
81
81
 
82
82
  !function(QError) {
83
- QError[QError.stringifyClassOrStyle = 0] = "stringifyClassOrStyle", QError[QError.UNUSED_1 = 1] = "UNUSED_1",
84
- QError[QError.UNUSED_2 = 2] = "UNUSED_2", QError[QError.verifySerializable = 3] = "verifySerializable",
83
+ QError[QError.stringifyClassOrStyle = 0] = "stringifyClassOrStyle", QError[QError.schedulerNotFound = 1] = "schedulerNotFound",
84
+ QError[QError.trackObjectWithoutProp = 2] = "trackObjectWithoutProp", QError[QError.verifySerializable = 3] = "verifySerializable",
85
85
  QError[QError.UNUSED_4 = 4] = "UNUSED_4", QError[QError.cannotRenderOverExistingContainer = 5] = "cannotRenderOverExistingContainer",
86
86
  QError[QError.UNUSED_6 = 6] = "UNUSED_6", QError[QError.UNUSED_7 = 7] = "UNUSED_7",
87
87
  QError[QError.UNUSED_8 = 8] = "UNUSED_8", QError[QError.UNUSED_9 = 9] = "UNUSED_9",
@@ -104,10 +104,9 @@ var QError;
104
104
  QError[QError.serializeErrorMissingChunk = 39] = "serializeErrorMissingChunk", QError[QError.wrongTextareaValue = 40] = "wrongTextareaValue",
105
105
  QError[QError.containerNotFound = 41] = "containerNotFound", QError[QError.elementWithoutContainer = 42] = "elementWithoutContainer",
106
106
  QError[QError.invalidVNodeType = 43] = "invalidVNodeType", QError[QError.materializeVNodeDataError = 44] = "materializeVNodeDataError",
107
- QError[QError.serverHostMismatch = 45] = "serverHostMismatch", QError[QError.cannotCoerceSignal = 46] = "cannotCoerceSignal",
108
- QError[QError.computedNotSync = 47] = "computedNotSync", QError[QError.computedReadOnly = 48] = "computedReadOnly",
109
- QError[QError.wrappedReadOnly = 49] = "wrappedReadOnly", QError[QError.promisesNotExpected = 50] = "promisesNotExpected",
110
- QError[QError.unsafeAttr = 51] = "unsafeAttr";
107
+ QError[QError.cannotCoerceSignal = 45] = "cannotCoerceSignal", QError[QError.computedNotSync = 46] = "computedNotSync",
108
+ QError[QError.computedReadOnly = 47] = "computedReadOnly", QError[QError.wrappedReadOnly = 48] = "wrappedReadOnly",
109
+ QError[QError.unsafeAttr = 49] = "unsafeAttr";
111
110
  }(QError || (QError = {}));
112
111
 
113
112
  const qError = (code, errorMessageArgs = []) => {
@@ -115,117 +114,23 @@ const qError = (code, errorMessageArgs = []) => {
115
114
  return logErrorAndStop(text, ...errorMessageArgs);
116
115
  };
117
116
 
118
- const createPlatform = () => ({
119
- isServer,
120
- importSymbol(containerEl, url, symbolName) {
121
- if (isServer) {
122
- const hash = getSymbolHash(symbolName);
123
- const regSym = globalThis.__qwik_reg_symbols?.get(hash);
124
- if (regSym) {
125
- return regSym;
126
- }
127
- }
128
- if (!url) {
129
- throw qError(QError.qrlMissingChunk, [ symbolName ]);
130
- }
131
- if (!containerEl) {
132
- throw qError(QError.qrlMissingContainer, [ url, symbolName ]);
133
- }
134
- const urlDoc = toUrl(containerEl.ownerDocument, containerEl, url).toString();
135
- const urlCopy = new URL(urlDoc);
136
- urlCopy.hash = "";
137
- return import(urlCopy.href).then((mod => mod[symbolName]));
138
- },
139
- raf: fn => new Promise((resolve => {
140
- requestAnimationFrame((() => {
141
- resolve(fn());
142
- }));
143
- })),
144
- nextTick: fn => new Promise((resolve => {
145
- setTimeout((() => {
146
- resolve(fn());
147
- }));
148
- })),
149
- chunkForSymbol: (symbolName, chunk) => [ symbolName, chunk ?? "_" ]
150
- });
151
-
152
- const toUrl = (doc, containerEl, url) => {
153
- const baseURI = doc.baseURI;
154
- const base = new URL(containerEl.getAttribute("q:base") ?? baseURI, baseURI);
155
- return new URL(url, base);
156
- };
157
-
158
- let _platform = /*#__PURE__ */ createPlatform();
159
-
160
- const setPlatform = plt => _platform = plt;
161
-
162
- const getPlatform = () => _platform;
163
-
164
- const isServerPlatform = () => _platform.isServer;
165
-
166
- const isNode = value => value && "number" == typeof value.nodeType;
167
-
168
- const isDocument = value => 9 === value.nodeType;
169
-
170
- const isElement$1 = value => 1 === value.nodeType;
171
-
172
- const MAX_RETRY_ON_PROMISE_COUNT = 100;
173
-
174
- const isPromise = value => !!value && "object" == typeof value && "function" == typeof value.then;
175
-
176
- const safeCall = (call, thenFn, rejectFn) => {
177
- try {
178
- const result = call();
179
- return isPromise(result) ? result.then(thenFn, rejectFn) : thenFn(result);
180
- } catch (e) {
181
- return rejectFn(e);
182
- }
183
- };
184
-
185
- const maybeThen = (valueOrPromise, thenFn) => isPromise(valueOrPromise) ? valueOrPromise.then(thenFn, shouldNotError) : thenFn(valueOrPromise);
186
-
187
- const maybeThenPassError = (valueOrPromise, thenFn) => isPromise(valueOrPromise) ? valueOrPromise.then(thenFn) : thenFn(valueOrPromise);
117
+ const SYNC_QRL = "<sync>";
188
118
 
189
- const shouldNotError = reason => {
190
- throwErrorAndStop(reason);
191
- };
119
+ const isSyncQrl = value => isQrl$1(value) && "<sync>" == value.$symbol$;
192
120
 
193
- const delay = timeout => new Promise((resolve => {
194
- setTimeout(resolve, timeout);
195
- }));
121
+ const isQrl$1 = value => "function" == typeof value && "function" == typeof value.getSymbol;
196
122
 
197
- function retryOnPromise(fn, retryCount = 0) {
198
- try {
199
- return fn();
200
- } catch (e) {
201
- if (isPromise(e) && retryCount < 100) {
202
- return e.then(retryOnPromise.bind(null, fn, retryCount++));
203
- }
204
- throw e;
123
+ function assertQrl(qrl) {
124
+ if (isDev && !isQrl$1(qrl)) {
125
+ throw new Error("Not a QRL");
205
126
  }
206
127
  }
207
128
 
208
- const isSerializableObject = v => {
209
- const proto = Object.getPrototypeOf(v);
210
- return proto === Object.prototype || proto === Array.prototype || null === proto;
129
+ const getSymbolHash = symbolName => {
130
+ const index = symbolName.lastIndexOf("_");
131
+ return index > -1 ? symbolName.slice(index + 1) : symbolName;
211
132
  };
212
133
 
213
- const isObject = v => !!v && "object" == typeof v;
214
-
215
- const isArray = v => Array.isArray(v);
216
-
217
- const isString = v => "string" == typeof v;
218
-
219
- const isFunction = v => "function" == typeof v;
220
-
221
- var VNodeDataFlag;
222
-
223
- !function(VNodeDataFlag) {
224
- VNodeDataFlag[VNodeDataFlag.NONE = 0] = "NONE", VNodeDataFlag[VNodeDataFlag.TEXT_DATA = 1] = "TEXT_DATA",
225
- VNodeDataFlag[VNodeDataFlag.VIRTUAL_NODE = 2] = "VIRTUAL_NODE", VNodeDataFlag[VNodeDataFlag.ELEMENT_NODE = 4] = "ELEMENT_NODE",
226
- VNodeDataFlag[VNodeDataFlag.REFERENCE = 8] = "REFERENCE", VNodeDataFlag[VNodeDataFlag.SERIALIZE = 16] = "SERIALIZE";
227
- }(VNodeDataFlag || (VNodeDataFlag = {}));
228
-
229
134
  const DEBUG_TYPE = "q:type";
230
135
 
231
136
  var VirtualType;
@@ -259,7 +164,7 @@ var QContainerValue;
259
164
 
260
165
  const OnRenderProp = "q:renderFn";
261
166
 
262
- const ComponentStylesPrefixContent = "⭐️";
167
+ const ComponentStylesPrefixContent = "⚡️";
263
168
 
264
169
  const QSlot = "q:slot";
265
170
 
@@ -281,7 +186,7 @@ const QScopedStyle = "q:sstyle";
281
186
 
282
187
  const QCtxAttr = "q:ctx";
283
188
 
284
- const QSubscribers = "q:subs";
189
+ const QBackRefs = "q:brefs";
285
190
 
286
191
  const QFuncsPrefix = "qFuncs_";
287
192
 
@@ -357,6 +262,113 @@ const dangerouslySetInnerHTML = "dangerouslySetInnerHTML";
357
262
 
358
263
  const qwikInspectorAttr = "data-qwik-inspector";
359
264
 
265
+ const createPlatform = () => ({
266
+ isServer,
267
+ importSymbol(containerEl, url, symbolName) {
268
+ if (isServer) {
269
+ const hash = getSymbolHash(symbolName);
270
+ const regSym = globalThis.__qwik_reg_symbols?.get(hash);
271
+ if (regSym) {
272
+ return regSym;
273
+ }
274
+ }
275
+ if (!url) {
276
+ throw qError(QError.qrlMissingChunk, [ symbolName ]);
277
+ }
278
+ if (!containerEl) {
279
+ throw qError(QError.qrlMissingContainer, [ url, symbolName ]);
280
+ }
281
+ const urlDoc = toUrl(containerEl.ownerDocument, containerEl, url).toString();
282
+ const urlCopy = new URL(urlDoc);
283
+ urlCopy.hash = "";
284
+ return import(urlCopy.href).then((mod => mod[symbolName]));
285
+ },
286
+ raf: fn => new Promise((resolve => {
287
+ requestAnimationFrame((() => {
288
+ resolve(fn());
289
+ }));
290
+ })),
291
+ nextTick: fn => new Promise((resolve => {
292
+ setTimeout((() => {
293
+ resolve(fn());
294
+ }));
295
+ })),
296
+ chunkForSymbol: (symbolName, chunk) => [ symbolName, chunk ?? "_" ]
297
+ });
298
+
299
+ const toUrl = (doc, containerEl, url) => {
300
+ const baseURI = doc.baseURI;
301
+ const base = new URL(containerEl.getAttribute("q:base") ?? baseURI, baseURI);
302
+ return new URL(url, base);
303
+ };
304
+
305
+ let _platform = /*#__PURE__ */ createPlatform();
306
+
307
+ const setPlatform = plt => _platform = plt;
308
+
309
+ const getPlatform = () => _platform;
310
+
311
+ const isServerPlatform = () => _platform.isServer;
312
+
313
+ const isNode = value => value && "number" == typeof value.nodeType;
314
+
315
+ const isDocument = value => 9 === value.nodeType;
316
+
317
+ const isElement$1 = value => 1 === value.nodeType;
318
+
319
+ const MAX_RETRY_ON_PROMISE_COUNT = 100;
320
+
321
+ const isPromise = value => !!value && "object" == typeof value && "function" == typeof value.then;
322
+
323
+ const safeCall = (call, thenFn, rejectFn) => {
324
+ try {
325
+ const result = call();
326
+ return isPromise(result) ? result.then(thenFn, rejectFn) : thenFn(result);
327
+ } catch (e) {
328
+ return rejectFn(e);
329
+ }
330
+ };
331
+
332
+ const maybeThen = (valueOrPromise, thenFn) => isPromise(valueOrPromise) ? valueOrPromise.then(thenFn, shouldNotError) : thenFn(valueOrPromise);
333
+
334
+ const shouldNotError = reason => {
335
+ throwErrorAndStop(reason);
336
+ };
337
+
338
+ const delay = timeout => new Promise((resolve => {
339
+ setTimeout(resolve, timeout);
340
+ }));
341
+
342
+ function retryOnPromise(fn, retryCount = 0) {
343
+ const retryOrThrow = e => {
344
+ if (isPromise(e) && retryCount < 100) {
345
+ return e.then(retryOnPromise.bind(null, fn, retryCount++));
346
+ }
347
+ throw e;
348
+ };
349
+ try {
350
+ const result = fn();
351
+ return isPromise(result) ? result.catch((e => retryOrThrow(e))) : result;
352
+ } catch (e) {
353
+ return retryOrThrow(e);
354
+ }
355
+ }
356
+
357
+ const isSerializableObject = v => {
358
+ const proto = Object.getPrototypeOf(v);
359
+ return proto === Object.prototype || proto === Array.prototype || null === proto;
360
+ };
361
+
362
+ const isObject = v => !!v && "object" == typeof v;
363
+
364
+ const isArray = v => Array.isArray(v);
365
+
366
+ const isString = v => "string" == typeof v;
367
+
368
+ const isFunction = v => "function" == typeof v;
369
+
370
+ var VNodeDataFlag;
371
+
360
372
  let _locale;
361
373
 
362
374
  function getLocale(defaultLocale) {
@@ -386,7 +398,13 @@ function setLocale(locale) {
386
398
  _locale = locale;
387
399
  }
388
400
 
389
- const isQrl$1 = value => "function" == typeof value && "function" == typeof value.getSymbol;
401
+ !function(VNodeDataFlag) {
402
+ VNodeDataFlag[VNodeDataFlag.NONE = 0] = "NONE", VNodeDataFlag[VNodeDataFlag.TEXT_DATA = 1] = "TEXT_DATA",
403
+ VNodeDataFlag[VNodeDataFlag.VIRTUAL_NODE = 2] = "VIRTUAL_NODE", VNodeDataFlag[VNodeDataFlag.ELEMENT_NODE = 4] = "ELEMENT_NODE",
404
+ VNodeDataFlag[VNodeDataFlag.REFERENCE = 8] = "REFERENCE", VNodeDataFlag[VNodeDataFlag.SERIALIZE = 16] = "SERIALIZE";
405
+ }(VNodeDataFlag || (VNodeDataFlag = {}));
406
+
407
+ const isQrl = value => "function" == typeof value && "function" == typeof value.getSymbol;
390
408
 
391
409
  const EMPTY_ARRAY = [];
392
410
 
@@ -431,14 +449,14 @@ const qrl = (chunkOrFn, symbol, lexicalScopeCapture = EMPTY_ARRAY, stackOffset =
431
449
  chunk = chunkOrFn;
432
450
  }
433
451
  return announcedQRL.has(symbol) || (announcedQRL.add(symbol), emitEvent("qprefetch", {
434
- symbols: [ getSymbolHash(symbol) ],
452
+ symbols: [ symbol ],
435
453
  bundles: chunk && [ chunk ]
436
- })), createQRL(chunk, symbol, null, symbolFn, null, lexicalScopeCapture, null);
454
+ })), createQRL(chunk, symbol, null, symbolFn, null, lexicalScopeCapture);
437
455
  };
438
456
 
439
- const inlinedQrl = (symbol, symbolName, lexicalScopeCapture = EMPTY_ARRAY) => createQRL(null, symbolName, symbol, null, null, lexicalScopeCapture, null);
457
+ const inlinedQrl = (symbol, symbolName, lexicalScopeCapture = EMPTY_ARRAY) => createQRL(null, symbolName, symbol, null, null, lexicalScopeCapture);
440
458
 
441
- const _noopQrl = (symbolName, lexicalScopeCapture = EMPTY_ARRAY) => createQRL(null, symbolName, null, null, null, lexicalScopeCapture, null);
459
+ const _noopQrl = (symbolName, lexicalScopeCapture = EMPTY_ARRAY) => createQRL(null, symbolName, null, null, null, lexicalScopeCapture);
442
460
 
443
461
  const _noopQrlDEV = (symbolName, opts, lexicalScopeCapture = EMPTY_ARRAY) => {
444
462
  const newQrl = _noopQrl(symbolName, lexicalScopeCapture);
@@ -458,6 +476,43 @@ const inlinedQrlDEV = (symbol, symbolName, opts, lexicalScopeCapture = EMPTY_ARR
458
476
  const _regSymbol = (symbol, hash) => (void 0 === globalThis.__qwik_reg_symbols && (globalThis.__qwik_reg_symbols = new Map),
459
477
  globalThis.__qwik_reg_symbols.set(hash, symbol), symbol);
460
478
 
479
+ var ChoreType;
480
+
481
+ !function(ChoreType) {
482
+ ChoreType[ChoreType.MACRO = 240] = "MACRO", ChoreType[ChoreType.MICRO = 15] = "MICRO",
483
+ ChoreType[ChoreType.QRL_RESOLVE = 1] = "QRL_RESOLVE", ChoreType[ChoreType.RUN_QRL = 2] = "RUN_QRL",
484
+ ChoreType[ChoreType.TASK = 3] = "TASK", ChoreType[ChoreType.NODE_DIFF = 4] = "NODE_DIFF",
485
+ ChoreType[ChoreType.NODE_PROP = 5] = "NODE_PROP", ChoreType[ChoreType.COMPONENT = 6] = "COMPONENT",
486
+ ChoreType[ChoreType.RECOMPUTE_AND_SCHEDULE_EFFECTS = 7] = "RECOMPUTE_AND_SCHEDULE_EFFECTS",
487
+ ChoreType[ChoreType.JOURNAL_FLUSH = 16] = "JOURNAL_FLUSH", ChoreType[ChoreType.VISIBLE = 32] = "VISIBLE",
488
+ ChoreType[ChoreType.CLEANUP_VISIBLE = 48] = "CLEANUP_VISIBLE", ChoreType[ChoreType.WAIT_FOR_ALL = 255] = "WAIT_FOR_ALL";
489
+ }(ChoreType || (ChoreType = {}));
490
+
491
+ const useLexicalScope = () => {
492
+ const context = getInvokeContext();
493
+ let qrl = context.$qrl$;
494
+ if (qrl) {
495
+ assertQrl(qrl), assertDefined(qrl.$captureRef$, "invoke: qrl $captureRef$ must be defined inside useLexicalScope()", qrl);
496
+ } else {
497
+ const el = context.$element$;
498
+ assertDefined(el, "invoke: element must be defined inside useLexicalScope()", context);
499
+ const containerElement = _getQContainerElement(el);
500
+ assertDefined(containerElement, "invoke: cant find parent q:container of", el);
501
+ qrl = getDomContainer(containerElement).parseQRL(decodeURIComponent(String(context.$url$)));
502
+ }
503
+ return qrl.$captureRef$;
504
+ };
505
+
506
+ const queueQRL = (...args) => {
507
+ const [runQrl] = useLexicalScope();
508
+ const hostElement = getInvokeContext().$hostElement$;
509
+ const scheduler = getDomContainer(hostElement).$scheduler$;
510
+ if (!scheduler) {
511
+ throw qError(QError.schedulerNotFound);
512
+ }
513
+ return scheduler(ChoreType.RUN_QRL, hostElement, runQrl, args);
514
+ };
515
+
461
516
  const Slot = props => _jsxSorted(Virtual, null, {
462
517
  [QSlotS]: ""
463
518
  }, props.children, 0, props.name ?? "");
@@ -536,13 +591,54 @@ function isPreventDefault(key) {
536
591
  return key.startsWith("preventdefault:");
537
592
  }
538
593
 
539
- const unitlessNumbers = new Set([ "animationIterationCount", "aspectRatio", "borderImageOutset", "borderImageSlice", "borderImageWidth", "boxFlex", "boxFlexGroup", "boxOrdinalGroup", "columnCount", "columns", "flex", "flexGrow", "flexShrink", "gridArea", "gridRow", "gridRowEnd", "gridRowStart", "gridColumn", "gridColumnEnd", "gridColumnStart", "fontWeight", "lineClamp", "lineHeight", "opacity", "order", "orphans", "scale", "tabSize", "widows", "zIndex", "zoom", "MozAnimationIterationCount", "MozBoxFlex", "msFlex", "msFlexPositive", "WebkitAnimationIterationCount", "WebkitBoxFlex", "WebkitBoxOrdinalGroup", "WebkitColumnCount", "WebkitColumns", "WebkitFlex", "WebkitFlexGrow", "WebkitFlexShrink", "WebkitLineClamp" ]);
594
+ function getFileLocationFromJsx(jsxDev) {
595
+ if (!jsxDev) {
596
+ return null;
597
+ }
598
+ const sanitizedFileName = jsxDev.fileName?.replace(/\\/g, "/");
599
+ return sanitizedFileName ? `${sanitizedFileName}:${jsxDev.lineNumber}:${jsxDev.columnNumber}` : null;
600
+ }
540
601
 
541
- const isUnitlessNumber = name => unitlessNumbers.has(name);
602
+ const styleContent = styleId => "⚡️" + styleId;
542
603
 
543
- const hashCode = (text, hash = 0) => {
544
- for (let i = 0; i < text.length; i++) {
545
- hash = (hash << 5) - hash + text.charCodeAt(i), hash |= 0;
604
+ function hasClassAttr(props) {
605
+ for (const key in props) {
606
+ if (Object.prototype.hasOwnProperty.call(props, key) && isClassAttr(key)) {
607
+ return !0;
608
+ }
609
+ }
610
+ return !1;
611
+ }
612
+
613
+ function isClassAttr(key) {
614
+ return "class" === key || "className" === key;
615
+ }
616
+
617
+ function convertScopedStyleIdsToArray(scopedStyleIds) {
618
+ return scopedStyleIds?.split(" ") ?? null;
619
+ }
620
+
621
+ function convertStyleIdsToString(scopedStyleIds) {
622
+ return Array.from(scopedStyleIds).join(" ");
623
+ }
624
+
625
+ const addComponentStylePrefix = styleId => {
626
+ if (styleId) {
627
+ let idx = 0;
628
+ do {
629
+ styleId = styleId.substring(0, idx) + styleContent(styleId.substring(idx));
630
+ } while (0 !== (idx = styleId.indexOf(" ", idx) + 1));
631
+ }
632
+ return styleId || null;
633
+ };
634
+
635
+ const unitlessNumbers = new Set([ "animationIterationCount", "aspectRatio", "borderImageOutset", "borderImageSlice", "borderImageWidth", "boxFlex", "boxFlexGroup", "boxOrdinalGroup", "columnCount", "columns", "flex", "flexGrow", "flexShrink", "gridArea", "gridRow", "gridRowEnd", "gridRowStart", "gridColumn", "gridColumnEnd", "gridColumnStart", "fontWeight", "lineClamp", "lineHeight", "opacity", "order", "orphans", "scale", "tabSize", "widows", "zIndex", "zoom", "MozAnimationIterationCount", "MozBoxFlex", "msFlex", "msFlexPositive", "WebkitAnimationIterationCount", "WebkitBoxFlex", "WebkitBoxOrdinalGroup", "WebkitColumnCount", "WebkitColumns", "WebkitFlex", "WebkitFlexGrow", "WebkitFlexShrink", "WebkitLineClamp" ]);
636
+
637
+ const isUnitlessNumber = name => unitlessNumbers.has(name);
638
+
639
+ const hashCode = (text, hash = 0) => {
640
+ for (let i = 0; i < text.length; i++) {
641
+ hash = (hash << 5) - hash + text.charCodeAt(i), hash |= 0;
546
642
  }
547
643
  return Number(Math.abs(hash)).toString(36);
548
644
  };
@@ -616,39 +712,6 @@ function isAriaAttribute(prop) {
616
712
 
617
713
  const styleKey = (qStyles, index) => (assertQrl(qStyles), `${hashCode(qStyles.$hash$)}-${index}`);
618
714
 
619
- const styleContent = styleId => "⭐️" + styleId;
620
-
621
- function hasClassAttr(props) {
622
- for (const key in props) {
623
- if (Object.prototype.hasOwnProperty.call(props, key) && isClassAttr(key)) {
624
- return !0;
625
- }
626
- }
627
- return !1;
628
- }
629
-
630
- function isClassAttr(key) {
631
- return "class" === key || "className" === key;
632
- }
633
-
634
- function convertScopedStyleIdsToArray(scopedStyleIds) {
635
- return scopedStyleIds?.split(" ") ?? null;
636
- }
637
-
638
- function convertStyleIdsToString(scopedStyleIds) {
639
- return Array.from(scopedStyleIds).join(" ");
640
- }
641
-
642
- const addComponentStylePrefix = styleId => {
643
- if (styleId) {
644
- let idx = 0;
645
- do {
646
- styleId = styleId.substring(0, idx) + styleContent(styleId.substring(idx));
647
- } while (0 !== (idx = styleId.indexOf(" ", idx) + 1));
648
- }
649
- return styleId || null;
650
- };
651
-
652
715
  const STORE_TARGET = Symbol("store.target");
653
716
 
654
717
  const STORE_HANDLER = Symbol("store.handler");
@@ -752,18 +815,19 @@ class StoreHandler {
752
815
  Reflect.ownKeys(target);
753
816
  }
754
817
  getOwnPropertyDescriptor(target, prop) {
755
- return Array.isArray(target) || "symbol" == typeof prop ? Object.getOwnPropertyDescriptor(target, prop) : {
818
+ const descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
819
+ return Array.isArray(target) || "symbol" == typeof prop || descriptor && !descriptor.configurable ? descriptor : {
756
820
  enumerable: !0,
757
821
  configurable: !0
758
822
  };
759
823
  }
760
824
  }
761
825
 
762
- function addEffect(target, prop, store, effectSubscriber) {
763
- const effectsMap = store.$effects$ ||= {};
764
- const effects = Object.prototype.hasOwnProperty.call(effectsMap, prop) && effectsMap[prop] || (effectsMap[prop] = []);
765
- ensureContainsEffect(effects, effectSubscriber), ensureContains(effectSubscriber, target),
766
- ensureEffectContainsSubscriber(effectSubscriber[EffectSubscriptionsProp.EFFECT], target, store.$container$);
826
+ function addEffect(target, prop, store, effectSubscription) {
827
+ const effectsMap = store.$effects$ ||= new Map;
828
+ let effects = effectsMap.get(prop);
829
+ effects || (effects = new Set, effectsMap.set(prop, effects)), ensureContainsSubscription(effects, effectSubscription),
830
+ ensureContainsBackRef(effectSubscription, target), addQrlToSerializationCtx(effectSubscription, store.$container$);
767
831
  }
768
832
 
769
833
  function setNewValueAndTriggerEffects(prop, value, target, currentStore) {
@@ -771,12 +835,87 @@ function setNewValueAndTriggerEffects(prop, value, target, currentStore) {
771
835
  }
772
836
 
773
837
  function getEffects(target, prop, storeEffects) {
774
- let effectsToTrigger = storeEffects ? Array.isArray(target) ? Object.values(storeEffects).flatMap((effects => effects)) : storeEffects[prop] : null;
775
- const storeArrayValue = storeEffects?.[STORE_ARRAY_PROP];
776
- return storeArrayValue && (effectsToTrigger ||= [], effectsToTrigger.push(...storeArrayValue)),
777
- effectsToTrigger;
838
+ let effectsToTrigger;
839
+ if (storeEffects) {
840
+ if (Array.isArray(target)) {
841
+ for (const effects of storeEffects.values()) {
842
+ effectsToTrigger ||= new Set;
843
+ for (const effect of effects) {
844
+ effectsToTrigger.add(effect);
845
+ }
846
+ }
847
+ } else {
848
+ effectsToTrigger = storeEffects.get(prop);
849
+ }
850
+ }
851
+ const storeArrayValue = storeEffects?.get(STORE_ARRAY_PROP);
852
+ if (storeArrayValue) {
853
+ effectsToTrigger ||= new Set;
854
+ for (const effect of storeArrayValue) {
855
+ effectsToTrigger.add(effect);
856
+ }
857
+ }
858
+ return effectsToTrigger || null;
859
+ }
860
+
861
+ const NEEDS_COMPUTATION = Symbol("invalid");
862
+
863
+ const _EFFECT_BACK_REF = Symbol("backRef");
864
+
865
+ class BackRef {
866
+ [_EFFECT_BACK_REF]=null;
867
+ }
868
+
869
+ function clearAllEffects(container, consumer) {
870
+ vnode_isVNode(consumer) && vnode_isElementVNode(consumer) && ensureMaterialized(consumer);
871
+ const effects = consumer[_EFFECT_BACK_REF];
872
+ if (effects) {
873
+ for (const [, effect] of effects) {
874
+ const backRefs = effect[EffectSubscriptionProp.BACK_REF];
875
+ if (!backRefs) {
876
+ return;
877
+ }
878
+ for (const producer of backRefs) {
879
+ if (producer instanceof Signal) {
880
+ clearSignal(container, producer, effect);
881
+ } else if (container.$storeProxyMap$.has(producer)) {
882
+ const target = container.$storeProxyMap$.get(producer);
883
+ clearStore(getStoreHandler(target), effect);
884
+ }
885
+ }
886
+ }
887
+ }
888
+ }
889
+
890
+ function clearSignal(container, producer, effect) {
891
+ const effects = producer.$effects$;
892
+ effects && effects.delete(effect), producer instanceof WrappedSignal && (producer.$hostElement$ = null,
893
+ clearAllEffects(container, producer));
894
+ }
895
+
896
+ function clearStore(producer, effect) {
897
+ const effects = producer?.$effects$;
898
+ if (effects) {
899
+ for (const propEffects of effects.values()) {
900
+ propEffects.delete(effect);
901
+ }
902
+ }
778
903
  }
779
904
 
905
+ const implicit$FirstArg = fn => function(first, ...rest) {
906
+ return fn.call(null, dollar(first), ...rest);
907
+ };
908
+
909
+ const createSignal$1 = value => new Signal(null, value);
910
+
911
+ const createComputedSignal = qrl => (throwIfQRLNotResolved(qrl), new ComputedSignal(null, qrl));
912
+
913
+ const createSignal = createSignal$1;
914
+
915
+ const createComputedQrl = createComputedSignal;
916
+
917
+ const createComputed$ = /*#__PURE__*/ implicit$FirstArg(createComputedQrl);
918
+
780
919
  const useSequentialScope = () => {
781
920
  const iCtx = useInvokeContext();
782
921
  const host = iCtx.$hostElement$;
@@ -794,235 +933,123 @@ const useSequentialScope = () => {
794
933
  };
795
934
  };
796
935
 
797
- class Subscriber {
798
- $effectDependencies$=null;
936
+ function getSubscriber(effect, prop, data) {
937
+ effect[_EFFECT_BACK_REF] || (isServer && isSsrNode(effect) ? effect.setProp("q:brefs", new Map) : effect[_EFFECT_BACK_REF] = new Map);
938
+ const subMap = effect[_EFFECT_BACK_REF];
939
+ let sub = subMap.get(prop);
940
+ return sub || (sub = [ effect, prop ], subMap.set(prop, sub)), data && (sub[EffectSubscriptionProp.DATA] = data),
941
+ sub;
799
942
  }
800
943
 
801
- function isSubscriber(value) {
802
- return value instanceof Subscriber || value instanceof WrappedSignal;
944
+ function isSsrNode(value) {
945
+ return "__brand__" in value && "currentComponentNode" in value;
803
946
  }
804
947
 
805
- function clearVNodeEffectDependencies(container, value) {
806
- vnode_isElementVNode(value) && ensureMaterialized(value);
807
- const effects = vnode_getProp(value, "q:subs", container.$getObjectById$);
808
- if (effects) {
809
- for (let i = effects.length - 1; i >= 0; i--) {
810
- clearEffects(effects[i], value, effects, i, container);
811
- }
812
- 0 === effects.length && vnode_setProp(value, "q:subs", null);
813
- }
814
- }
948
+ var TaskFlags;
815
949
 
816
- function clearSubscriberEffectDependencies(container, value) {
817
- if (value.$effectDependencies$) {
818
- for (let i = value.$effectDependencies$.length - 1; i >= 0; i--) {
819
- clearEffects(value.$effectDependencies$[i], value, value.$effectDependencies$, i, container);
820
- }
821
- 0 === value.$effectDependencies$.length && (value.$effectDependencies$ = null);
822
- }
823
- }
950
+ !function(TaskFlags) {
951
+ TaskFlags[TaskFlags.VISIBLE_TASK = 1] = "VISIBLE_TASK", TaskFlags[TaskFlags.TASK = 2] = "TASK",
952
+ TaskFlags[TaskFlags.RESOURCE = 4] = "RESOURCE", TaskFlags[TaskFlags.DIRTY = 8] = "DIRTY";
953
+ }(TaskFlags || (TaskFlags = {}));
824
954
 
825
- function clearEffects(subscriber, value, effectArray, indexToRemove, container) {
826
- let subscriptionRemoved = !1;
827
- const seenSet = new Set;
828
- if (subscriber instanceof WrappedSignal) {
829
- subscriptionRemoved = clearSignalEffects(subscriber, value, seenSet);
830
- } else if (container.$storeProxyMap$.has(subscriber)) {
831
- const store = container.$storeProxyMap$.get(subscriber);
832
- subscriptionRemoved = clearStoreEffects(getStoreHandler(store), value);
955
+ const useTaskQrl = qrl => {
956
+ const {val, set, iCtx, i} = useSequentialScope();
957
+ if (val) {
958
+ return;
833
959
  }
834
- subscriptionRemoved && effectArray.splice(indexToRemove, 1);
835
- }
960
+ assertQrl(qrl), set(1);
961
+ const task = new Task(TaskFlags.DIRTY | TaskFlags.TASK, i, iCtx.$hostElement$, qrl, void 0, null);
962
+ set(task);
963
+ const promise = iCtx.$container$.$scheduler$(ChoreType.TASK, task);
964
+ isPromise(promise) && promise.catch((() => {}));
965
+ };
836
966
 
837
- function clearSignalEffects(subscriber, value, seenSet) {
838
- const effectSubscriptions = subscriber.$effects$;
839
- let subscriptionRemoved = !1;
840
- if (effectSubscriptions) {
841
- for (let i = effectSubscriptions.length - 1; i >= 0; i--) {
842
- effectSubscriptions[i][EffectSubscriptionsProp.EFFECT] === value && (effectSubscriptions.splice(i, 1),
843
- subscriptionRemoved = !0);
967
+ const runTask = (task, container, host) => {
968
+ task.$flags$ &= ~TaskFlags.DIRTY, cleanupTask(task);
969
+ const iCtx = newInvokeContext(container.$locale$, host, void 0, "qTask");
970
+ iCtx.$container$ = container;
971
+ const taskFn = task.$qrl$.getFn(iCtx, (() => clearAllEffects(container, task)));
972
+ let cleanupFns = null;
973
+ const cleanup = fn => {
974
+ "function" == typeof fn && (cleanupFns || (cleanupFns = [], task.$destroy$ = noSerialize((() => {
975
+ task.$destroy$ = null, cleanupFns.forEach((fn => {
976
+ try {
977
+ fn();
978
+ } catch (err) {
979
+ container.handleError(err, host);
980
+ }
981
+ }));
982
+ }))), cleanupFns.push(fn));
983
+ };
984
+ const taskApi = {
985
+ track: (obj, prop) => {
986
+ const ctx = newInvokeContext();
987
+ return ctx.$effectSubscriber$ = getSubscriber(task, EffectProperty.COMPONENT), ctx.$container$ = container,
988
+ invoke(ctx, (() => {
989
+ if (isFunction(obj)) {
990
+ return obj();
991
+ }
992
+ if (prop) {
993
+ return obj[prop];
994
+ }
995
+ if (isSignal(obj)) {
996
+ return obj.value;
997
+ }
998
+ throw qError(QError.trackObjectWithoutProp);
999
+ }));
1000
+ },
1001
+ cleanup
1002
+ };
1003
+ return safeCall((() => taskFn(taskApi)), cleanup, (err => {
1004
+ if (isPromise(err)) {
1005
+ return err.then((() => runTask(task, container, host)));
844
1006
  }
845
- }
846
- if (subscriber instanceof WrappedSignal) {
847
- const hostElement = subscriber.$hostElement$;
848
- hostElement && hostElement === value && (subscriber.$hostElement$ = null);
849
- const args = subscriber.$args$;
850
- args && clearArgsEffects(args, subscriber, seenSet);
851
- }
852
- return subscriptionRemoved;
853
- }
1007
+ throw err;
1008
+ }));
1009
+ };
854
1010
 
855
- function clearStoreEffects(storeHandler, value) {
856
- const effectSubscriptions = storeHandler.$effects$;
857
- if (!effectSubscriptions) {
858
- return !1;
859
- }
860
- let subscriptionRemoved = !1;
861
- for (const key in effectSubscriptions) {
862
- const effects = effectSubscriptions[key];
863
- for (let i = effects.length - 1; i >= 0; i--) {
864
- effects[i][EffectSubscriptionsProp.EFFECT] === value && (effects.splice(i, 1), subscriptionRemoved = !0);
1011
+ const cleanupTask = task => {
1012
+ const destroy = task.$destroy$;
1013
+ if (destroy) {
1014
+ task.$destroy$ = null;
1015
+ try {
1016
+ destroy();
1017
+ } catch (err) {
1018
+ logError(err);
865
1019
  }
866
- 0 === effects.length && delete effectSubscriptions[key];
867
1020
  }
868
- return subscriptionRemoved;
869
- }
1021
+ };
870
1022
 
871
- function clearArgsEffects(args, subscriber, seenSet) {
872
- for (let i = args.length - 1; i >= 0; i--) {
873
- clearArgEffect(args[i], subscriber, seenSet);
1023
+ class Task extends BackRef {
1024
+ $flags$;
1025
+ $index$;
1026
+ $el$;
1027
+ $qrl$;
1028
+ $state$;
1029
+ $destroy$;
1030
+ constructor($flags$, $index$, $el$, $qrl$, $state$, $destroy$) {
1031
+ super(), this.$flags$ = $flags$, this.$index$ = $index$, this.$el$ = $el$, this.$qrl$ = $qrl$,
1032
+ this.$state$ = $state$, this.$destroy$ = $destroy$;
874
1033
  }
875
1034
  }
876
1035
 
877
- function clearArgEffect(arg, subscriber, seenSet) {
878
- if (!seenSet.has(arg)) {
879
- if (seenSet.add(arg), isSignal(arg)) {
880
- clearSignalEffects(arg, subscriber, seenSet);
881
- } else if ("object" == typeof arg && null !== arg) {
882
- if (isStore(arg)) {
883
- clearStoreEffects(getStoreHandler(arg), subscriber);
884
- } else {
885
- for (const key in arg) {
886
- clearArgEffect(arg[key], subscriber, seenSet);
887
- }
888
- }
889
- } else {
890
- Array.isArray(arg) && clearArgsEffects(arg, subscriber, seenSet);
891
- }
892
- }
893
- }
1036
+ const isTask = value => value instanceof Task;
894
1037
 
895
- const useResourceQrl = (qrl, opts) => {
896
- const {val, set, i, iCtx} = useSequentialScope();
897
- if (null != val) {
898
- return val;
899
- }
900
- assertQrl(qrl);
901
- const container = iCtx.$container$;
902
- const resource = createResourceReturn(container, opts);
903
- const task = new Task(TaskFlags.DIRTY | TaskFlags.RESOURCE, i, iCtx.$hostElement$, qrl, resource, null);
904
- return runResource(task, container, iCtx.$hostElement$), set(resource), resource;
1038
+ const scheduleTask = (_event, element) => {
1039
+ const [task] = useLexicalScope();
1040
+ const type = task.$flags$ & TaskFlags.VISIBLE_TASK ? ChoreType.VISIBLE : ChoreType.TASK;
1041
+ getDomContainer(element).$scheduler$(type, task);
905
1042
  };
906
1043
 
907
- const Resource = props => _jsxSorted(Fragment, null, null, getResourceValueAsPromise(props), 0, null);
1044
+ var VNodeFlags;
908
1045
 
909
- function getResourceValueAsPromise(props) {
910
- const resource = props.value;
911
- if (isResourceReturn(resource)) {
912
- if (!isServerPlatform()) {
913
- const state = resource._state;
914
- if ("pending" === state && props.onPending) {
915
- return Promise.resolve().then(useBindInvokeContext(props.onPending));
916
- }
917
- if ("rejected" === state && props.onRejected) {
918
- return Promise.resolve(resource._error).then(useBindInvokeContext(props.onRejected));
919
- }
920
- {
921
- const resolvedValue = untrack((() => resource._resolved));
922
- if (void 0 !== resolvedValue) {
923
- return Promise.resolve(resolvedValue).then(useBindInvokeContext(props.onResolved));
924
- }
925
- }
926
- }
927
- return resource.value.then(useBindInvokeContext(props.onResolved), useBindInvokeContext(props.onRejected));
928
- }
929
- return isPromise(resource) ? resource.then(useBindInvokeContext(props.onResolved), useBindInvokeContext(props.onRejected)) : isSignal(resource) ? Promise.resolve(resource.value).then(useBindInvokeContext(props.onResolved), useBindInvokeContext(props.onRejected)) : Promise.resolve(resource).then(useBindInvokeContext(props.onResolved), useBindInvokeContext(props.onRejected));
930
- }
1046
+ var VNodeFlagsIndex;
931
1047
 
932
- const _createResourceReturn = opts => ({
933
- __brand: "resource",
934
- value: void 0,
935
- loading: !isServerPlatform(),
936
- _resolved: void 0,
937
- _error: void 0,
938
- _state: "pending",
939
- _timeout: opts?.timeout ?? -1,
940
- _cache: 0
941
- });
1048
+ var VNodeProps;
942
1049
 
943
- const createResourceReturn = (container, opts, initialPromise) => {
944
- const result = _createResourceReturn(opts);
945
- return result.value = initialPromise, createStore(container, result, StoreFlags.RECURSIVE);
946
- };
1050
+ var ElementVNodeProps;
947
1051
 
948
- const isResourceReturn = obj => isObject(obj) && "resource" === (getStoreTarget(obj) || obj).__brand;
949
-
950
- const runResource = (task, container, host) => {
951
- task.$flags$ &= ~TaskFlags.DIRTY, cleanupTask(task);
952
- const iCtx = newInvokeContext(container.$locale$, host, void 0, "qResource");
953
- iCtx.$container$ = container;
954
- const taskFn = task.$qrl$.getFn(iCtx, (() => clearSubscriberEffectDependencies(container, task)));
955
- const resource = task.$state$;
956
- assertDefined(resource, 'useResource: when running a resource, "task.resource" must be a defined.', task);
957
- const cleanups = [];
958
- task.$destroy$ = noSerialize((() => {
959
- cleanups.forEach((fn => {
960
- try {
961
- fn();
962
- } catch (err) {
963
- container.handleError(err, host);
964
- }
965
- })), done = !0;
966
- }));
967
- const resourceTarget = unwrapStore(resource);
968
- const opts = {
969
- track: (obj, prop) => {
970
- const ctx = newInvokeContext();
971
- return ctx.$effectSubscriber$ = [ task, EffectProperty.COMPONENT ], ctx.$container$ = container,
972
- invoke(ctx, (() => isFunction(obj) ? obj() : prop ? obj[prop] : isSignal(obj) ? obj.value : obj));
973
- },
974
- cleanup(fn) {
975
- "function" == typeof fn && cleanups.push(fn);
976
- },
977
- cache(policy) {
978
- let milliseconds = 0;
979
- milliseconds = "immutable" === policy ? 1 / 0 : policy, resource._cache = milliseconds;
980
- },
981
- previous: resourceTarget._resolved
982
- };
983
- let resolve;
984
- let reject;
985
- let done = !1;
986
- const setState = (resolved, value) => !done && (done = !0, resolved ? (done = !0,
987
- resource.loading = !1, resource._state = "resolved", resource._resolved = value,
988
- resource._error = void 0, resolve(value)) : (done = !0, resource.loading = !1, resource._state = "rejected",
989
- resource._error = value, reject(value)), !0);
990
- cleanups.push((() => {
991
- if (!0 === untrack((() => resource.loading))) {
992
- const value = untrack((() => resource._resolved));
993
- setState(!0, value);
994
- }
995
- })), invoke(iCtx, (() => {
996
- resource._state = "pending", resource.loading = !isServerPlatform();
997
- (resource.value = new Promise(((r, re) => {
998
- resolve = r, reject = re;
999
- }))).catch(ignoreErrorToPreventNodeFromCrashing);
1000
- }));
1001
- const promise = safeCall((() => Promise.resolve(taskFn(opts))), (value => {
1002
- setState(!0, value);
1003
- }), (err => {
1004
- if (isPromise(err)) {
1005
- return err.then((() => runResource(task, container, host)));
1006
- }
1007
- setState(!1, err);
1008
- }));
1009
- const timeout = resourceTarget._timeout;
1010
- return timeout > 0 ? Promise.race([ promise, delay(timeout).then((() => {
1011
- setState(!1, new Error("timeout")) && cleanupTask(task);
1012
- })) ]) : promise;
1013
- };
1014
-
1015
- const ignoreErrorToPreventNodeFromCrashing = () => {};
1016
-
1017
- var VNodeFlags;
1018
-
1019
- var VNodeFlagsIndex;
1020
-
1021
- var VNodeProps;
1022
-
1023
- var ElementVNodeProps;
1024
-
1025
- var TextVNodeProps;
1052
+ var TextVNodeProps;
1026
1053
 
1027
1054
  var VirtualVNodeProps;
1028
1055
 
@@ -1053,7 +1080,32 @@ var VirtualVNodeProps;
1053
1080
  VirtualVNodeProps[VirtualVNodeProps.PROPS_OFFSET = 6] = "PROPS_OFFSET";
1054
1081
  }(VirtualVNodeProps || (VirtualVNodeProps = {}));
1055
1082
 
1056
- const isForeignObjectElement = elementName => "foreignobject" === elementName.toLowerCase();
1083
+ const mapApp_findIndx = (elementVNode, key, start) => {
1084
+ assertTrue(start % 2 == 0, "Expecting even number.");
1085
+ let bottom = start >> 1;
1086
+ let top = elementVNode.length - 2 >> 1;
1087
+ for (;bottom <= top; ) {
1088
+ const mid = bottom + (top - bottom >> 1);
1089
+ const midKey = elementVNode[mid << 1];
1090
+ if (midKey === key) {
1091
+ return mid << 1;
1092
+ }
1093
+ midKey < key ? bottom = mid + 1 : top = mid - 1;
1094
+ }
1095
+ return ~(bottom << 1);
1096
+ };
1097
+
1098
+ const mapArray_set = (elementVNode, key, value, start) => {
1099
+ const indx = mapApp_findIndx(elementVNode, key, start);
1100
+ indx >= 0 ? null == value ? elementVNode.splice(indx, 2) : elementVNode[indx + 1] = value : null != value && elementVNode.splice(~indx, 0, key, value);
1101
+ };
1102
+
1103
+ const mapArray_get = (elementVNode, key, start) => {
1104
+ const indx = mapApp_findIndx(elementVNode, key, start);
1105
+ return indx >= 0 ? elementVNode[indx + 1] : null;
1106
+ };
1107
+
1108
+ const isForeignObjectElement = elementName => isDev ? "foreignobject" === elementName.toLowerCase() : "foreignObject" === elementName;
1057
1109
 
1058
1110
  const isSvgElement = elementName => "svg" === elementName || isForeignObjectElement(elementName);
1059
1111
 
@@ -1061,7 +1113,18 @@ const isMathElement = elementName => "math" === elementName;
1061
1113
 
1062
1114
  const vnode_isDefaultNamespace = vnode => !(vnode[VNodeProps.flags] & VNodeFlags.NAMESPACE_MASK);
1063
1115
 
1064
- const vnode_getElementNamespaceFlags = elementName => isSvgElement(elementName) ? VNodeFlags.NS_svg : isMathElement(elementName) ? VNodeFlags.NS_math : VNodeFlags.NS_html;
1116
+ const vnode_getElementNamespaceFlags = element => {
1117
+ switch (fastNamespaceURI(element)) {
1118
+ case SVG_NS:
1119
+ return VNodeFlags.NS_svg;
1120
+
1121
+ case MATH_NS:
1122
+ return VNodeFlags.NS_math;
1123
+
1124
+ default:
1125
+ return VNodeFlags.NS_html;
1126
+ }
1127
+ };
1065
1128
 
1066
1129
  function vnode_getDomChildrenWithCorrectNamespacesToInsert(journal, domParentVNode, newChild) {
1067
1130
  const {elementNamespace, elementNamespaceFlag} = getNewElementNamespaceData(domParentVNode, newChild);
@@ -1232,14 +1295,14 @@ const useOnEventsSequentialScope = () => {
1232
1295
  };
1233
1296
 
1234
1297
  const executeComponent = (container, renderHost, subscriptionHost, componentQRL, props) => {
1235
- const iCtx = newInvokeContext(container.$locale$, subscriptionHost, void 0, "qRender");
1298
+ const iCtx = newInvokeContext(container.$locale$, subscriptionHost || void 0, void 0, "qRender");
1236
1299
  let componentFn;
1237
- iCtx.$effectSubscriber$ = [ subscriptionHost, EffectProperty.COMPONENT ], iCtx.$container$ = container,
1238
- container.ensureProjectionResolved(renderHost);
1300
+ subscriptionHost && (iCtx.$effectSubscriber$ = getSubscriber(subscriptionHost, EffectProperty.COMPONENT),
1301
+ iCtx.$container$ = container), container.ensureProjectionResolved(renderHost);
1239
1302
  let isInlineComponent = !1;
1240
- if (null === componentQRL && assertDefined(componentQRL = componentQRL || container.getHostProp(renderHost, "q:renderFn"), "No Component found at this location"),
1241
- isQrl(componentQRL)) {
1242
- (props = props || container.getHostProp(renderHost, "q:props") || EMPTY_OBJ) && props.children && delete props.children,
1303
+ if (null === componentQRL && assertDefined(componentQRL = container.getHostProp(renderHost, "q:renderFn"), "No Component found at this location"),
1304
+ isQrl$1(componentQRL)) {
1305
+ (props = props || container.getHostProp(renderHost, "q:props") || EMPTY_OBJ).children && delete props.children,
1243
1306
  componentFn = componentQRL.getFn(iCtx);
1244
1307
  } else if (isQwikComponent(componentQRL)) {
1245
1308
  const qComponentFn = componentQRL;
@@ -1250,11 +1313,10 @@ const executeComponent = (container, renderHost, subscriptionHost, componentQRL,
1250
1313
  componentFn = () => invokeApply(iCtx, inlineComponent, [ props || EMPTY_OBJ ]);
1251
1314
  }
1252
1315
  const executeComponentWithPromiseExceptionRetry = (retryCount = 0) => safeCall((() => (isInlineComponent || (container.setHostProp(renderHost, "q:seqIdx", null),
1253
- container.setHostProp(renderHost, ":onIdx", null), container.getHostProp(renderHost, "q:props") !== props && container.setHostProp(renderHost, "q:props", props)),
1254
- vnode_isVNode(renderHost) && clearVNodeEffectDependencies(container, renderHost),
1255
- componentFn(props))), (jsx => {
1316
+ container.setHostProp(renderHost, ":onIdx", null), container.setHostProp(renderHost, "q:props", props)),
1317
+ vnode_isVNode(renderHost) && clearAllEffects(container, renderHost), componentFn(props))), (jsx => {
1256
1318
  const useOnEvents = container.getHostProp(renderHost, ":on");
1257
- return useOnEvents ? maybeThen(addUseOnEvents(jsx, useOnEvents), (() => jsx)) : jsx;
1319
+ return useOnEvents ? addUseOnEvents(jsx, useOnEvents) : jsx;
1258
1320
  }), (err => {
1259
1321
  if (isPromise(err) && retryCount < 100) {
1260
1322
  return err.then((() => executeComponentWithPromiseExceptionRetry(retryCount++)));
@@ -1266,13 +1328,28 @@ const executeComponent = (container, renderHost, subscriptionHost, componentQRL,
1266
1328
 
1267
1329
  function addUseOnEvents(jsx, useOnEvents) {
1268
1330
  const jsxElement = findFirstStringJSX(jsx);
1331
+ let jsxResult = jsx;
1269
1332
  return maybeThen(jsxElement, (jsxElement => {
1270
1333
  let isInvisibleComponent = !1;
1271
1334
  jsxElement || (isInvisibleComponent = !0);
1272
1335
  for (const key in useOnEvents) {
1273
- Object.prototype.hasOwnProperty.call(useOnEvents, key) && (isInvisibleComponent ? "onQvisible$" === key ? (jsxElement = addScriptNodeForInvisibleComponents(jsx)) && addUseOnEvent(jsxElement, "document:onQinit$", useOnEvents[key]) : key.startsWith("document:") || key.startsWith("window:") ? (jsxElement = addScriptNodeForInvisibleComponents(jsx)) && addUseOnEvent(jsxElement, key, useOnEvents[key]) : isDev && logWarn('You are trying to add an event "' + key + '" using `useOn` hook, but a node to which you can add an event is not found. Please make sure that the component has a valid element node. ') : jsxElement && addUseOnEvent(jsxElement, key, useOnEvents[key]));
1336
+ if (Object.prototype.hasOwnProperty.call(useOnEvents, key)) {
1337
+ if (isInvisibleComponent) {
1338
+ if ("onQvisible$" === key) {
1339
+ const [jsxElement, jsx] = addScriptNodeForInvisibleComponents(jsxResult);
1340
+ jsxResult = jsx, jsxElement && addUseOnEvent(jsxElement, "document:onQinit$", useOnEvents[key]);
1341
+ } else if (key.startsWith("document:") || key.startsWith("window:")) {
1342
+ const [jsxElement, jsx] = addScriptNodeForInvisibleComponents(jsxResult);
1343
+ jsxResult = jsx, jsxElement && addUseOnEvent(jsxElement, key, useOnEvents[key]);
1344
+ } else {
1345
+ isDev && logWarn('You are trying to add an event "' + key + '" using `useOn` hook, but a node to which you can add an event is not found. Please make sure that the component has a valid element node. ');
1346
+ }
1347
+ } else {
1348
+ jsxElement && addUseOnEvent(jsxElement, key, useOnEvents[key]);
1349
+ }
1350
+ }
1274
1351
  }
1275
- return jsxElement;
1352
+ return jsxResult;
1276
1353
  }));
1277
1354
  }
1278
1355
 
@@ -1313,12 +1390,22 @@ function addScriptNodeForInvisibleComponents(jsx) {
1313
1390
  type: "placeholder",
1314
1391
  hidden: ""
1315
1392
  }, null, 3);
1316
- return null == jsx.children ? jsx.children = jsxElement : Array.isArray(jsx.children) ? jsx.children.push(jsxElement) : jsx.children = [ jsx.children, jsxElement ],
1317
- jsxElement;
1393
+ return jsx.type === Slot ? [ jsxElement, _jsxSorted(Fragment, null, null, [ jsx, jsxElement ], 0, null) ] : (null == jsx.children ? jsx.children = jsxElement : Array.isArray(jsx.children) ? jsx.children.push(jsxElement) : jsx.children = [ jsx.children, jsxElement ],
1394
+ [ jsxElement, jsx ]);
1395
+ }
1396
+ if (Array.isArray(jsx) && jsx.length) {
1397
+ const [jsxElement, _] = addScriptNodeForInvisibleComponents(jsx[0]);
1398
+ return [ jsxElement, jsx ];
1318
1399
  }
1319
- return Array.isArray(jsx) && jsx.length ? addScriptNodeForInvisibleComponents(jsx[0]) : null;
1400
+ return [ null, null ];
1320
1401
  }
1321
1402
 
1403
+ const _CONST_PROPS = Symbol("CONST");
1404
+
1405
+ const _VAR_PROPS = Symbol("VAR");
1406
+
1407
+ const _IMMUTABLE = Symbol("IMMUTABLE");
1408
+
1322
1409
  function isSlotProp(prop) {
1323
1410
  return !prop.startsWith("q:") && !prop.startsWith(":");
1324
1411
  }
@@ -1328,10 +1415,19 @@ function isParentSlotProp(prop) {
1328
1415
  }
1329
1416
 
1330
1417
  const _restProps = (props, omit, target = {}) => {
1331
- for (const key in props) {
1332
- omit.includes(key) || (target[key] = props[key]);
1418
+ let constPropsTarget = null;
1419
+ const constProps = props[_CONST_PROPS];
1420
+ if (constProps) {
1421
+ for (const key in constProps) {
1422
+ omit.includes(key) || (constPropsTarget ||= {}, constPropsTarget[key] = constProps[key]);
1423
+ }
1333
1424
  }
1334
- return target;
1425
+ const varPropsTarget = target;
1426
+ const varProps = props[_VAR_PROPS];
1427
+ for (const key in varProps) {
1428
+ omit.includes(key) || (varPropsTarget[key] = varProps[key]);
1429
+ }
1430
+ return createPropsProxy(varPropsTarget, constPropsTarget);
1335
1431
  };
1336
1432
 
1337
1433
  function escapeHTML(html) {
@@ -1360,14 +1456,6 @@ function escapeHTML(html) {
1360
1456
  return 0 === lastIdx ? html : escapedHTML + html.substring(lastIdx);
1361
1457
  }
1362
1458
 
1363
- function getFileLocationFromJsx(jsxDev) {
1364
- if (!jsxDev) {
1365
- return null;
1366
- }
1367
- const sanitizedFileName = jsxDev.fileName?.replace(/\\/g, "/");
1368
- return sanitizedFileName ? `${sanitizedFileName}:${jsxDev.lineNumber}:${jsxDev.columnNumber}` : null;
1369
- }
1370
-
1371
1459
  const vnode_diff = (container, jsxNode, vStartNode, scopedStyleIdPrefix) => {
1372
1460
  let journal = container.$journal$;
1373
1461
  const stack = [];
@@ -1405,7 +1493,7 @@ const vnode_diff = (container, jsxNode, vStartNode, scopedStyleIdPrefix) => {
1405
1493
  if (Array.isArray(jsxValue)) {
1406
1494
  descend(jsxValue, !1);
1407
1495
  } else if (isSignal(jsxValue)) {
1408
- vCurrent && clearVNodeEffectDependencies(container, vCurrent), expectVirtual(VirtualType.WrappedSignal, null),
1496
+ vCurrent && clearAllEffects(container, vCurrent), expectVirtual(VirtualType.WrappedSignal, null),
1409
1497
  descend(trackSignalAndAssignHost(jsxValue, vNewNode || vCurrent, EffectProperty.VNODE, container), !0);
1410
1498
  } else if (isPromise(jsxValue)) {
1411
1499
  expectVirtual(VirtualType.Awaited, null), asyncQueue.push(jsxValue, vNewNode || vCurrent);
@@ -1544,8 +1632,12 @@ const vnode_diff = (container, jsxNode, vStartNode, scopedStyleIdPrefix) => {
1544
1632
  if (isJsxPropertyAnEventName(key)) {
1545
1633
  const eventName = getEventNameFromJsxProp(key);
1546
1634
  const scope = getEventNameScopeFromJsxProp(key);
1547
- vnode_setProp(vNewNode, HANDLER_PREFIX + ":" + scope + ":" + eventName, value),
1548
- eventName && registerQwikLoaderEvent(eventName), needsQDispatchEventPatch = !0;
1635
+ if (eventName && (vnode_setProp(vNewNode, HANDLER_PREFIX + ":" + scope + ":" + eventName, value),
1636
+ registerQwikLoaderEvent(eventName)), scope) {
1637
+ const htmlEvent = convertEventNameFromJsxPropToHtmlAttr(key);
1638
+ htmlEvent && vnode_setAttr(journal, vNewNode, htmlEvent, "");
1639
+ }
1640
+ needsQDispatchEventPatch = !0;
1549
1641
  } else {
1550
1642
  if ("ref" === key) {
1551
1643
  if (isSignal(value)) {
@@ -1556,10 +1648,13 @@ const vnode_diff = (container, jsxNode, vStartNode, scopedStyleIdPrefix) => {
1556
1648
  value(element);
1557
1649
  continue;
1558
1650
  }
1651
+ if (null == value) {
1652
+ continue;
1653
+ }
1559
1654
  throw qError(QError.invalidRefValue, [ currentFile ]);
1560
1655
  }
1561
1656
  if (isSignal(value)) {
1562
- const signalData = new EffectPropData({
1657
+ const signalData = new SubscriptionData({
1563
1658
  $scopedStyleIdPrefix$: scopedStyleIdPrefix,
1564
1659
  $isConst$: !0
1565
1660
  });
@@ -1606,10 +1701,10 @@ const vnode_diff = (container, jsxNode, vStartNode, scopedStyleIdPrefix) => {
1606
1701
  const vNode = vNewNode || vCurrent;
1607
1702
  if (needsQDispatchEventPatch = function(vnode, srcAttrs, currentFile) {
1608
1703
  vnode_ensureElementInflated(vnode);
1609
- const dstAttrs = vnode;
1704
+ const dstAttrs = vnode_getProps(vnode);
1610
1705
  let srcIdx = 0;
1611
1706
  const srcLength = srcAttrs.length;
1612
- let dstIdx = ElementVNodeProps.PROPS_OFFSET;
1707
+ let dstIdx = 0;
1613
1708
  let dstLength = dstAttrs.length;
1614
1709
  let srcKey = srcIdx < srcLength ? srcAttrs[srcIdx++] : null;
1615
1710
  let dstKey = dstIdx < dstLength ? dstAttrs[dstIdx++] : null;
@@ -1626,10 +1721,13 @@ const vnode_diff = (container, jsxNode, vStartNode, scopedStyleIdPrefix) => {
1626
1721
  if ("function" == typeof value) {
1627
1722
  return void value(element);
1628
1723
  }
1724
+ if (null == value) {
1725
+ return;
1726
+ }
1629
1727
  throw qError(QError.invalidRefValue, [ currentFile ]);
1630
1728
  }
1631
1729
  if (isSignal(value)) {
1632
- const signalData = new EffectPropData({
1730
+ const signalData = new SubscriptionData({
1633
1731
  $scopedStyleIdPrefix$: scopedStyleIdPrefix,
1634
1732
  $isConst$: !1
1635
1733
  });
@@ -1641,12 +1739,12 @@ const vnode_diff = (container, jsxNode, vStartNode, scopedStyleIdPrefix) => {
1641
1739
  };
1642
1740
  const recordJsxEvent = (key, value) => {
1643
1741
  const eventName = getEventNameFromJsxProp(key);
1644
- if (eventName) {
1645
- const scope = getEventNameScopeFromJsxProp(key);
1646
- record(":" + scope + ":" + eventName, value);
1742
+ const scope = getEventNameScopeFromJsxProp(key);
1743
+ if (eventName && (record(":" + scope + ":" + eventName, value), registerQwikLoaderEvent(eventName)),
1744
+ scope) {
1745
+ const htmlEvent = convertEventNameFromJsxPropToHtmlAttr(key);
1746
+ htmlEvent && record(htmlEvent, "");
1647
1747
  }
1648
- const htmlEvent = convertEventNameFromJsxPropToHtmlAttr(key);
1649
- htmlEvent && record(htmlEvent, ""), eventName && registerQwikLoaderEvent(eventName);
1650
1748
  };
1651
1749
  for (;null !== srcKey || null !== dstKey; ) {
1652
1750
  if (dstKey?.startsWith(HANDLER_PREFIX) || dstKey?.startsWith("q:")) {
@@ -1678,7 +1776,7 @@ const vnode_diff = (container, jsxNode, vStartNode, scopedStyleIdPrefix) => {
1678
1776
  let returnValue = !1;
1679
1777
  return qrls.flat(2).forEach((qrl => {
1680
1778
  if (qrl) {
1681
- const value = qrl(event, element);
1779
+ const value = container.$scheduler$(ChoreType.RUN_QRL, vNode, qrl, [ event, element ]);
1682
1780
  returnValue = returnValue || !0 === value;
1683
1781
  }
1684
1782
  })), returnValue;
@@ -1727,8 +1825,8 @@ const vnode_diff = (container, jsxNode, vStartNode, scopedStyleIdPrefix) => {
1727
1825
  const vNodeComponentHash = getComponentHash(host, container.$getObjectById$);
1728
1826
  const lookupKey = jsxNode.key || componentHash;
1729
1827
  if (lookupKey === (getKey(host) || vNodeComponentHash) ? componentHash === vNodeComponentHash || (insertNewComponent(host, componentQRL, jsxProps),
1730
- vNewNode && (host && (vNewNode[VNodeProps.flags] = host[VNodeProps.flags]), host = vNewNode,
1731
- shouldRender = !0)) : (vNewNode = retrieveChildWithKey(null, lookupKey), vNewNode ? vnode_insertBefore(journal, vParent, vNewNode, vCurrent) : insertNewComponent(host, componentQRL, jsxProps),
1828
+ vNewNode && (host = vNewNode, shouldRender = !0)) : (vNewNode = retrieveChildWithKey(null, lookupKey),
1829
+ vNewNode ? vnode_insertBefore(journal, vParent, vNewNode, vCurrent) : insertNewComponent(host, componentQRL, jsxProps),
1732
1830
  host = vNewNode, shouldRender = !0), host) {
1733
1831
  const vNodeProps = vnode_getProp(host, "q:props", container.$getObjectById$);
1734
1832
  shouldRender = shouldRender || propsDiffer(jsxProps, vNodeProps), shouldRender && (host[VNodeProps.flags] &= ~VNodeFlags.Deleted,
@@ -1739,8 +1837,9 @@ const vnode_diff = (container, jsxNode, vStartNode, scopedStyleIdPrefix) => {
1739
1837
  const createProjectionJSXNode = slotName => new JSXNodeImpl(Projection, EMPTY_OBJ, null, [], 0, slotName);
1740
1838
  const projections = [];
1741
1839
  if (host) {
1742
- for (let i = vnode_getPropStartIndex(host); i < host.length; i += 2) {
1743
- const prop = host[i];
1840
+ const props = vnode_getProps(host);
1841
+ for (let i = 0; i < props.length; i += 2) {
1842
+ const prop = props[i];
1744
1843
  if (isSlotProp(prop)) {
1745
1844
  const slotName = prop;
1746
1845
  projections.push(slotName), projections.push(createProjectionJSXNode(slotName));
@@ -1781,7 +1880,7 @@ const vnode_diff = (container, jsxNode, vStartNode, scopedStyleIdPrefix) => {
1781
1880
  }
1782
1881
  }
1783
1882
  function insertNewComponent(host, componentQRL, jsxProps) {
1784
- host && clearVNodeEffectDependencies(container, host), vnode_insertBefore(journal, vParent, vNewNode = vnode_newVirtual(), vCurrent && getInsertBefore());
1883
+ host && clearAllEffects(container, host), vnode_insertBefore(journal, vParent, vNewNode = vnode_newVirtual(), vCurrent && getInsertBefore());
1785
1884
  const jsxNode = jsxValue;
1786
1885
  isDev && vnode_setProp(vNewNode, "q:type", VirtualType.Component), container.setHostProp(vNewNode, "q:renderFn", componentQRL),
1787
1886
  container.setHostProp(vNewNode, "q:props", jsxProps), container.setHostProp(vNewNode, "q:key", jsxNode.key);
@@ -1814,8 +1913,8 @@ function propsDiffer(src, dst) {
1814
1913
  if (!src || !dst) {
1815
1914
  return !0;
1816
1915
  }
1817
- let srcKeys = removePropsKeys(Object.keys(src), [ "children", "q:subs" ]);
1818
- let dstKeys = removePropsKeys(Object.keys(dst), [ "children", "q:subs" ]);
1916
+ let srcKeys = removePropsKeys(Object.keys(src), [ "children", "q:brefs" ]);
1917
+ let dstKeys = removePropsKeys(Object.keys(dst), [ "children", "q:brefs" ]);
1819
1918
  if (srcKeys.length !== dstKeys.length) {
1820
1919
  return !0;
1821
1920
  }
@@ -1847,22 +1946,21 @@ function cleanup(container, vNode) {
1847
1946
  for (;;) {
1848
1947
  const type = vCursor[VNodeProps.flags];
1849
1948
  if (type & VNodeFlags.ELEMENT_OR_VIRTUAL_MASK) {
1850
- if (clearVNodeEffectDependencies(container, vCursor), markVNodeAsDeleted(vCursor),
1851
- type & VNodeFlags.Virtual) {
1949
+ if (clearAllEffects(container, vCursor), markVNodeAsDeleted(vCursor), type & VNodeFlags.Virtual) {
1852
1950
  const seq = container.getHostProp(vCursor, "q:seq");
1853
1951
  if (seq) {
1854
1952
  for (let i = 0; i < seq.length; i++) {
1855
1953
  const obj = seq[i];
1856
1954
  if (isTask(obj)) {
1857
1955
  const task = obj;
1858
- clearSubscriberEffectDependencies(container, task), task.$flags$ & TaskFlags.VISIBLE_TASK ? container.$scheduler$(ChoreType.CLEANUP_VISIBLE, task) : cleanupTask(task);
1956
+ clearAllEffects(container, task), task.$flags$ & TaskFlags.VISIBLE_TASK ? container.$scheduler$(ChoreType.CLEANUP_VISIBLE, task) : cleanupTask(task);
1859
1957
  }
1860
1958
  }
1861
1959
  }
1862
1960
  }
1863
1961
  if (type & VNodeFlags.Virtual && null !== vnode_getProp(vCursor, "q:renderFn", null)) {
1864
- const attrs = vCursor;
1865
- for (let i = VirtualVNodeProps.PROPS_OFFSET; i < attrs.length; i += 2) {
1962
+ const attrs = vnode_getProps(vCursor);
1963
+ for (let i = 0; i < attrs.length; i += 2) {
1866
1964
  const key = attrs[i];
1867
1965
  if (!isParentSlotProp(key) && isSlotProp(key)) {
1868
1966
  const value = attrs[i + 1];
@@ -1941,39 +2039,210 @@ var SiblingsArray;
1941
2039
  SiblingsArray[SiblingsArray.NextVNode = 5] = "NextVNode";
1942
2040
  }(SiblingsArray || (SiblingsArray = {}));
1943
2041
 
1944
- const implicit$FirstArg = fn => function(first, ...rest) {
1945
- return fn.call(null, dollar(first), ...rest);
2042
+ const useResourceQrl = (qrl, opts) => {
2043
+ const {val, set, i, iCtx} = useSequentialScope();
2044
+ if (null != val) {
2045
+ return val;
2046
+ }
2047
+ assertQrl(qrl);
2048
+ const container = iCtx.$container$;
2049
+ const resource = createResourceReturn(container, opts);
2050
+ const task = new Task(TaskFlags.DIRTY | TaskFlags.RESOURCE, i, iCtx.$hostElement$, qrl, resource, null);
2051
+ return container.$scheduler$(ChoreType.TASK, task), set(resource), resource;
1946
2052
  };
1947
2053
 
1948
- const createSignal$1 = value => new Signal(null, value);
2054
+ const Resource = props => _jsxSorted(Fragment, null, null, getResourceValueAsPromise(props), 0, null);
1949
2055
 
1950
- const createComputedSignal = qrl => (throwIfQRLNotResolved(qrl), new ComputedSignal(null, qrl));
2056
+ function getResourceValueAsPromise(props) {
2057
+ const resource = props.value;
2058
+ if (isResourceReturn(resource) && resource.value) {
2059
+ if (!isServerPlatform()) {
2060
+ const state = resource._state;
2061
+ if ("pending" === state && props.onPending) {
2062
+ return Promise.resolve().then(useBindInvokeContext(props.onPending));
2063
+ }
2064
+ if ("rejected" === state && props.onRejected) {
2065
+ return Promise.resolve(resource._error).then(useBindInvokeContext(props.onRejected));
2066
+ }
2067
+ {
2068
+ const resolvedValue = untrack((() => resource._resolved));
2069
+ if (void 0 !== resolvedValue) {
2070
+ return Promise.resolve(resolvedValue).then(useBindInvokeContext(props.onResolved));
2071
+ }
2072
+ }
2073
+ }
2074
+ return resource.value.then(useBindInvokeContext(props.onResolved), useBindInvokeContext(props.onRejected));
2075
+ }
2076
+ return isPromise(resource) ? resource.then(useBindInvokeContext(props.onResolved), useBindInvokeContext(props.onRejected)) : isSignal(resource) ? Promise.resolve(resource.value).then(useBindInvokeContext(props.onResolved), useBindInvokeContext(props.onRejected)) : Promise.resolve(resource).then(useBindInvokeContext(props.onResolved), useBindInvokeContext(props.onRejected));
2077
+ }
1951
2078
 
1952
- const createSignal = createSignal$1;
2079
+ const _createResourceReturn = opts => ({
2080
+ __brand: "resource",
2081
+ value: void 0,
2082
+ loading: !isServerPlatform(),
2083
+ _resolved: void 0,
2084
+ _error: void 0,
2085
+ _state: "pending",
2086
+ _timeout: opts?.timeout ?? -1,
2087
+ _cache: 0
2088
+ });
1953
2089
 
1954
- const createComputedQrl = createComputedSignal;
2090
+ const createResourceReturn = (container, opts, initialPromise) => {
2091
+ const result = _createResourceReturn(opts);
2092
+ return result.value = initialPromise, createStore(container, result, StoreFlags.RECURSIVE);
2093
+ };
1955
2094
 
1956
- const createComputed$ = /*#__PURE__*/ implicit$FirstArg(createComputedQrl);
2095
+ const isResourceReturn = obj => isObject(obj) && "resource" === (getStoreTarget(obj) || obj).__brand;
1957
2096
 
1958
- var ChoreType;
2097
+ const runResource = (task, container, host) => {
2098
+ task.$flags$ &= ~TaskFlags.DIRTY, cleanupTask(task);
2099
+ const iCtx = newInvokeContext(container.$locale$, host, void 0, "qResource");
2100
+ iCtx.$container$ = container;
2101
+ const taskFn = task.$qrl$.getFn(iCtx, (() => clearAllEffects(container, task)));
2102
+ const resource = task.$state$;
2103
+ assertDefined(resource, 'useResource: when running a resource, "task.resource" must be a defined.', task);
2104
+ const cleanups = [];
2105
+ task.$destroy$ = noSerialize((() => {
2106
+ cleanups.forEach((fn => {
2107
+ try {
2108
+ fn();
2109
+ } catch (err) {
2110
+ container.handleError(err, host);
2111
+ }
2112
+ })), done = !0;
2113
+ }));
2114
+ const resourceTarget = unwrapStore(resource);
2115
+ const opts = {
2116
+ track: (obj, prop) => {
2117
+ const ctx = newInvokeContext();
2118
+ return ctx.$effectSubscriber$ = getSubscriber(task, EffectProperty.COMPONENT), ctx.$container$ = container,
2119
+ invoke(ctx, (() => isFunction(obj) ? obj() : prop ? obj[prop] : isSignal(obj) ? obj.value : obj));
2120
+ },
2121
+ cleanup(fn) {
2122
+ "function" == typeof fn && cleanups.push(fn);
2123
+ },
2124
+ cache(policy) {
2125
+ let milliseconds = 0;
2126
+ milliseconds = "immutable" === policy ? 1 / 0 : policy, resource._cache = milliseconds;
2127
+ },
2128
+ previous: resourceTarget._resolved
2129
+ };
2130
+ let resolve;
2131
+ let reject;
2132
+ let done = !1;
2133
+ const setState = (resolved, value) => !done && (done = !0, resolved ? (done = !0,
2134
+ resource.loading = !1, resource._state = "resolved", resource._resolved = value,
2135
+ resource._error = void 0, resolve(value)) : (done = !0, resource.loading = !1, resource._state = "rejected",
2136
+ resource._error = value, reject(value)), !0);
2137
+ cleanups.push((() => {
2138
+ if (!0 === untrack((() => resource.loading))) {
2139
+ const value = untrack((() => resource._resolved));
2140
+ setState(!0, value);
2141
+ }
2142
+ })), invoke(iCtx, (() => {
2143
+ resource._state = "pending", resource.loading = !isServerPlatform();
2144
+ (resource.value = new Promise(((r, re) => {
2145
+ resolve = r, reject = re;
2146
+ }))).catch(ignoreErrorToPreventNodeFromCrashing);
2147
+ }));
2148
+ const promise = safeCall((() => Promise.resolve(taskFn(opts))), (value => {
2149
+ setState(!0, value);
2150
+ }), (err => {
2151
+ if (isPromise(err)) {
2152
+ return err.then((() => runResource(task, container, host)));
2153
+ }
2154
+ setState(!1, err);
2155
+ }));
2156
+ const timeout = resourceTarget._timeout;
2157
+ return timeout > 0 ? Promise.race([ promise, delay(timeout).then((() => {
2158
+ setState(!1, new Error("timeout")) && cleanupTask(task);
2159
+ })) ]) : promise;
2160
+ };
1959
2161
 
1960
- !function(ChoreType) {
1961
- ChoreType[ChoreType.MACRO = 240] = "MACRO", ChoreType[ChoreType.MICRO = 15] = "MICRO",
1962
- ChoreType[ChoreType.QRL_RESOLVE = 1] = "QRL_RESOLVE", ChoreType[ChoreType.RESOURCE = 2] = "RESOURCE",
1963
- ChoreType[ChoreType.TASK = 3] = "TASK", ChoreType[ChoreType.NODE_DIFF = 4] = "NODE_DIFF",
1964
- ChoreType[ChoreType.NODE_PROP = 5] = "NODE_PROP", ChoreType[ChoreType.COMPONENT_SSR = 6] = "COMPONENT_SSR",
1965
- ChoreType[ChoreType.COMPONENT = 7] = "COMPONENT", ChoreType[ChoreType.RECOMPUTE_AND_SCHEDULE_EFFECTS = 8] = "RECOMPUTE_AND_SCHEDULE_EFFECTS",
1966
- ChoreType[ChoreType.JOURNAL_FLUSH = 16] = "JOURNAL_FLUSH", ChoreType[ChoreType.VISIBLE = 32] = "VISIBLE",
1967
- ChoreType[ChoreType.CLEANUP_VISIBLE = 48] = "CLEANUP_VISIBLE", ChoreType[ChoreType.WAIT_FOR_ALL = 255] = "WAIT_FOR_ALL";
1968
- }(ChoreType || (ChoreType = {}));
2162
+ const ignoreErrorToPreventNodeFromCrashing = () => {};
2163
+
2164
+ const aVNodePath = [];
2165
+
2166
+ const bVNodePath = [];
2167
+
2168
+ const vnode_documentPosition = (a, b, rootVNode) => {
2169
+ if (a === b) {
2170
+ return 0;
2171
+ }
2172
+ let aDepth = -1;
2173
+ let bDepth = -1;
2174
+ for (;a; ) {
2175
+ a = (aVNodePath[++aDepth] = a)[VNodeProps.parent] || rootVNode && vnode_getProp(a, ":", (id => vnode_locate(rootVNode, id)));
2176
+ }
2177
+ for (;b; ) {
2178
+ b = (bVNodePath[++bDepth] = b)[VNodeProps.parent] || rootVNode && vnode_getProp(b, ":", (id => vnode_locate(rootVNode, id)));
2179
+ }
2180
+ for (;aDepth >= 0 && bDepth >= 0; ) {
2181
+ if ((a = aVNodePath[aDepth]) !== (b = bVNodePath[bDepth])) {
2182
+ let cursor = b;
2183
+ do {
2184
+ if (cursor = vnode_getNextSibling(cursor), cursor === a) {
2185
+ return 1;
2186
+ }
2187
+ } while (cursor);
2188
+ cursor = b;
2189
+ do {
2190
+ if (cursor = vnode_getPreviousSibling(cursor), cursor === a) {
2191
+ return -1;
2192
+ }
2193
+ } while (cursor);
2194
+ return rootVNode && vnode_getProp(b, ":", (id => vnode_locate(rootVNode, id))) ? -1 : 1;
2195
+ }
2196
+ aDepth--, bDepth--;
2197
+ }
2198
+ return aDepth < bDepth ? -1 : 1;
2199
+ };
2200
+
2201
+ const aSsrNodePath = [];
2202
+
2203
+ const bSsrNodePath = [];
2204
+
2205
+ const ssrNodeDocumentPosition = (a, b) => {
2206
+ if (a === b) {
2207
+ return 0;
2208
+ }
2209
+ let aDepth = -1;
2210
+ let bDepth = -1;
2211
+ for (;a; ) {
2212
+ a = (aSsrNodePath[++aDepth] = a).currentComponentNode;
2213
+ }
2214
+ for (;b; ) {
2215
+ b = (bSsrNodePath[++bDepth] = b).currentComponentNode;
2216
+ }
2217
+ for (;aDepth >= 0 && bDepth >= 0; ) {
2218
+ if ((a = aSsrNodePath[aDepth]) !== (b = bSsrNodePath[bDepth])) {
2219
+ return 1;
2220
+ }
2221
+ aDepth--, bDepth--;
2222
+ }
2223
+ return aDepth < bDepth ? -1 : 1;
2224
+ };
2225
+
2226
+ const DEBUG$1 = !1;
2227
+
2228
+ const getPromise = chore => chore.$promise$ ||= new Promise((resolve => {
2229
+ chore.$resolve$ = resolve;
2230
+ }));
1969
2231
 
1970
2232
  const createScheduler = (container, scheduleDrain, journalFlush) => {
1971
2233
  const choreQueue = [];
2234
+ const qrlRuns = [];
1972
2235
  let currentChore = null;
1973
- let journalFlushScheduled = !1;
2236
+ let drainScheduled = !1;
1974
2237
  return function schedule(type, hostOrTask = null, targetOrQrl = null, payload = null) {
1975
- const runLater = type !== ChoreType.WAIT_FOR_ALL && type !== ChoreType.COMPONENT_SSR;
1976
- const isTask = type === ChoreType.TASK || type === ChoreType.VISIBLE || type === ChoreType.RESOURCE || type === ChoreType.CLEANUP_VISIBLE;
2238
+ const isServer = !isDomContainer(container);
2239
+ const isComponentSsr = isServer && type === ChoreType.COMPONENT;
2240
+ const runLater = type !== ChoreType.WAIT_FOR_ALL && !isComponentSsr && type !== ChoreType.RUN_QRL;
2241
+ const isTask = type === ChoreType.TASK || type === ChoreType.VISIBLE || type === ChoreType.CLEANUP_VISIBLE;
2242
+ const isClientOnly = type === ChoreType.JOURNAL_FLUSH || type === ChoreType.NODE_DIFF || type === ChoreType.NODE_PROP;
2243
+ if (isServer && isClientOnly) {
2244
+ return;
2245
+ }
1977
2246
  isTask && (hostOrTask.$flags$ |= TaskFlags.DIRTY);
1978
2247
  let chore = {
1979
2248
  $type$: type,
@@ -1986,303 +2255,241 @@ const createScheduler = (container, scheduleDrain, journalFlush) => {
1986
2255
  $returnValue$: null,
1987
2256
  $executed$: !1
1988
2257
  };
1989
- chore.$promise$ = new Promise((resolve => chore.$resolve$ = resolve)), chore = sortedInsert(choreQueue, chore, container.rootVNode || null),
1990
- !journalFlushScheduled && runLater && (journalFlushScheduled = !0, schedule(ChoreType.JOURNAL_FLUSH),
1991
- scheduleDrain());
1992
- return runLater ? chore.$promise$ : drainUpTo(chore, container.rootVNode || null);
2258
+ chore = function(sortedArray, value, rootVNode) {
2259
+ const idx = function(sortedArray, value, rootVNode) {
2260
+ let bottom = 0;
2261
+ let top = sortedArray.length;
2262
+ for (;bottom < top; ) {
2263
+ const middle = bottom + (top - bottom >> 1);
2264
+ const comp = choreComparator(value, sortedArray[middle], rootVNode);
2265
+ if (comp < 0) {
2266
+ top = middle;
2267
+ } else {
2268
+ if (!(comp > 0)) {
2269
+ return middle;
2270
+ }
2271
+ bottom = middle + 1;
2272
+ }
2273
+ }
2274
+ return ~bottom;
2275
+ }(sortedArray, value, rootVNode);
2276
+ if (idx < 0) {
2277
+ return sortedArray.splice(~idx, 0, value), value;
2278
+ }
2279
+ const existing = sortedArray[idx];
2280
+ existing.$type$ === ChoreType.NODE_DIFF && (existing.$payload$ = value.$payload$);
2281
+ existing.$executed$ && (existing.$executed$ = !1);
2282
+ return existing;
2283
+ }(choreQueue, chore, container.rootVNode || null), !drainScheduled && runLater && (drainScheduled = !0,
2284
+ schedule(ChoreType.JOURNAL_FLUSH), scheduleDrain()?.catch?.((() => {})));
2285
+ return runLater ? getPromise(chore) : drainUpTo(chore, isServer);
1993
2286
  };
1994
- function drainUpTo(runUptoChore, rootVNode) {
1995
- if (runUptoChore.$executed$) {
1996
- return runUptoChore.$returnValue$;
1997
- }
1998
- if (currentChore) {
1999
- return runUptoChore.$promise$;
2000
- }
2287
+ function drainUpTo(runUptoChore, isServer) {
2288
+ let maxRetries = 5e3;
2001
2289
  for (;choreQueue.length; ) {
2002
- const nextChore = choreQueue.shift();
2003
- const order = choreComparator(nextChore, runUptoChore, rootVNode, !1);
2004
- if (null === order) {
2005
- continue;
2290
+ if (maxRetries-- < 0) {
2291
+ throw new Error("drainUpTo: max retries reached");
2006
2292
  }
2007
- if (order > 0) {
2008
- break;
2009
- }
2010
- if (vNodeAlreadyDeleted(nextChore) && nextChore.$type$ !== ChoreType.CLEANUP_VISIBLE) {
2011
- continue;
2293
+ if (currentChore) {
2294
+ return getPromise(currentChore).then((() => drainUpTo(runUptoChore, isServer))).catch((e => {
2295
+ container.handleError(e, currentChore?.$host$);
2296
+ }));
2012
2297
  }
2013
- const returnValue = executeChore(nextChore);
2014
- if (isPromise(returnValue)) {
2015
- return returnValue.then((() => drainUpTo(runUptoChore, rootVNode)));
2298
+ const nextChore = choreQueue[0];
2299
+ if (nextChore.$executed$) {
2300
+ if (choreQueue.shift(), nextChore === runUptoChore) {
2301
+ break;
2302
+ }
2303
+ } else {
2304
+ vNodeAlreadyDeleted(nextChore) && nextChore.$type$ !== ChoreType.CLEANUP_VISIBLE ? choreQueue.shift() : executeChore(nextChore, isServer);
2016
2305
  }
2017
2306
  }
2018
2307
  return runUptoChore.$returnValue$;
2019
2308
  }
2020
- function executeChore(chore) {
2309
+ function executeChore(chore, isServer) {
2021
2310
  const host = chore.$host$;
2022
2311
  assertEqual(currentChore, null, "Chore already running."), currentChore = chore;
2023
2312
  let returnValue = null;
2024
- switch (chore.$type$) {
2025
- case ChoreType.JOURNAL_FLUSH:
2026
- returnValue = journalFlush(), journalFlushScheduled = !1;
2027
- break;
2028
-
2029
- case ChoreType.COMPONENT:
2030
- case ChoreType.COMPONENT_SSR:
2031
- returnValue = safeCall((() => executeComponent(container, host, host, chore.$target$, chore.$payload$)), (jsx => {
2032
- if (chore.$type$ === ChoreType.COMPONENT) {
2033
- const styleScopedId = container.getHostProp(host, "q:sstyle");
2034
- return vnode_diff(container, jsx, host, addComponentStylePrefix(styleScopedId));
2035
- }
2036
- return jsx;
2037
- }), (err => container.handleError(err, host)));
2038
- break;
2039
-
2040
- case ChoreType.RESOURCE:
2041
- const result = runResource(chore.$payload$, container, host);
2042
- returnValue = isDomContainer(container) ? null : result;
2043
- break;
2044
-
2045
- case ChoreType.TASK:
2046
- case ChoreType.VISIBLE:
2047
- returnValue = runTask(chore.$payload$, container, host);
2048
- break;
2049
-
2050
- case ChoreType.CLEANUP_VISIBLE:
2051
- cleanupTask(chore.$payload$);
2052
- break;
2053
-
2054
- case ChoreType.NODE_DIFF:
2055
- const parentVirtualNode = chore.$target$;
2056
- let jsx = chore.$payload$;
2057
- isSignal(jsx) && (jsx = jsx.value), returnValue = vnode_diff(container, jsx, parentVirtualNode, null);
2058
- break;
2313
+ try {
2314
+ switch (chore.$type$) {
2315
+ case ChoreType.WAIT_FOR_ALL:
2316
+ isServer && (drainScheduled = !1);
2317
+ break;
2059
2318
 
2060
- case ChoreType.NODE_PROP:
2061
- const virtualNode = chore.$host$;
2062
- const payload = chore.$payload$;
2063
- let value = payload.$value$;
2064
- isSignal(value) && (value = value.value);
2065
- const isConst = payload.$isConst$;
2066
- const journal = container.$journal$;
2067
- const property = chore.$idx$;
2068
- const serializedValue = serializeAttribute(property, value, payload.$scopedStyleIdPrefix$);
2069
- if (isConst) {
2070
- journal.push(VNodeJournalOpCode.SetAttribute, virtualNode[ElementVNodeProps.element], property, serializedValue);
2071
- } else {
2072
- vnode_setAttr(journal, virtualNode, property, serializedValue);
2073
- }
2074
- break;
2319
+ case ChoreType.JOURNAL_FLUSH:
2320
+ returnValue = journalFlush(), drainScheduled = !1;
2321
+ break;
2075
2322
 
2076
- case ChoreType.QRL_RESOLVE:
2077
- {
2078
- const target = chore.$target$;
2079
- returnValue = target.resolved ? null : target.resolve();
2323
+ case ChoreType.COMPONENT:
2324
+ returnValue = safeCall((() => executeComponent(container, host, host, chore.$target$, chore.$payload$)), (jsx => {
2325
+ if (isServer) {
2326
+ return jsx;
2327
+ }
2328
+ {
2329
+ const styleScopedId = container.getHostProp(host, "q:sstyle");
2330
+ return retryOnPromise((() => vnode_diff(container, jsx, host, addComponentStylePrefix(styleScopedId))));
2331
+ }
2332
+ }), (err => container.handleError(err, host)));
2080
2333
  break;
2081
- }
2082
2334
 
2083
- case ChoreType.RECOMPUTE_AND_SCHEDULE_EFFECTS:
2084
- {
2085
- const target = chore.$target$;
2086
- const forceRunEffects = target.$forceRunEffects$;
2087
- if (target.$forceRunEffects$ = !1, !target.$effects$?.length) {
2088
- break;
2335
+ case ChoreType.RUN_QRL:
2336
+ {
2337
+ const fn = chore.$target$.getFn();
2338
+ const result = retryOnPromise((() => fn(...chore.$payload$)));
2339
+ if (isPromise(result)) {
2340
+ const handled = result.finally((() => {
2341
+ qrlRuns.splice(qrlRuns.indexOf(handled), 1);
2342
+ })).catch((error => {
2343
+ container.handleError(error, chore.$host$);
2344
+ }));
2345
+ return qrlRuns.push(handled), chore.$returnValue$ = handled, chore.$resolve$?.(handled),
2346
+ currentChore = null, void (chore.$executed$ = !0);
2347
+ }
2348
+ returnValue = null;
2089
2349
  }
2090
- returnValue = retryOnPromise((() => {
2091
- (target.$computeIfNeeded$() || forceRunEffects) && triggerEffects(container, target, target.$effects$);
2092
- }));
2093
2350
  break;
2094
- }
2095
- }
2096
- return maybeThenPassError(returnValue, (value => (currentChore && (currentChore.$executed$ = !0,
2097
- currentChore.$resolve$?.(value)), currentChore = null, chore.$returnValue$ = value)));
2098
- }
2099
- };
2100
-
2101
- const toNumber = value => "number" == typeof value ? value : -1;
2102
2351
 
2103
- const choreUpdate = (existing, newChore) => {
2104
- existing.$type$ === ChoreType.NODE_DIFF && (existing.$payload$ = newChore.$payload$);
2105
- };
2106
-
2107
- function vNodeAlreadyDeleted(chore) {
2108
- return !!(chore.$host$ && vnode_isVNode(chore.$host$) && chore.$host$[VNodeProps.flags] & VNodeFlags.Deleted);
2109
- }
2110
-
2111
- function choreComparator(a, b, rootVNode, shouldThrowOnHostMismatch) {
2112
- const macroTypeDiff = (a.$type$ & ChoreType.MACRO) - (b.$type$ & ChoreType.MACRO);
2113
- if (0 !== macroTypeDiff) {
2114
- return macroTypeDiff;
2115
- }
2116
- if (a.$type$ !== ChoreType.JOURNAL_FLUSH) {
2117
- const aHost = a.$host$;
2118
- const bHost = b.$host$;
2119
- if (aHost !== bHost && null !== aHost && null !== bHost) {
2120
- if (!vnode_isVNode(aHost) || !vnode_isVNode(bHost)) {
2121
- const errorMessage = `SERVER: during HTML streaming, re-running tasks on a different host is not allowed.\n You are attempting to change a state that has already been streamed to the client.\n This can lead to inconsistencies between Server-Side Rendering (SSR) and Client-Side Rendering (CSR).\n Problematic Node: ${aHost.toString()}`;
2122
- if (shouldThrowOnHostMismatch) {
2123
- throw qError(QError.serverHostMismatch, [ errorMessage ]);
2124
- }
2125
- return logWarn(errorMessage), null;
2126
- }
2127
- {
2128
- const hostDiff = vnode_documentPosition(aHost, bHost, rootVNode);
2129
- if (0 !== hostDiff) {
2130
- return hostDiff;
2352
+ case ChoreType.TASK:
2353
+ case ChoreType.VISIBLE:
2354
+ {
2355
+ const payload = chore.$payload$;
2356
+ if (payload.$flags$ & TaskFlags.RESOURCE) {
2357
+ const result = runResource(payload, container, host);
2358
+ returnValue = isServer ? result : null;
2359
+ } else {
2360
+ returnValue = runTask(payload, container, host);
2361
+ }
2131
2362
  }
2132
- }
2133
- }
2134
- const microTypeDiff = (a.$type$ & ChoreType.MICRO) - (b.$type$ & ChoreType.MICRO);
2135
- if (0 !== microTypeDiff) {
2136
- return microTypeDiff;
2137
- }
2138
- const idxDiff = toNumber(a.$idx$) - toNumber(b.$idx$);
2139
- if (0 !== idxDiff) {
2140
- return idxDiff;
2141
- }
2142
- if (a.$target$ !== b.$target$ && (a.$type$ === ChoreType.QRL_RESOLVE && b.$type$ === ChoreType.QRL_RESOLVE || a.$type$ === ChoreType.NODE_PROP && b.$type$ === ChoreType.NODE_PROP || a.$type$ === ChoreType.RECOMPUTE_AND_SCHEDULE_EFFECTS && b.$type$ === ChoreType.RECOMPUTE_AND_SCHEDULE_EFFECTS)) {
2143
- return 1;
2144
- }
2145
- }
2146
- return 0;
2147
- }
2148
-
2149
- function sortedFindIndex(sortedArray, value, rootVNode) {
2150
- let bottom = 0;
2151
- let top = sortedArray.length;
2152
- for (;bottom < top; ) {
2153
- const middle = bottom + (top - bottom >> 1);
2154
- const comp = choreComparator(value, sortedArray[middle], rootVNode, !0);
2155
- if (comp < 0) {
2156
- top = middle;
2157
- } else {
2158
- if (!(comp > 0)) {
2159
- return middle;
2160
- }
2161
- bottom = middle + 1;
2162
- }
2163
- }
2164
- return ~bottom;
2165
- }
2166
-
2167
- function sortedInsert(sortedArray, value, rootVNode) {
2168
- const idx = sortedFindIndex(sortedArray, value, rootVNode);
2169
- if (idx < 0) {
2170
- return sortedArray.splice(~idx, 0, value), value;
2171
- }
2172
- const existing = sortedArray[idx];
2173
- return choreUpdate(existing, value), existing;
2174
- }
2175
-
2176
- const useLexicalScope = () => {
2177
- const context = getInvokeContext();
2178
- let qrl = context.$qrl$;
2179
- if (qrl) {
2180
- assertQrl(qrl), assertDefined(qrl.$captureRef$, "invoke: qrl $captureRef$ must be defined inside useLexicalScope()", qrl);
2181
- } else {
2182
- const el = context.$element$;
2183
- assertDefined(el, "invoke: element must be defined inside useLexicalScope()", context);
2184
- const containerElement = _getQContainerElement(el);
2185
- assertDefined(containerElement, "invoke: cant find parent q:container of", el);
2186
- qrl = getDomContainer(containerElement).parseQRL(decodeURIComponent(String(context.$url$)));
2187
- }
2188
- return qrl.$captureRef$;
2189
- };
2190
-
2191
- var TaskFlags;
2363
+ break;
2192
2364
 
2193
- !function(TaskFlags) {
2194
- TaskFlags[TaskFlags.VISIBLE_TASK = 1] = "VISIBLE_TASK", TaskFlags[TaskFlags.TASK = 2] = "TASK",
2195
- TaskFlags[TaskFlags.RESOURCE = 4] = "RESOURCE", TaskFlags[TaskFlags.DIRTY = 8] = "DIRTY";
2196
- }(TaskFlags || (TaskFlags = {}));
2365
+ case ChoreType.CLEANUP_VISIBLE:
2366
+ cleanupTask(chore.$payload$);
2367
+ break;
2197
2368
 
2198
- const useTaskQrl = (qrl, opts) => {
2199
- const {val, set, iCtx, i} = useSequentialScope();
2200
- if (val) {
2201
- return;
2202
- }
2203
- assertQrl(qrl), set(1);
2204
- const host = iCtx.$hostElement$;
2205
- const task = new Task(TaskFlags.DIRTY | TaskFlags.TASK, i, iCtx.$hostElement$, qrl, void 0, null);
2206
- set(task);
2207
- const result = runTask(task, iCtx.$container$, host);
2208
- if (isPromise(result)) {
2209
- throw result;
2210
- }
2211
- qrl.$resolveLazy$(iCtx.$element$), isServerPlatform() && useRunTask(task, opts?.eagerness);
2212
- };
2369
+ case ChoreType.NODE_DIFF:
2370
+ {
2371
+ const parentVirtualNode = chore.$target$;
2372
+ let jsx = chore.$payload$;
2373
+ isSignal(jsx) && (jsx = jsx.value), returnValue = retryOnPromise((() => vnode_diff(container, jsx, parentVirtualNode, null)));
2374
+ }
2375
+ break;
2213
2376
 
2214
- const runTask = (task, container, host) => {
2215
- task.$flags$ &= ~TaskFlags.DIRTY, cleanupTask(task);
2216
- const iCtx = newInvokeContext(container.$locale$, host, void 0, "qTask");
2217
- iCtx.$container$ = container;
2218
- const taskFn = task.$qrl$.getFn(iCtx, (() => clearSubscriberEffectDependencies(container, task)));
2219
- const handleError = reason => container.handleError(reason, host);
2220
- let cleanupFns = null;
2221
- const cleanup = fn => {
2222
- "function" == typeof fn && (cleanupFns || (cleanupFns = [], task.$destroy$ = noSerialize((() => {
2223
- task.$destroy$ = null, cleanupFns.forEach((fn => {
2224
- try {
2225
- fn();
2226
- } catch (err) {
2227
- handleError(err);
2377
+ case ChoreType.NODE_PROP:
2378
+ {
2379
+ const virtualNode = chore.$host$;
2380
+ const payload = chore.$payload$;
2381
+ let value = payload.$value$;
2382
+ isSignal(value) && (value = value.value);
2383
+ const isConst = payload.$isConst$;
2384
+ const journal = container.$journal$;
2385
+ const property = chore.$idx$;
2386
+ const serializedValue = serializeAttribute(property, value, payload.$scopedStyleIdPrefix$);
2387
+ if (isConst) {
2388
+ journal.push(VNodeJournalOpCode.SetAttribute, virtualNode[ElementVNodeProps.element], property, serializedValue);
2389
+ } else {
2390
+ vnode_setAttr(journal, virtualNode, property, serializedValue);
2391
+ }
2228
2392
  }
2229
- }));
2230
- }))), cleanupFns.push(fn));
2231
- };
2232
- const taskApi = {
2233
- track: (obj, prop) => {
2234
- const ctx = newInvokeContext();
2235
- return ctx.$effectSubscriber$ = [ task, EffectProperty.COMPONENT ], ctx.$container$ = container,
2236
- invoke(ctx, (() => isFunction(obj) ? obj() : prop ? obj[prop] : isSignal(obj) ? obj.value : obj));
2237
- },
2238
- cleanup
2239
- };
2240
- return safeCall((() => taskFn(taskApi)), cleanup, (err => isPromise(err) ? err.then((() => runTask(task, container, host))) : handleError(err)));
2241
- };
2393
+ break;
2242
2394
 
2243
- const cleanupTask = task => {
2244
- const destroy = task.$destroy$;
2245
- if (destroy) {
2246
- task.$destroy$ = null;
2247
- try {
2248
- destroy();
2249
- } catch (err) {
2250
- logError(err);
2395
+ case ChoreType.QRL_RESOLVE:
2396
+ {
2397
+ const target = chore.$target$;
2398
+ returnValue = target.resolved ? null : target.resolve();
2399
+ }
2400
+ break;
2401
+
2402
+ case ChoreType.RECOMPUTE_AND_SCHEDULE_EFFECTS:
2403
+ {
2404
+ const target = chore.$target$;
2405
+ const forceRunEffects = target.$forceRunEffects$;
2406
+ if (target.$forceRunEffects$ = !1, !target.$effects$?.size) {
2407
+ break;
2408
+ }
2409
+ returnValue = retryOnPromise((() => {
2410
+ (target.$computeIfNeeded$() || forceRunEffects) && triggerEffects(container, target, target.$effects$);
2411
+ }));
2412
+ }
2413
+ }
2414
+ } catch (e) {
2415
+ returnValue = Promise.reject(e);
2251
2416
  }
2417
+ const after = (value, error) => {
2418
+ currentChore = null, chore.$executed$ = !0, error ? container.handleError(error, host) : (chore.$returnValue$ = value,
2419
+ chore.$resolve$?.(value));
2420
+ };
2421
+ isPromise(returnValue) ? (chore.$promise$ = returnValue.then(after, (error => after(void 0, error))),
2422
+ chore.$resolve$?.(chore.$promise$), chore.$resolve$ = void 0) : after(returnValue);
2423
+ }
2424
+ function choreComparator(a, b, rootVNode) {
2425
+ const macroTypeDiff = (a.$type$ & ChoreType.MACRO) - (b.$type$ & ChoreType.MACRO);
2426
+ if (0 !== macroTypeDiff) {
2427
+ return macroTypeDiff;
2428
+ }
2429
+ const aHost = a.$host$;
2430
+ const bHost = b.$host$;
2431
+ if (aHost !== bHost && null !== aHost && null !== bHost) {
2432
+ if (vnode_isVNode(aHost) && vnode_isVNode(bHost)) {
2433
+ const hostDiff = vnode_documentPosition(aHost, bHost, rootVNode);
2434
+ if (0 !== hostDiff) {
2435
+ return hostDiff;
2436
+ }
2437
+ } else {
2438
+ assertFalse(vnode_isVNode(aHost), "expected aHost to be SSRNode but it is a VNode"),
2439
+ assertFalse(vnode_isVNode(bHost), "expected bHost to be SSRNode but it is a VNode");
2440
+ const errorMessage = `SERVER: during HTML streaming, re-running tasks on a different host is not allowed.\n You are attempting to change a state that has already been streamed to the client.\n This can lead to inconsistencies between Server-Side Rendering (SSR) and Client-Side Rendering (CSR).\n Problematic Node: ${aHost.toString()}`;
2441
+ logWarn(errorMessage);
2442
+ const hostDiff = ssrNodeDocumentPosition(aHost, bHost);
2443
+ if (0 !== hostDiff) {
2444
+ return hostDiff;
2445
+ }
2446
+ }
2447
+ }
2448
+ const microTypeDiff = (a.$type$ & ChoreType.MICRO) - (b.$type$ & ChoreType.MICRO);
2449
+ if (0 !== microTypeDiff) {
2450
+ return microTypeDiff;
2451
+ }
2452
+ const idxDiff = toNumber(a.$idx$) - toNumber(b.$idx$);
2453
+ return 0 !== idxDiff ? idxDiff : a.$target$ !== b.$target$ || a.$payload$ !== b.$payload$ || b === currentChore ? 1 : 0;
2252
2454
  }
2253
2455
  };
2254
2456
 
2255
- const useRunTask = (task, eagerness) => {
2256
- "visible" === eagerness || "intersection-observer" === eagerness ? useOn("qvisible", getTaskHandlerQrl(task)) : "load" === eagerness || "document-ready" === eagerness ? useOnDocument("qinit", getTaskHandlerQrl(task)) : "idle" !== eagerness && "document-idle" !== eagerness || useOnDocument("qidle", getTaskHandlerQrl(task));
2257
- };
2258
-
2259
- const getTaskHandlerQrl = task => {
2260
- const taskQrl = task.$qrl$;
2261
- const taskHandler = createQRL(taskQrl.$chunk$, "_hW", _hW, null, null, [ task ], taskQrl.$symbol$);
2262
- return taskQrl.dev && (taskHandler.dev = taskQrl.dev), taskHandler;
2263
- };
2457
+ const toNumber = value => "number" == typeof value ? value : -1;
2264
2458
 
2265
- class Task extends Subscriber {
2266
- $flags$;
2267
- $index$;
2268
- $el$;
2269
- $qrl$;
2270
- $state$;
2271
- $destroy$;
2272
- constructor($flags$, $index$, $el$, $qrl$, $state$, $destroy$) {
2273
- super(), this.$flags$ = $flags$, this.$index$ = $index$, this.$el$ = $el$, this.$qrl$ = $qrl$,
2274
- this.$state$ = $state$, this.$destroy$ = $destroy$;
2275
- }
2459
+ function vNodeAlreadyDeleted(chore) {
2460
+ return !!(chore.$host$ && vnode_isVNode(chore.$host$) && chore.$host$[VNodeProps.flags] & VNodeFlags.Deleted);
2276
2461
  }
2277
2462
 
2278
- const isTask = value => value instanceof Task;
2463
+ function debugChoreTypeToString(type) {
2464
+ return {
2465
+ [ChoreType.QRL_RESOLVE]: "QRL_RESOLVE",
2466
+ [ChoreType.RUN_QRL]: "RUN_QRL",
2467
+ [ChoreType.TASK]: "TASK",
2468
+ [ChoreType.NODE_DIFF]: "NODE_DIFF",
2469
+ [ChoreType.NODE_PROP]: "NODE_PROP",
2470
+ [ChoreType.COMPONENT]: "COMPONENT",
2471
+ [ChoreType.RECOMPUTE_AND_SCHEDULE_EFFECTS]: "RECOMPUTE_SIGNAL",
2472
+ [ChoreType.JOURNAL_FLUSH]: "JOURNAL_FLUSH",
2473
+ [ChoreType.VISIBLE]: "VISIBLE",
2474
+ [ChoreType.CLEANUP_VISIBLE]: "CLEANUP_VISIBLE",
2475
+ [ChoreType.WAIT_FOR_ALL]: "WAIT_FOR_ALL"
2476
+ }[type] || "UNKNOWN: " + type;
2477
+ }
2279
2478
 
2280
- const _hW = () => {
2281
- const [task] = useLexicalScope();
2282
- getDomContainer(task.$el$).$scheduler$(task.$flags$ & TaskFlags.VISIBLE_TASK ? ChoreType.VISIBLE : ChoreType.TASK, task);
2283
- };
2479
+ function debugChoreToString(chore) {
2480
+ const type = debugChoreTypeToString(chore.$type$);
2481
+ const host = String(chore.$host$).replaceAll(/\n.*/gim, "");
2482
+ const qrlTarget = chore.$target$?.$symbol$;
2483
+ return `Chore(${type} ${chore.$type$ === ChoreType.QRL_RESOLVE || chore.$type$ === ChoreType.RUN_QRL ? qrlTarget : host} ${chore.$idx$})`;
2484
+ }
2284
2485
 
2285
- const NEEDS_COMPUTATION = Symbol("invalid");
2486
+ function debugTrace(action, arg, currentChore, queue) {
2487
+ const lines = [ "===========================\nScheduler: " + action ];
2488
+ arg && !("$type$" in arg) && lines.push(" arg: " + String(arg).replaceAll(/\n.*/gim, "")),
2489
+ queue && queue.forEach((chore => {
2490
+ lines.push(` ${chore === arg ? ">>>" : " "} > ` + (chore === currentChore ? "[running] " : "") + debugChoreToString(chore));
2491
+ })), console.log(lines.join("\n") + "\n");
2492
+ }
2286
2493
 
2287
2494
  const DEBUG = !1;
2288
2495
 
@@ -2296,21 +2503,21 @@ const throwIfQRLNotResolved = qrl => {
2296
2503
 
2297
2504
  const isSignal = value => value instanceof Signal;
2298
2505
 
2299
- class EffectPropData {
2506
+ class SubscriptionData {
2300
2507
  data;
2301
2508
  constructor(data) {
2302
2509
  this.data = data;
2303
2510
  }
2304
2511
  }
2305
2512
 
2306
- var EffectSubscriptionsProp;
2513
+ var EffectSubscriptionProp;
2307
2514
 
2308
2515
  var EffectProperty;
2309
2516
 
2310
- !function(EffectSubscriptionsProp) {
2311
- EffectSubscriptionsProp[EffectSubscriptionsProp.EFFECT = 0] = "EFFECT", EffectSubscriptionsProp[EffectSubscriptionsProp.PROPERTY = 1] = "PROPERTY",
2312
- EffectSubscriptionsProp[EffectSubscriptionsProp.FIRST_BACK_REF_OR_DATA = 2] = "FIRST_BACK_REF_OR_DATA";
2313
- }(EffectSubscriptionsProp || (EffectSubscriptionsProp = {})), function(EffectProperty) {
2517
+ !function(EffectSubscriptionProp) {
2518
+ EffectSubscriptionProp[EffectSubscriptionProp.CONSUMER = 0] = "CONSUMER", EffectSubscriptionProp[EffectSubscriptionProp.PROPERTY = 1] = "PROPERTY",
2519
+ EffectSubscriptionProp[EffectSubscriptionProp.BACK_REF = 2] = "BACK_REF", EffectSubscriptionProp[EffectSubscriptionProp.DATA = 3] = "DATA";
2520
+ }(EffectSubscriptionProp || (EffectSubscriptionProp = {})), function(EffectProperty) {
2314
2521
  EffectProperty.COMPONENT = ":", EffectProperty.VNODE = ".";
2315
2522
  }(EffectProperty || (EffectProperty = {}));
2316
2523
 
@@ -2340,9 +2547,9 @@ class Signal {
2340
2547
  }
2341
2548
  const effectSubscriber = ctx.$effectSubscriber$;
2342
2549
  if (effectSubscriber) {
2343
- const effects = this.$effects$ ||= [];
2344
- ensureContainsEffect(effects, effectSubscriber), ensureContains(effectSubscriber, this),
2345
- isSubscriber(this) && ensureEffectContainsSubscriber(effectSubscriber[EffectSubscriptionsProp.EFFECT], this, this.$container$);
2550
+ const effects = this.$effects$ ||= new Set;
2551
+ ensureContainsSubscription(effects, effectSubscriber), ensureContainsBackRef(effectSubscriber, this),
2552
+ addQrlToSerializationCtx(effectSubscriber, this.$container$);
2346
2553
  }
2347
2554
  }
2348
2555
  return this.untrackedValue;
@@ -2354,7 +2561,7 @@ class Signal {
2354
2561
  qDev;
2355
2562
  }
2356
2563
  toString() {
2357
- return `[${this.constructor.name}${this.$invalid$ ? " INVALID" : ""} ${String(this.$untrackedValue$)}]` + (this.$effects$?.map((e => "\n -> " + pad(qwikDebugToString(e[0]), " "))).join("\n") || "");
2564
+ return `[${this.constructor.name}${this.$invalid$ ? " INVALID" : ""} ${String(this.$untrackedValue$)}]` + (Array.from(this.$effects$ || []).map((e => "\n -> " + pad(qwikDebugToString(e[0]), " "))).join("\n") || "");
2358
2565
  }
2359
2566
  toJSON() {
2360
2567
  return {
@@ -2363,85 +2570,61 @@ class Signal {
2363
2570
  }
2364
2571
  }
2365
2572
 
2366
- const ensureContains = (array, value) => {
2367
- -1 === array.indexOf(value) && array.push(value);
2368
- };
2369
-
2370
- const ensureContainsEffect = (array, effectSubscriptions) => {
2371
- for (let i = 0; i < array.length; i++) {
2372
- const existingEffect = array[i];
2373
- if (existingEffect[0] === effectSubscriptions[0] && existingEffect[1] === effectSubscriptions[1]) {
2374
- return;
2375
- }
2376
- }
2377
- array.push(effectSubscriptions);
2573
+ const ensureContainsSubscription = (array, effectSubscription) => {
2574
+ array.add(effectSubscription);
2378
2575
  };
2379
2576
 
2380
- const ensureEffectContainsSubscriber = (effect, subscriber, container) => {
2381
- if (isSubscriber(effect)) {
2382
- if (effect.$effectDependencies$ ||= [], subscriberExistInSubscribers(effect.$effectDependencies$, subscriber)) {
2383
- return;
2384
- }
2385
- effect.$effectDependencies$.push(subscriber);
2386
- } else if (vnode_isVNode(effect) && !vnode_isTextVNode(effect)) {
2387
- let subscribers = vnode_getProp(effect, "q:subs", container ? container.$getObjectById$ : null);
2388
- if (subscribers ||= [], subscriberExistInSubscribers(subscribers, subscriber)) {
2389
- return;
2390
- }
2391
- subscribers.push(subscriber), vnode_setProp(effect, "q:subs", subscribers);
2392
- } else if (isSSRNode(effect)) {
2393
- let subscribers = effect.getProp("q:subs");
2394
- if (subscribers ||= [], subscriberExistInSubscribers(subscribers, subscriber)) {
2395
- return;
2396
- }
2397
- subscribers.push(subscriber), effect.setProp("q:subs", subscribers);
2398
- }
2577
+ const ensureContainsBackRef = (array, value) => {
2578
+ array[EffectSubscriptionProp.BACK_REF] ||= new Set, array[EffectSubscriptionProp.BACK_REF].add(value);
2399
2579
  };
2400
2580
 
2401
- const isSSRNode = effect => "setProp" in effect && "getProp" in effect && "removeProp" in effect && "id" in effect;
2402
-
2403
- const subscriberExistInSubscribers = (subscribers, subscriber) => {
2404
- for (let i = 0; i < subscribers.length; i++) {
2405
- if (subscribers[i] === subscriber) {
2406
- return !0;
2407
- }
2581
+ const addQrlToSerializationCtx = (effectSubscriber, container) => {
2582
+ if (container && !isDomContainer(container)) {
2583
+ const effect = effectSubscriber[EffectSubscriptionProp.CONSUMER];
2584
+ const property = effectSubscriber[EffectSubscriptionProp.PROPERTY];
2585
+ let qrl = null;
2586
+ isTask(effect) ? qrl = effect.$qrl$ : effect instanceof ComputedSignal ? qrl = effect.$computeQrl$ : property === EffectProperty.COMPONENT && (qrl = container.getHostProp(effect, "q:renderFn")),
2587
+ qrl && container.serializationCtx.$eventQrls$.add(qrl);
2408
2588
  }
2409
- return !1;
2410
2589
  };
2411
2590
 
2412
2591
  const triggerEffects = (container, signal, effects) => {
2592
+ const isBrowser = isDomContainer(container);
2413
2593
  if (effects) {
2414
- const scheduleEffect = effectSubscriptions => {
2415
- const effect = effectSubscriptions[EffectSubscriptionsProp.EFFECT];
2416
- const property = effectSubscriptions[EffectSubscriptionsProp.PROPERTY];
2417
- if (assertDefined(container, "Container must be defined."), isTask(effect)) {
2418
- effect.$flags$ |= TaskFlags.DIRTY;
2594
+ const scheduleEffect = effectSubscription => {
2595
+ const consumer = effectSubscription[EffectSubscriptionProp.CONSUMER];
2596
+ const property = effectSubscription[EffectSubscriptionProp.PROPERTY];
2597
+ if (assertDefined(container, "Container must be defined."), isTask(consumer)) {
2598
+ consumer.$flags$ |= TaskFlags.DIRTY;
2419
2599
  let choreType = ChoreType.TASK;
2420
- effect.$flags$ & TaskFlags.VISIBLE_TASK ? choreType = ChoreType.VISIBLE : effect.$flags$ & TaskFlags.RESOURCE && (choreType = ChoreType.RESOURCE),
2421
- container.$scheduler$(choreType, effect);
2422
- } else if (effect instanceof Signal) {
2423
- effect instanceof ComputedSignal && (effect.$computeQrl$.resolved || container.$scheduler$(ChoreType.QRL_RESOLVE, null, effect.$computeQrl$)),
2424
- effect.$invalidate$();
2600
+ consumer.$flags$ & TaskFlags.VISIBLE_TASK && (choreType = ChoreType.VISIBLE), container.$scheduler$(choreType, consumer);
2601
+ } else if (consumer instanceof Signal) {
2602
+ consumer instanceof ComputedSignal && (consumer.$computeQrl$.resolved || container.$scheduler$(ChoreType.QRL_RESOLVE, null, consumer.$computeQrl$)),
2603
+ consumer.$invalidate$();
2425
2604
  } else if (property === EffectProperty.COMPONENT) {
2426
- const host = effect;
2605
+ const host = consumer;
2427
2606
  const qrl = container.getHostProp(host, "q:renderFn");
2428
2607
  assertDefined(qrl, "Component must have QRL");
2429
2608
  const props = container.getHostProp(host, "q:props");
2430
2609
  container.$scheduler$(ChoreType.COMPONENT, host, qrl, props);
2431
- } else if (property === EffectProperty.VNODE) {
2432
- container.$scheduler$(ChoreType.NODE_DIFF, effect, effect, signal);
2433
- } else {
2434
- const effectData = effectSubscriptions[EffectSubscriptionsProp.FIRST_BACK_REF_OR_DATA];
2435
- if (effectData instanceof EffectPropData) {
2436
- const payload = {
2437
- ...effectData.data,
2438
- $value$: signal
2439
- };
2440
- container.$scheduler$(ChoreType.NODE_PROP, effect, property, payload);
2610
+ } else if (isBrowser) {
2611
+ if (property === EffectProperty.VNODE) {
2612
+ container.$scheduler$(ChoreType.NODE_DIFF, consumer, consumer, signal);
2613
+ } else {
2614
+ const effectData = effectSubscription[EffectSubscriptionProp.DATA];
2615
+ if (effectData instanceof SubscriptionData) {
2616
+ const payload = {
2617
+ ...effectData.data,
2618
+ $value$: signal
2619
+ };
2620
+ container.$scheduler$(ChoreType.NODE_PROP, consumer, property, payload);
2621
+ }
2441
2622
  }
2442
2623
  }
2443
2624
  };
2444
- effects.forEach(scheduleEffect);
2625
+ for (const effect of effects) {
2626
+ scheduleEffect(effect);
2627
+ }
2445
2628
  }
2446
2629
  };
2447
2630
 
@@ -2471,7 +2654,7 @@ class ComputedSignal extends Signal {
2471
2654
  throwIfQRLNotResolved(computeQrl);
2472
2655
  const ctx = tryGetInvokeContext();
2473
2656
  const previousEffectSubscription = ctx?.$effectSubscriber$;
2474
- ctx && (ctx.$effectSubscriber$ = [ this, EffectProperty.VNODE ]);
2657
+ ctx && (ctx.$effectSubscriber$ = getSubscriber(this, EffectProperty.VNODE));
2475
2658
  try {
2476
2659
  const untrackedValue = computeQrl.getFn(ctx)();
2477
2660
  if (isPromise(untrackedValue)) {
@@ -2497,9 +2680,9 @@ class WrappedSignal extends Signal {
2497
2680
  $func$;
2498
2681
  $funcStr$;
2499
2682
  $invalid$=!0;
2500
- $effectDependencies$=null;
2501
2683
  $hostElement$=null;
2502
2684
  $forceRunEffects$=!1;
2685
+ [_EFFECT_BACK_REF]=null;
2503
2686
  constructor(container, fn, args, fnStr) {
2504
2687
  super(container, NEEDS_COMPUTATION), this.$args$ = args, this.$func$ = fn, this.$funcStr$ = fnStr;
2505
2688
  }
@@ -2542,7 +2725,7 @@ const applyQwikComponentBody = (ssr, jsx, component) => {
2542
2725
  srcProps && srcProps.children && delete srcProps.children;
2543
2726
  const scheduler = ssr.$scheduler$;
2544
2727
  return host.setProp("q:renderFn", componentQrl), host.setProp("q:props", srcProps),
2545
- null !== jsx.key && host.setProp("q:key", jsx.key), scheduler(ChoreType.COMPONENT_SSR, host, componentQrl, srcProps);
2728
+ null !== jsx.key && host.setProp("q:key", jsx.key), scheduler(ChoreType.COMPONENT, host, componentQrl, srcProps);
2546
2729
  };
2547
2730
 
2548
2731
  class ParentComponentData {
@@ -2553,18 +2736,10 @@ class ParentComponentData {
2553
2736
  }
2554
2737
  }
2555
2738
 
2556
- function _walkJSX(ssr, value, options) {
2739
+ async function _walkJSX(ssr, value, options) {
2557
2740
  const stack = [ value ];
2558
- let resolveDrain;
2559
- let rejectDrain;
2560
- const drained = options.allowPromises && new Promise(((res, rej) => {
2561
- resolveDrain = res, rejectDrain = rej;
2562
- }));
2563
2741
  const enqueue = value => stack.push(value);
2564
- const resolveValue = value => {
2565
- stack.push(value), drain();
2566
- };
2567
- const drain = () => {
2742
+ await (async () => {
2568
2743
  for (;stack.length; ) {
2569
2744
  const value = stack.pop();
2570
2745
  if (value instanceof ParentComponentData) {
@@ -2576,23 +2751,13 @@ function _walkJSX(ssr, value, options) {
2576
2751
  });
2577
2752
  } else {
2578
2753
  if (value === Promise) {
2579
- if (!options.allowPromises) {
2580
- throw qError(QError.promisesNotExpected);
2581
- }
2582
- return void stack.pop().then(resolveValue, rejectDrain);
2583
- }
2584
- const waitOn = value.apply(ssr);
2585
- if (waitOn) {
2586
- if (!options.allowPromises) {
2587
- throw qError(QError.promisesNotExpected);
2588
- }
2589
- return void waitOn.then(drain, rejectDrain);
2754
+ stack.push(await stack.pop());
2755
+ continue;
2590
2756
  }
2757
+ await value.apply(ssr);
2591
2758
  }
2592
2759
  }
2593
- 0 === stack.length && options.allowPromises && resolveDrain();
2594
- };
2595
- return drain(), drained;
2760
+ })();
2596
2761
  }
2597
2762
 
2598
2763
  function processJSXNode(ssr, enqueue, value, options) {
@@ -2620,7 +2785,6 @@ function processJSXNode(ssr, enqueue, value, options) {
2620
2785
  enqueue((async () => {
2621
2786
  for await (const chunk of value) {
2622
2787
  await _walkJSX(ssr, chunk, {
2623
- allowPromises: !0,
2624
2788
  currentStyleScoped: options.styleScoped,
2625
2789
  parentComponentFrame: options.parentComponentFrame
2626
2790
  }), ssr.commentNode("qkssr-f");
@@ -2671,7 +2835,6 @@ function processJSXNode(ssr, enqueue, value, options) {
2671
2835
  value = isFunction(generator) ? generator({
2672
2836
  async write(chunk) {
2673
2837
  await _walkJSX(ssr, chunk, {
2674
- allowPromises: !0,
2675
2838
  currentStyleScoped: options.styleScoped,
2676
2839
  parentComponentFrame: options.parentComponentFrame
2677
2840
  }), ssr.commentNode("qkssr-f");
@@ -2759,18 +2922,20 @@ function setEvent(serializationCtx, key, rawValue) {
2759
2922
  const appendToValue = valueToAppend => {
2760
2923
  value = (null == value ? "" : value + "\n") + valueToAppend;
2761
2924
  };
2925
+ const getQrlString = qrl => (qrl.$symbol$.startsWith("_") || !qrl.$captureRef$ && !qrl.$capture$ || (qrl = createQRL(null, "_run", queueQRL, null, null, [ qrl ])),
2926
+ qrlToString(serializationCtx, qrl));
2762
2927
  if (Array.isArray(qrls)) {
2763
2928
  for (let i = 0; i <= qrls.length; i++) {
2764
2929
  const qrl = qrls[i];
2765
- if (isQrl(qrl)) {
2766
- appendToValue(qrlToString(serializationCtx, qrl)), addQwikEventToSerializationContext(serializationCtx, key, qrl);
2930
+ if (isQrl$1(qrl)) {
2931
+ appendToValue(getQrlString(qrl)), addQwikEventToSerializationContext(serializationCtx, key, qrl);
2767
2932
  } else if (null != qrl) {
2768
2933
  const nestedValue = setEvent(serializationCtx, key, qrl);
2769
2934
  nestedValue && appendToValue(nestedValue);
2770
2935
  }
2771
2936
  }
2772
2937
  } else {
2773
- isQrl(qrls) && (value = qrlToString(serializationCtx, qrls), addQwikEventToSerializationContext(serializationCtx, key, qrls));
2938
+ isQrl$1(qrls) && (value = getQrlString(qrls), addQwikEventToSerializationContext(serializationCtx, key, qrls));
2774
2939
  }
2775
2940
  return value;
2776
2941
  }
@@ -2805,7 +2970,7 @@ function appendClassIfScopedStyleExists(jsx, styleScoped) {
2805
2970
  jsx.constProps.class = "");
2806
2971
  }
2807
2972
 
2808
- const version = "2.0.0-alpha.5-dev+cb53bbd";
2973
+ const version = "2.0.0-alpha.7-dev+a26598a";
2809
2974
 
2810
2975
  class _SharedContainer {
2811
2976
  $version$;
@@ -2830,12 +2995,6 @@ class _SharedContainer {
2830
2995
  }
2831
2996
  }
2832
2997
 
2833
- const _CONST_PROPS = Symbol("CONST");
2834
-
2835
- const _VAR_PROPS = Symbol("VAR");
2836
-
2837
- const _IMMUTABLE = Symbol("IMMUTABLE");
2838
-
2839
2998
  const getValueProp = p0 => p0.value;
2840
2999
 
2841
3000
  const getProp = (p0, p1) => p0[p1];
@@ -3052,7 +3211,7 @@ function qwikDebugToString(value) {
3052
3211
  if (isTask(value)) {
3053
3212
  return `Task(${qwikDebugToString(value.$qrl$)})`;
3054
3213
  }
3055
- if (isQrl$1(value)) {
3214
+ if (isQrl(value)) {
3056
3215
  return `Qrl(${value.$symbol$})`;
3057
3216
  }
3058
3217
  if ("object" == typeof value || "function" == typeof value) {
@@ -3158,14 +3317,21 @@ const VNodeDataChar = {
3158
3317
  CONTEXT_CHAR: "]",
3159
3318
  SEQ_IDX: 94,
3160
3319
  SEQ_IDX_CHAR: "^",
3161
- SUBS: 96,
3162
- SUBS_CHAR: "`",
3320
+ BACK_REFS: 96,
3321
+ BACK_REFS_CHAR: "`",
3163
3322
  SEPARATOR: 124,
3164
3323
  SEPARATOR_CHAR: "|",
3165
3324
  SLOT: 126,
3166
3325
  SLOT_CHAR: "~"
3167
3326
  };
3168
3327
 
3328
+ const mergeMaps = (map1, map2) => {
3329
+ for (const [k, v] of map2) {
3330
+ map1.set(k, v);
3331
+ }
3332
+ return map1;
3333
+ };
3334
+
3169
3335
  var VNodeJournalOpCode;
3170
3336
 
3171
3337
  !function(VNodeJournalOpCode) {
@@ -3271,6 +3437,7 @@ const vnode_ensureElementInflated = vnode => {
3271
3437
  elementVNode[VNodeProps.flags] ^= VNodeFlags.Inflated;
3272
3438
  const element = elementVNode[ElementVNodeProps.element];
3273
3439
  const attributes = element.attributes;
3440
+ const props = vnode_getProps(elementVNode);
3274
3441
  for (let idx = 0; idx < attributes.length; idx++) {
3275
3442
  const attr = attributes[idx];
3276
3443
  const key = attr.name;
@@ -3278,9 +3445,9 @@ const vnode_ensureElementInflated = vnode => {
3278
3445
  break;
3279
3446
  }
3280
3447
  if (key.startsWith("q:container")) {
3281
- attr.value === QContainerValue.HTML ? mapArray_set(elementVNode, dangerouslySetInnerHTML, element.innerHTML, ElementVNodeProps.PROPS_OFFSET) : attr.value === QContainerValue.TEXT && "value" in element && mapArray_set(elementVNode, "value", element.value, ElementVNodeProps.PROPS_OFFSET);
3448
+ attr.value === QContainerValue.HTML ? mapArray_set(props, dangerouslySetInnerHTML, element.innerHTML, 0) : attr.value === QContainerValue.TEXT && "value" in element && mapArray_set(props, "value", element.value, 0);
3282
3449
  } else if (!key.startsWith("on:")) {
3283
- mapArray_set(elementVNode, key, attr.value, ElementVNodeProps.PROPS_OFFSET);
3450
+ mapArray_set(props, key, attr.value, 0);
3284
3451
  }
3285
3452
  }
3286
3453
  }
@@ -3550,33 +3717,9 @@ const vnode_applyJournal = journal => {
3550
3717
  journal.length = 0;
3551
3718
  };
3552
3719
 
3553
- const mapApp_findIndx = (elementVNode, key, start) => {
3554
- assertTrue(start % 2 == 0, "Expecting even number.");
3555
- let bottom = start >> 1;
3556
- let top = elementVNode.length - 2 >> 1;
3557
- for (;bottom <= top; ) {
3558
- const mid = bottom + (top - bottom >> 1);
3559
- const midKey = elementVNode[mid << 1];
3560
- if (midKey === key) {
3561
- return mid << 1;
3562
- }
3563
- midKey < key ? bottom = mid + 1 : top = mid - 1;
3564
- }
3565
- return ~(bottom << 1);
3566
- };
3567
-
3568
- const mapArray_set = (elementVNode, key, value, start) => {
3569
- const indx = mapApp_findIndx(elementVNode, key, start);
3570
- indx >= 0 ? null == value ? elementVNode.splice(indx, 2) : elementVNode[indx + 1] = value : null != value && elementVNode.splice(~indx, 0, key, value);
3571
- };
3572
-
3573
- const mapArray_get = (elementVNode, key, start) => {
3574
- const indx = mapApp_findIndx(elementVNode, key, start);
3575
- return indx >= 0 ? elementVNode[indx + 1] : null;
3576
- };
3577
-
3578
3720
  const vnode_insertBefore = (journal, parent, newChild, insertBefore) => {
3579
- ensureElementOrVirtualVNode(parent), vnode_isElementVNode(parent) && ensureMaterialized(parent);
3721
+ ensureElementOrVirtualVNode(parent), vnode_isElementVNode(parent) && ensureMaterialized(parent),
3722
+ newChild === insertBefore && (insertBefore = null);
3580
3723
  let adjustedInsertBefore = null;
3581
3724
  null == insertBefore ? vnode_isVirtualVNode(parent) && (adjustedInsertBefore = vnode_getDomSibling(parent, !0, !1)) : adjustedInsertBefore = vnode_isVirtualVNode(insertBefore) ? vnode_getDomSibling(insertBefore, !0, !0) : insertBefore,
3582
3725
  adjustedInsertBefore && vnode_ensureInflatedIfText(journal, adjustedInsertBefore);
@@ -3635,9 +3778,12 @@ const vnode_truncate = (journal, vParent, vDelete) => {
3635
3778
  const vnode_getElementName = vnode => {
3636
3779
  const elementVNode = ensureElementVNode(vnode);
3637
3780
  let elementName = elementVNode[ElementVNodeProps.elementName];
3638
- return void 0 === elementName && (elementName = elementVNode[ElementVNodeProps.elementName] = elementVNode[ElementVNodeProps.element].nodeName.toLowerCase(),
3639
- elementVNode[VNodeProps.flags] |= vnode_getElementNamespaceFlags(elementName)),
3640
- elementName;
3781
+ if (void 0 === elementName) {
3782
+ const element = elementVNode[ElementVNodeProps.element];
3783
+ const nodeName = isDev ? fastNodeName(element).toLowerCase() : fastNodeName(element);
3784
+ elementName = elementVNode[ElementVNodeProps.elementName] = nodeName, elementVNode[VNodeProps.flags] |= vnode_getElementNamespaceFlags(element);
3785
+ }
3786
+ return elementName;
3641
3787
  };
3642
3788
 
3643
3789
  const vnode_getText = vnode => {
@@ -3765,6 +3911,16 @@ const fastFirstChild = node => {
3765
3911
  return node;
3766
3912
  };
3767
3913
 
3914
+ let _fastNamespaceURI = null;
3915
+
3916
+ const fastNamespaceURI = element => (_fastNamespaceURI || (_fastNamespaceURI = fastGetter(element, "namespaceURI")),
3917
+ _fastNamespaceURI.call(element));
3918
+
3919
+ let _fastNodeName = null;
3920
+
3921
+ const fastNodeName = element => (_fastNodeName || (_fastNodeName = fastGetter(element, "nodeName")),
3922
+ _fastNodeName.call(element));
3923
+
3768
3924
  const fastGetter = (prototype, name) => {
3769
3925
  let getter;
3770
3926
  for (;prototype && !(getter = Object.getOwnPropertyDescriptor(prototype, name)?.get); ) {
@@ -3804,13 +3960,25 @@ const materializeFromDOM = (vParent, firstChild, vData) => {
3804
3960
  const id = consumeValue();
3805
3961
  container.$setRawState$(parseInt(id), vParent), isDev && vnode_setAttr(null, vParent, "q:id", id);
3806
3962
  } else {
3807
- peek() === VNodeDataChar.SUBS ? vnode_setProp(vParent, "q:subs", consumeValue()) : consumeValue();
3963
+ peek() === VNodeDataChar.BACK_REFS ? (container || (container = getDomContainer(vParent[ElementVNodeProps.element])),
3964
+ setEffectBackRefFromVNodeData(vParent, consumeValue(), container)) : consumeValue();
3808
3965
  }
3809
3966
  }));
3810
3967
  }
3811
3968
  return vFirstChild;
3812
3969
  };
3813
3970
 
3971
+ function setEffectBackRefFromVNodeData(vParent, value, container) {
3972
+ const deserializedSubMap = container.$getObjectById$(value);
3973
+ if (vParent[_EFFECT_BACK_REF]) {
3974
+ mergeMaps(vParent[_EFFECT_BACK_REF], deserializedSubMap);
3975
+ } else {
3976
+ Object.defineProperty(vParent, _EFFECT_BACK_REF, {
3977
+ value: deserializedSubMap
3978
+ });
3979
+ }
3980
+ }
3981
+
3814
3982
  const processVNodeData$1 = (vData, callback) => {
3815
3983
  let nextToConsumeIdx = 0;
3816
3984
  let ch = 0;
@@ -3838,8 +4006,9 @@ const vnode_getAttrKeys = vnode => {
3838
4006
  if (vnode[VNodeProps.flags] & VNodeFlags.ELEMENT_OR_VIRTUAL_MASK) {
3839
4007
  vnode_ensureElementInflated(vnode);
3840
4008
  const keys = [];
3841
- for (let i = vnode_getPropStartIndex(vnode); i < vnode.length; i += 2) {
3842
- const key = vnode[i];
4009
+ const props = vnode_getProps(vnode);
4010
+ for (let i = 0; i < props.length; i += 2) {
4011
+ const key = props[i];
3843
4012
  key.startsWith(":") || keys.push(key);
3844
4013
  }
3845
4014
  return keys;
@@ -3851,29 +4020,37 @@ const vnode_setAttr = (journal, vnode, key, value) => {
3851
4020
  const type = vnode[VNodeProps.flags];
3852
4021
  if (type & VNodeFlags.ELEMENT_OR_VIRTUAL_MASK) {
3853
4022
  vnode_ensureElementInflated(vnode);
3854
- const idx = mapApp_findIndx(vnode, key, vnode_getPropStartIndex(vnode));
4023
+ const props = vnode_getProps(vnode);
4024
+ const idx = mapApp_findIndx(props, key, 0);
3855
4025
  if (idx >= 0) {
3856
- if (vnode[idx + 1] != value && type & VNodeFlags.Element) {
4026
+ if (props[idx + 1] != value && type & VNodeFlags.Element) {
3857
4027
  journal && journal.push(VNodeJournalOpCode.SetAttribute, vnode[ElementVNodeProps.element], key, value);
3858
4028
  }
3859
- null == value ? vnode.splice(idx, 2) : vnode[idx + 1] = value;
3860
- } else if (null != value && (vnode.splice(~idx, 0, key, value), type & VNodeFlags.Element)) {
4029
+ null == value ? props.splice(idx, 2) : props[idx + 1] = value;
4030
+ } else if (null != value && (props.splice(~idx, 0, key, value), type & VNodeFlags.Element)) {
3861
4031
  journal && journal.push(VNodeJournalOpCode.SetAttribute, vnode[ElementVNodeProps.element], key, value);
3862
4032
  }
3863
4033
  }
3864
4034
  };
3865
4035
 
3866
- const vnode_getAttr = (vnode, key) => vnode[VNodeProps.flags] & VNodeFlags.ELEMENT_OR_VIRTUAL_MASK ? (vnode_ensureElementInflated(vnode),
3867
- mapArray_get(vnode, key, vnode_getPropStartIndex(vnode))) : null;
4036
+ const vnode_getAttr = (vnode, key) => {
4037
+ if (vnode[VNodeProps.flags] & VNodeFlags.ELEMENT_OR_VIRTUAL_MASK) {
4038
+ vnode_ensureElementInflated(vnode);
4039
+ const props = vnode_getProps(vnode);
4040
+ return mapArray_get(props, key, 0);
4041
+ }
4042
+ return null;
4043
+ };
3868
4044
 
3869
4045
  const vnode_getProp = (vnode, key, getObject) => {
3870
4046
  const type = vnode[VNodeProps.flags];
3871
4047
  if (type & VNodeFlags.ELEMENT_OR_VIRTUAL_MASK) {
3872
4048
  type & VNodeFlags.Element && vnode_ensureElementInflated(vnode);
3873
- const idx = mapApp_findIndx(vnode, key, vnode_getPropStartIndex(vnode));
4049
+ const props = vnode_getProps(vnode);
4050
+ const idx = mapApp_findIndx(props, key, 0);
3874
4051
  if (idx >= 0) {
3875
- let value = vnode[idx + 1];
3876
- return "string" == typeof value && getObject && (vnode[idx + 1] = value = getObject(value)),
4052
+ let value = props[idx + 1];
4053
+ return "string" == typeof value && getObject && (props[idx + 1] = value = getObject(value)),
3877
4054
  value;
3878
4055
  }
3879
4056
  }
@@ -3882,8 +4059,9 @@ const vnode_getProp = (vnode, key, getObject) => {
3882
4059
 
3883
4060
  const vnode_setProp = (vnode, key, value) => {
3884
4061
  ensureElementOrVirtualVNode(vnode);
3885
- const idx = mapApp_findIndx(vnode, key, vnode_getPropStartIndex(vnode));
3886
- idx >= 0 ? vnode[idx + 1] = value : null != value && vnode.splice(~idx, 0, key, value);
4062
+ const props = vnode_getProps(vnode);
4063
+ const idx = mapApp_findIndx(props, key, 0);
4064
+ idx >= 0 ? props[idx + 1] = value : null != value && props.splice(~idx, 0, key, value);
3887
4065
  };
3888
4066
 
3889
4067
  const vnode_getPropStartIndex = vnode => {
@@ -3897,6 +4075,8 @@ const vnode_getPropStartIndex = vnode => {
3897
4075
  throw qError(QError.invalidVNodeType, [ type ]);
3898
4076
  };
3899
4077
 
4078
+ const vnode_getProps = vnode => vnode[vnode_getPropStartIndex(vnode)];
4079
+
3900
4080
  const vnode_getParent = vnode => vnode[VNodeProps.parent] || null;
3901
4081
 
3902
4082
  const vnode_getNode = vnode => null === vnode || vnode_isVirtualVNode(vnode) ? null : vnode_isElementVNode(vnode) ? vnode[ElementVNodeProps.element] : (assertTrue(vnode_isTextVNode(vnode), "Expecting Text Node."),
@@ -4017,8 +4197,8 @@ function materializeFromVNodeData(vParent, vData, element, child) {
4017
4197
  vnode_setAttr(null, vParent, "q:seq", consumeValue());
4018
4198
  } else if (peek() === VNodeDataChar.SEQ_IDX) {
4019
4199
  vnode_setAttr(null, vParent, "q:seqIdx", consumeValue());
4020
- } else if (peek() === VNodeDataChar.SUBS) {
4021
- vnode_setProp(vParent, "q:subs", consumeValue());
4200
+ } else if (peek() === VNodeDataChar.BACK_REFS) {
4201
+ container || (container = getDomContainer(element)), setEffectBackRefFromVNodeData(vParent, consumeValue(), container);
4022
4202
  } else if (peek() === VNodeDataChar.CONTEXT) {
4023
4203
  vnode_setAttr(null, vParent, "q:ctx", consumeValue());
4024
4204
  } else if (peek() === VNodeDataChar.OPEN) {
@@ -4064,43 +4244,6 @@ const vnode_getType = vnode => {
4064
4244
 
4065
4245
  const isElement = node => node && "object" == typeof node && 1 === fastNodeType(node);
4066
4246
 
4067
- const aPath = [];
4068
-
4069
- const bPath = [];
4070
-
4071
- const vnode_documentPosition = (a, b, rootVNode) => {
4072
- if (a === b) {
4073
- return 0;
4074
- }
4075
- let aDepth = -1;
4076
- let bDepth = -1;
4077
- for (;a; ) {
4078
- a = (aPath[++aDepth] = a)[VNodeProps.parent] || rootVNode && vnode_getProp(a, ":", (id => vnode_locate(rootVNode, id)));
4079
- }
4080
- for (;b; ) {
4081
- b = (bPath[++bDepth] = b)[VNodeProps.parent] || rootVNode && vnode_getProp(b, ":", (id => vnode_locate(rootVNode, id)));
4082
- }
4083
- for (;aDepth >= 0 && bDepth >= 0; ) {
4084
- if ((a = aPath[aDepth]) !== (b = bPath[bDepth])) {
4085
- let cursor = b;
4086
- do {
4087
- if (cursor = vnode_getNextSibling(cursor), cursor === a) {
4088
- return 1;
4089
- }
4090
- } while (cursor);
4091
- cursor = b;
4092
- do {
4093
- if (cursor = vnode_getPreviousSibling(cursor), cursor === a) {
4094
- return -1;
4095
- }
4096
- } while (cursor);
4097
- return rootVNode && vnode_getProp(b, ":", (id => vnode_locate(rootVNode, id))) ? -1 : 1;
4098
- }
4099
- aDepth--, bDepth--;
4100
- }
4101
- return aDepth < bDepth ? -1 : 1;
4102
- };
4103
-
4104
4247
  const vnode_getProjectionParentComponent = (vHost, rootVNode) => {
4105
4248
  let projectionDepth = 1;
4106
4249
  for (;projectionDepth--; ) {
@@ -4116,19 +4259,16 @@ const vnode_getProjectionParentComponent = (vHost, rootVNode) => {
4116
4259
 
4117
4260
  const VNodeArray = class VNode extends Array {
4118
4261
  static createElement(flags, parent, previousSibling, nextSibling, firstChild, lastChild, element, elementName) {
4119
- const vnode = new VNode(flags, parent, previousSibling, nextSibling);
4120
- return vnode.push(firstChild, lastChild, element, elementName), vnode;
4262
+ return new VNode(flags, parent, previousSibling, nextSibling, firstChild, lastChild, element, elementName, []);
4121
4263
  }
4122
4264
  static createText(flags, parent, previousSibling, nextSibling, textNode, text) {
4123
- const vnode = new VNode(flags, parent, previousSibling, nextSibling);
4124
- return vnode.push(textNode, text), vnode;
4265
+ return new VNode(flags, parent, previousSibling, nextSibling, textNode, text);
4125
4266
  }
4126
4267
  static createVirtual(flags, parent, previousSibling, nextSibling, firstChild, lastChild) {
4127
- const vnode = new VNode(flags, parent, previousSibling, nextSibling);
4128
- return vnode.push(firstChild, lastChild), vnode;
4268
+ return new VNode(flags, parent, previousSibling, nextSibling, firstChild, lastChild, []);
4129
4269
  }
4130
- constructor(flags, parent, previousSibling, nextSibling) {
4131
- super(), this.push(flags, parent, previousSibling, nextSibling), isDev && (this.toString = vnode_toString);
4270
+ constructor(flags, parent, previousSibling, nextSibling, ...rest) {
4271
+ super(flags, parent, previousSibling, nextSibling, ...rest), isDev && (this.toString = vnode_toString);
4132
4272
  }
4133
4273
  };
4134
4274
 
@@ -4189,9 +4329,11 @@ function invokeApply(context, fn, args) {
4189
4329
  }
4190
4330
 
4191
4331
  const newInvokeContextFromTuple = ([element, event, url]) => {
4192
- const container = element.closest(QContainerSelector);
4332
+ const domContainer = getDomContainer(element);
4333
+ const container = domContainer.element;
4334
+ const vNode = container ? vnode_locate(domContainer.rootVNode, element) : void 0;
4193
4335
  const locale = container?.getAttribute("q:locale") || void 0;
4194
- return locale && setLocale(locale), newInvokeContext(locale, void 0, element, event, url);
4336
+ return locale && setLocale(locale), newInvokeContext(locale, vNode, element, event, url);
4195
4337
  };
4196
4338
 
4197
4339
  const newInvokeContext = (locale, hostElement, element, event, url) => {
@@ -4217,7 +4359,7 @@ const trackSignal = (fn, subscriber, property, container, data) => {
4217
4359
  const previousSubscriber = trackInvocation.$effectSubscriber$;
4218
4360
  const previousContainer = trackInvocation.$container$;
4219
4361
  try {
4220
- return trackInvocation.$effectSubscriber$ = [ subscriber, property ], data && trackInvocation.$effectSubscriber$.push(data),
4362
+ return trackInvocation.$effectSubscriber$ = getSubscriber(subscriber, property, data),
4221
4363
  trackInvocation.$container$ = container, invoke(trackInvocation, fn);
4222
4364
  } finally {
4223
4365
  trackInvocation.$effectSubscriber$ = previousSubscriber, trackInvocation.$container$ = previousContainer;
@@ -4232,7 +4374,7 @@ const _getContextElement = () => {
4232
4374
  if (iCtx) {
4233
4375
  const hostElement = iCtx.$hostElement$;
4234
4376
  let element = null;
4235
- return vnode_isVNode(hostElement) && vnode_isElementVNode(hostElement) && (element = vnode_getNode(hostElement)),
4377
+ return null != hostElement && (vnode_isVNode(hostElement) ? vnode_isElementVNode(hostElement) && (element = vnode_getNode(hostElement)) : element = hostElement),
4236
4378
  element ?? iCtx.$qrl$?.$setContainer$(void 0);
4237
4379
  }
4238
4380
  };
@@ -4513,9 +4655,9 @@ class DomContainer extends _SharedContainer {
4513
4655
  $storeProxyMap$=new WeakMap;
4514
4656
  $qFuncs$;
4515
4657
  $instanceHash$;
4516
- stateData;
4658
+ vNodeLocate=id => vnode_locate(this.rootVNode, id);
4659
+ $stateData$;
4517
4660
  $styleIds$=null;
4518
- $vnodeLocate$=id => vnode_locate(this.rootVNode, id);
4519
4661
  $renderCount$=0;
4520
4662
  constructor(element) {
4521
4663
  if (super((() => this.scheduleRender()), (() => vnode_applyJournal(this.$journal$)), {}, element.getAttribute("q:locale")),
@@ -4525,24 +4667,24 @@ class DomContainer extends _SharedContainer {
4525
4667
  this.$journal$ = [ VNodeJournalOpCode.HoistStyles, element.ownerDocument ], this.document = element.ownerDocument,
4526
4668
  this.element = element, this.qBase = element.getAttribute("q:base"), this.$instanceHash$ = element.getAttribute("q:instance"),
4527
4669
  this.qManifestHash = element.getAttribute("q:manifest-hash"), this.rootVNode = vnode_newUnMaterializedElement(this.element),
4528
- this.$rawStateData$ = null, this.stateData = null;
4670
+ this.$rawStateData$ = null, this.$stateData$ = null;
4529
4671
  const document = this.element.ownerDocument;
4530
- document.qVNodeData || processVNodeData(document), this.$rawStateData$ = [], this.stateData = [];
4672
+ document.qVNodeData || processVNodeData(document), this.$rawStateData$ = [], this.$stateData$ = [];
4531
4673
  const qwikStates = element.querySelectorAll('script[type="qwik/state"]');
4532
4674
  if (0 !== qwikStates.length) {
4533
4675
  this.$rawStateData$ = JSON.parse(qwikStates[qwikStates.length - 1].textContent),
4534
- this.stateData = wrapDeserializerProxy(this, this.$rawStateData$);
4676
+ this.$stateData$ = wrapDeserializerProxy(this, this.$rawStateData$);
4535
4677
  }
4536
4678
  this.$qFuncs$ = getQFuncs(document, this.$instanceHash$) || EMPTY_ARRAY;
4537
4679
  }
4538
4680
  $setRawState$(id, vParent) {
4539
- this.stateData[id] = vParent;
4681
+ this.$stateData$[id] = vParent;
4540
4682
  }
4541
4683
  parseQRL(qrl) {
4542
4684
  return inflateQRL(this, parseQRL(qrl));
4543
4685
  }
4544
4686
  handleError(err, host) {
4545
- const errorStore = this.resolveContext(host, ERROR_CONTEXT);
4687
+ const errorStore = host && this.resolveContext(host, ERROR_CONTEXT);
4546
4688
  if (!errorStore) {
4547
4689
  throw err;
4548
4690
  }
@@ -4571,7 +4713,7 @@ class DomContainer extends _SharedContainer {
4571
4713
  if (null !== vnode_getProp(vNode, "q:renderFn", null)) {
4572
4714
  return vNode;
4573
4715
  }
4574
- vNode = vnode_getParent(vNode) || vnode_getProp(vNode, ":", this.$vnodeLocate$);
4716
+ vNode = vnode_getParent(vNode) || vnode_getProp(vNode, ":", this.vNodeLocate);
4575
4717
  } else {
4576
4718
  vNode = vnode_getParent(vNode);
4577
4719
  }
@@ -4589,7 +4731,7 @@ class DomContainer extends _SharedContainer {
4589
4731
  case "q:props":
4590
4732
  case "q:renderFn":
4591
4733
  case "q:ctx":
4592
- case "q:subs":
4734
+ case "q:brefs":
4593
4735
  getObjectById = this.$getObjectById$;
4594
4736
  break;
4595
4737
 
@@ -4601,7 +4743,10 @@ class DomContainer extends _SharedContainer {
4601
4743
  }
4602
4744
  scheduleRender() {
4603
4745
  return this.$renderCount$++, this.renderDone ||= getPlatform().nextTick((() => this.processChores())),
4604
- this.renderDone;
4746
+ this.renderDone.finally((() => emitEvent("qrender", {
4747
+ instanceHash: this.$instanceHash$,
4748
+ renderCount: this.$renderCount$
4749
+ })));
4605
4750
  }
4606
4751
  processChores() {
4607
4752
  let renderCount = this.$renderCount$;
@@ -4619,16 +4764,17 @@ class DomContainer extends _SharedContainer {
4619
4764
  ensureProjectionResolved(vNode) {
4620
4765
  if (!(vNode[VNodeProps.flags] & VNodeFlags.Resolved)) {
4621
4766
  vNode[VNodeProps.flags] |= VNodeFlags.Resolved;
4622
- for (let i = vnode_getPropStartIndex(vNode); i < vNode.length; i += 2) {
4623
- if (isSlotProp(vNode[i])) {
4624
- const value = vNode[i + 1];
4625
- "string" == typeof value && (vNode[i + 1] = this.$vnodeLocate$(value));
4767
+ const props = vnode_getProps(vNode);
4768
+ for (let i = 0; i < props.length; i += 2) {
4769
+ if (isSlotProp(props[i])) {
4770
+ const value = props[i + 1];
4771
+ "string" == typeof value && (props[i + 1] = this.vNodeLocate(value));
4626
4772
  }
4627
4773
  }
4628
4774
  }
4629
4775
  }
4630
4776
  $getObjectById$=id => ("string" == typeof id && (id = parseFloat(id)), assertTrue(id < this.$rawStateData$.length / 2, `Invalid reference: ${id} >= ${this.$rawStateData$.length / 2}`),
4631
- this.stateData[id]);
4777
+ this.$stateData$[id]);
4632
4778
  getSyncFn(id) {
4633
4779
  const fn = this.$qFuncs$[id];
4634
4780
  return assertTrue("function" == typeof fn, "Invalid reference: " + id), fn;
@@ -4760,7 +4906,7 @@ const inflate = (container, target, typeId, data) => {
4760
4906
  const task = target;
4761
4907
  const v = data;
4762
4908
  task.$qrl$ = inflateQRL(container, v[0]), task.$flags$ = v[1], task.$index$ = v[2],
4763
- task.$el$ = v[3], task.$effectDependencies$ = v[4], task.$state$ = v[5];
4909
+ task.$el$ = v[3], task[_EFFECT_BACK_REF] = v[4], task.$state$ = v[5];
4764
4910
  break;
4765
4911
 
4766
4912
  case TypeIds.Resource:
@@ -4778,11 +4924,9 @@ const inflate = (container, target, typeId, data) => {
4778
4924
  case TypeIds.Store:
4779
4925
  case TypeIds.StoreArray:
4780
4926
  {
4781
- const [value, flags, effects, storeEffect] = data;
4927
+ const [value, flags, effects] = data;
4782
4928
  const store = getOrCreateStore(value, flags, container);
4783
- const storeHandler = getStoreHandler(store);
4784
- storeEffect && (effects[STORE_ARRAY_PROP] = storeEffect), storeHandler.$effects$ = effects,
4785
- target = store;
4929
+ getStoreHandler(store).$effects$ = effects, target = store;
4786
4930
  break;
4787
4931
  }
4788
4932
 
@@ -4790,7 +4934,7 @@ const inflate = (container, target, typeId, data) => {
4790
4934
  {
4791
4935
  const signal = target;
4792
4936
  const d = data;
4793
- signal.$untrackedValue$ = d[0], signal.$effects$ = d.slice(1);
4937
+ signal.$untrackedValue$ = d[0], signal.$effects$ = new Set(d.slice(1));
4794
4938
  break;
4795
4939
  }
4796
4940
 
@@ -4798,8 +4942,8 @@ const inflate = (container, target, typeId, data) => {
4798
4942
  {
4799
4943
  const signal = target;
4800
4944
  const d = data;
4801
- signal.$func$ = container.getSyncFn(d[0]), signal.$args$ = d[1], signal.$effectDependencies$ = d[2],
4802
- signal.$untrackedValue$ = d[3], signal.$hostElement$ = d[4], signal.$effects$ = d.slice(5);
4945
+ signal.$func$ = container.getSyncFn(d[0]), signal.$args$ = d[1], signal[_EFFECT_BACK_REF] = d[2],
4946
+ signal.$untrackedValue$ = d[3], signal.$hostElement$ = d[4], signal.$effects$ = new Set(d.slice(5));
4803
4947
  break;
4804
4948
  }
4805
4949
 
@@ -4903,7 +5047,7 @@ const inflate = (container, target, typeId, data) => {
4903
5047
  return target;
4904
5048
  };
4905
5049
 
4906
- const _constants = [ void 0, null, !0, !1, "", EMPTY_ARRAY, EMPTY_OBJ, NEEDS_COMPUTATION, Slot, Fragment, NaN, 1 / 0, -1 / 0, Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER - 1, Number.MIN_SAFE_INTEGER ];
5050
+ const _constants = [ void 0, null, !0, !1, "", EMPTY_ARRAY, EMPTY_OBJ, NEEDS_COMPUTATION, STORE_ARRAY_PROP, Slot, Fragment, NaN, 1 / 0, -1 / 0, Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER - 1, Number.MIN_SAFE_INTEGER ];
4907
5051
 
4908
5052
  const allocate = (container, typeId, value) => {
4909
5053
  if (void 0 === value) {
@@ -4993,7 +5137,7 @@ const allocate = (container, typeId, value) => {
4993
5137
  const promise = new Promise(((res, rej) => {
4994
5138
  resolve = res, reject = rej;
4995
5139
  }));
4996
- return resolvers.set(promise, [ resolve, reject ]), promise;
5140
+ return resolvers.set(promise, [ resolve, reject ]), promise.catch((() => {})), promise;
4997
5141
 
4998
5142
  case TypeIds.Uint8Array:
4999
5143
  const encodedLength = value.length;
@@ -5003,12 +5147,10 @@ const allocate = (container, typeId, value) => {
5003
5147
  case TypeIds.PropsProxy:
5004
5148
  return createPropsProxy(null, null);
5005
5149
 
5006
- case TypeIds.RefVNode:
5007
5150
  case TypeIds.VNode:
5008
- const vnodeOrDocument = retrieveVNodeOrDocument(container, value);
5009
- if (typeId === TypeIds.VNode) {
5010
- return vnodeOrDocument;
5011
- }
5151
+ return retrieveVNodeOrDocument(container, value);
5152
+
5153
+ case TypeIds.RefVNode:
5012
5154
  const vNode = retrieveVNodeOrDocument(container, value);
5013
5155
  if (vnode_isVNode(vNode)) {
5014
5156
  return vnode_getNode(vNode);
@@ -5016,7 +5158,7 @@ const allocate = (container, typeId, value) => {
5016
5158
  throw qError(QError.serializeErrorExpectedVNode, [ typeof vNode ]);
5017
5159
 
5018
5160
  case TypeIds.EffectData:
5019
- return new EffectPropData({});
5161
+ return new SubscriptionData({});
5020
5162
 
5021
5163
  default:
5022
5164
  throw qError(QError.serializeErrorCannotAllocate, [ typeId ]);
@@ -5039,7 +5181,7 @@ function parseQRL(qrl) {
5039
5181
  const backChannel = globalThis[QRL_RUNTIME_CHUNK];
5040
5182
  assertDefined(backChannel, "Missing QRL_RUNTIME_CHUNK"), qrlRef = backChannel.get(symbol);
5041
5183
  }
5042
- return createQRL(chunk, symbol, qrlRef, null, captureIds, null, null);
5184
+ return createQRL(chunk, symbol, qrlRef, null, captureIds, null);
5043
5185
  }
5044
5186
 
5045
5187
  function inflateQRL(container, qrl) {
@@ -5117,18 +5259,18 @@ const createSerializationContext = (NodeConstructor, DomRefConstructor, symbolTo
5117
5259
  const promises = [];
5118
5260
  const visit = obj => {
5119
5261
  if ("function" == typeof obj) {
5120
- if (isQrl(obj)) {
5262
+ if (isQrl$1(obj)) {
5121
5263
  obj.$captureRef$ && discoveredValues.push(...obj.$captureRef$);
5122
5264
  } else if (isQwikComponent(obj)) {
5123
5265
  const [qrl] = obj[SERIALIZABLE_STATE];
5124
5266
  discoveredValues.push(qrl);
5125
5267
  }
5126
- } else if ("object" != typeof obj || null === obj || obj instanceof URL || obj instanceof Date || obj instanceof RegExp || obj instanceof Uint8Array || obj instanceof URLSearchParams || "undefined" != typeof FormData && obj instanceof FormData || fastSkipSerialize(obj)) {} else if (obj instanceof Error) {
5268
+ } else if ("object" != typeof obj || null === obj || obj instanceof URL || obj instanceof Date || obj instanceof RegExp || obj instanceof Uint8Array || obj instanceof URLSearchParams || vnode_isVNode(obj) || "undefined" != typeof FormData && obj instanceof FormData || fastSkipSerialize(obj)) {} else if (obj instanceof Error) {
5127
5269
  discoveredValues.push(...Object.values(obj));
5128
5270
  } else if (isStore(obj)) {
5129
5271
  const target = getStoreTarget(obj);
5130
5272
  const effects = getStoreHandler(obj).$effects$;
5131
- discoveredValues.push(target, effects, effects?.[STORE_ARRAY_PROP] ?? null);
5273
+ discoveredValues.push(target, effects);
5132
5274
  for (const prop in target) {
5133
5275
  const propValue = target[prop];
5134
5276
  storeProxyMap.has(propValue) && discoveredValues.push(prop, storeProxyMap.get(propValue));
@@ -5142,10 +5284,10 @@ const createSerializationContext = (NodeConstructor, DomRefConstructor, symbolTo
5142
5284
  } else if (obj instanceof Signal) {
5143
5285
  const v = obj instanceof WrappedSignal ? obj.untrackedValue : obj instanceof ComputedSignal && (obj.$invalid$ || fastSkipSerialize(obj)) ? NEEDS_COMPUTATION : obj.$untrackedValue$;
5144
5286
  v !== NEEDS_COMPUTATION && discoveredValues.push(v), obj.$effects$ && discoveredValues.push(...obj.$effects$),
5145
- obj instanceof WrappedSignal ? (obj.$effectDependencies$ && discoveredValues.push(...obj.$effectDependencies$),
5287
+ obj instanceof WrappedSignal ? (discoverEffectBackRefs(obj[_EFFECT_BACK_REF], discoveredValues),
5146
5288
  obj.$args$ && discoveredValues.push(...obj.$args$), obj.$hostElement$ && discoveredValues.push(obj.$hostElement$)) : obj instanceof ComputedSignal && discoveredValues.push(obj.$computeQrl$);
5147
5289
  } else if (obj instanceof Task) {
5148
- discoveredValues.push(obj.$el$, obj.$qrl$, obj.$state$, obj.$effectDependencies$);
5290
+ discoveredValues.push(obj.$el$, obj.$qrl$, obj.$state$), discoverEffectBackRefs(obj[_EFFECT_BACK_REF], discoveredValues);
5149
5291
  } else if (isSsrNode(obj)) {
5150
5292
  if (discoverValuesForVNodeData(obj.vnodeData, discoveredValues), obj.childrenVNodeData && obj.childrenVNodeData.length) {
5151
5293
  for (const data of obj.childrenVNodeData) {
@@ -5158,7 +5300,7 @@ const createSerializationContext = (NodeConstructor, DomRefConstructor, symbolTo
5158
5300
  discoveredValues.push(obj.type, obj.props, obj.constProps, obj.children);
5159
5301
  } else if (Array.isArray(obj)) {
5160
5302
  discoveredValues.push(...obj);
5161
- } else if (isQrl(obj)) {
5303
+ } else if (isQrl$1(obj)) {
5162
5304
  obj.$captureRef$ && obj.$captureRef$.length && discoveredValues.push(...obj.$captureRef$);
5163
5305
  } else if (isPropsProxy(obj)) {
5164
5306
  discoveredValues.push(obj[_VAR_PROPS], obj[_CONST_PROPS]);
@@ -5168,7 +5310,7 @@ const createSerializationContext = (NodeConstructor, DomRefConstructor, symbolTo
5168
5310
  }), (error => {
5169
5311
  promiseResults.set(obj, [ !1, error ]), discoveredValues.push(error);
5170
5312
  })), promises.push(obj);
5171
- } else if (obj instanceof EffectPropData) {
5313
+ } else if (obj instanceof SubscriptionData) {
5172
5314
  discoveredValues.push(obj.data);
5173
5315
  } else {
5174
5316
  if (!isObjectLiteral(obj)) {
@@ -5211,12 +5353,23 @@ const discoverValuesForVNodeData = (vnodeData, discoveredValues) => {
5211
5353
  for (const value of vnodeData) {
5212
5354
  if (isSsrAttrs(value)) {
5213
5355
  for (let i = 1; i < value.length; i += 2) {
5214
- if ("q:key" === value[i - 1]) {
5215
- continue;
5216
- }
5217
- discoveredValues.push(value[i]);
5356
+ const attrValue = value[i];
5357
+ "string" != typeof attrValue && discoveredValues.push(attrValue);
5358
+ }
5359
+ }
5360
+ }
5361
+ };
5362
+
5363
+ const discoverEffectBackRefs = (effectsBackRefs, discoveredValues) => {
5364
+ if (effectsBackRefs) {
5365
+ let hasBackRefs = !1;
5366
+ for (const [, effect] of effectsBackRefs) {
5367
+ if (effect[EffectSubscriptionProp.BACK_REF]) {
5368
+ hasBackRefs = !0;
5369
+ break;
5218
5370
  }
5219
5371
  }
5372
+ hasBackRefs && discoveredValues.push(effectsBackRefs);
5220
5373
  }
5221
5374
  };
5222
5375
 
@@ -5258,7 +5411,7 @@ function serialize(serializationContext) {
5258
5411
  output(TypeIds.Constant, Constants.Slot);
5259
5412
  } else if (value === Fragment) {
5260
5413
  output(TypeIds.Constant, Constants.Fragment);
5261
- } else if (isQrl(value)) {
5414
+ } else if (isQrl$1(value)) {
5262
5415
  const qrl = qrlToString(serializationContext, value);
5263
5416
  const id = serializationContext.$addRoot$(qrl);
5264
5417
  output(TypeIds.QRL, id);
@@ -5284,11 +5437,13 @@ function serialize(serializationContext) {
5284
5437
  }
5285
5438
  } else if (void 0 === value) {
5286
5439
  output(TypeIds.Constant, Constants.Undefined);
5440
+ } else if (value === NEEDS_COMPUTATION) {
5441
+ output(TypeIds.Constant, Constants.NEEDS_COMPUTATION);
5287
5442
  } else {
5288
- if (value !== NEEDS_COMPUTATION) {
5443
+ if (value !== STORE_ARRAY_PROP) {
5289
5444
  throw qError(QError.serializeErrorUnknownType, [ typeof value ]);
5290
5445
  }
5291
- output(TypeIds.Constant, Constants.NEEDS_COMPUTATION);
5446
+ output(TypeIds.Constant, Constants.STORE_ARRAY_PROP);
5292
5447
  }
5293
5448
  };
5294
5449
  const writeObjectValue = (value, idx) => {
@@ -5304,7 +5459,7 @@ function serialize(serializationContext) {
5304
5459
  const constProps = value[_CONST_PROPS];
5305
5460
  const out = constProps ? [ varProps, constProps ] : Object.keys(varProps).length ? [ varProps ] : 0;
5306
5461
  output(TypeIds.PropsProxy, out);
5307
- } else if (value instanceof EffectPropData) {
5462
+ } else if (value instanceof SubscriptionData) {
5308
5463
  output(TypeIds.EffectData, [ value.data.$scopedStyleIdPrefix$, value.data.$isConst$ ]);
5309
5464
  } else if (isStore(value)) {
5310
5465
  if (isResource(value)) {
@@ -5319,7 +5474,6 @@ function serialize(serializationContext) {
5319
5474
  const storeTarget = getStoreTarget(value);
5320
5475
  const flags = storeHandler.$flags$;
5321
5476
  const effects = storeHandler.$effects$;
5322
- const storeEffect = effects?.[STORE_ARRAY_PROP] ?? null;
5323
5477
  const innerStores = [];
5324
5478
  for (const prop in storeTarget) {
5325
5479
  const propValue = storeTarget[prop];
@@ -5328,7 +5482,7 @@ function serialize(serializationContext) {
5328
5482
  innerStores.push(innerStore), serializationContext.$addRoot$(innerStore);
5329
5483
  }
5330
5484
  }
5331
- const out = [ storeTarget, flags, effects, storeEffect, ...innerStores ];
5485
+ const out = [ storeTarget, flags, effects, ...innerStores ];
5332
5486
  for (;null == out[out.length - 1]; ) {
5333
5487
  out.pop();
5334
5488
  }
@@ -5349,7 +5503,7 @@ function serialize(serializationContext) {
5349
5503
  } else if (value instanceof Signal) {
5350
5504
  const v = value instanceof ComputedSignal && (value.$invalid$ || fastSkipSerialize(value.$untrackedValue$)) ? NEEDS_COMPUTATION : value.$untrackedValue$;
5351
5505
  if (value instanceof WrappedSignal) {
5352
- output(TypeIds.WrappedSignal, [ ...serializeWrappingFn(serializationContext, value), value.$effectDependencies$, v, value.$hostElement$, ...value.$effects$ || [] ]);
5506
+ output(TypeIds.WrappedSignal, [ ...serializeWrappingFn(serializationContext, value), filterEffectBackRefs(value[_EFFECT_BACK_REF]), v, value.$hostElement$, ...value.$effects$ || [] ]);
5353
5507
  } else if (value instanceof ComputedSignal) {
5354
5508
  const out = [ value.$computeQrl$, value.$effects$ ];
5355
5509
  v !== NEEDS_COMPUTATION && out.push(v), output(TypeIds.ComputedSignal, out);
@@ -5397,7 +5551,7 @@ function serialize(serializationContext) {
5397
5551
  } else if (isJSXNode(value)) {
5398
5552
  output(TypeIds.JSXNode, [ value.type, value.varProps, value.constProps, value.children, value.flags, value.key ]);
5399
5553
  } else if (value instanceof Task) {
5400
- const out = [ value.$qrl$, value.$flags$, value.$index$, value.$el$, value.$effectDependencies$, value.$state$ ];
5554
+ const out = [ value.$qrl$, value.$flags$, value.$index$, value.$el$, value[_EFFECT_BACK_REF], value.$state$ ];
5401
5555
  for (;null == out[out.length - 1]; ) {
5402
5556
  out.pop();
5403
5557
  }
@@ -5408,23 +5562,34 @@ function serialize(serializationContext) {
5408
5562
  throw qError(QError.serializeErrorUnvisited, [ "promise" ]);
5409
5563
  }
5410
5564
  output(TypeIds.Promise, res);
5565
+ } else if (value instanceof Uint8Array) {
5566
+ let buf = "";
5567
+ for (const c of value) {
5568
+ buf += String.fromCharCode(c);
5569
+ }
5570
+ const out = btoa(buf).replace(/=+$/, "");
5571
+ output(TypeIds.Uint8Array, out);
5411
5572
  } else {
5412
- if (!(value instanceof Uint8Array)) {
5573
+ if (!vnode_isVNode(value)) {
5413
5574
  throw qError(QError.serializeErrorUnknownType, [ typeof value ]);
5414
5575
  }
5415
- {
5416
- let buf = "";
5417
- for (const c of value) {
5418
- buf += String.fromCharCode(c);
5419
- }
5420
- const out = btoa(buf).replace(/=+$/, "");
5421
- output(TypeIds.Uint8Array, out);
5422
- }
5576
+ output(TypeIds.Constant, Constants.Undefined);
5423
5577
  }
5424
5578
  };
5425
5579
  writeValue(serializationContext.$roots$, -1);
5426
5580
  }
5427
5581
 
5582
+ function filterEffectBackRefs(effectBackRef) {
5583
+ let effectBackRefToSerialize = null;
5584
+ if (effectBackRef) {
5585
+ for (const [effectProp, effect] of effectBackRef) {
5586
+ effect[EffectSubscriptionProp.BACK_REF] && (effectBackRefToSerialize ||= new Map,
5587
+ effectBackRefToSerialize.set(effectProp, effect));
5588
+ }
5589
+ }
5590
+ return effectBackRefToSerialize;
5591
+ }
5592
+
5428
5593
  function serializeWrappingFn(serializationContext, value) {
5429
5594
  value.$funcStr$ && "{" === value.$funcStr$[0] && (value.$funcStr$ = `(${value.$funcStr$})`);
5430
5595
  return [ serializationContext.$addSyncFn$(value.$funcStr$, value.$args$.length, value.$func$), value.$args$ ];
@@ -5433,11 +5598,10 @@ function serializeWrappingFn(serializationContext, value) {
5433
5598
  function qrlToString(serializationContext, value) {
5434
5599
  let symbol = value.$symbol$;
5435
5600
  let chunk = value.$chunk$;
5436
- const refSymbol = value.$refSymbol$ ?? symbol;
5437
5601
  const platform = getPlatform();
5438
5602
  if (platform) {
5439
- const result = platform.chunkForSymbol(refSymbol, chunk, value.dev?.file);
5440
- result && (chunk = result[1], value.$refSymbol$ || (symbol = result[0]));
5603
+ const result = platform.chunkForSymbol(symbol, chunk, value.dev?.file);
5604
+ result && (chunk = result[1], symbol = result[0]);
5441
5605
  }
5442
5606
  if (isSyncQrl(value)) {
5443
5607
  chunk = "", symbol = String(serializationContext.$addSyncFn$(null, 0, value.resolved));
@@ -5531,17 +5695,21 @@ function isResource(value) {
5531
5695
  return "__brand" in value && "resource" === value.__brand;
5532
5696
  }
5533
5697
 
5534
- const frameworkType = obj => "object" == typeof obj && null !== obj && (obj instanceof Signal || obj instanceof Task || isJSXNode(obj)) || isQrl(obj);
5698
+ const frameworkType = obj => "object" == typeof obj && null !== obj && (obj instanceof Signal || obj instanceof Task || isJSXNode(obj)) || isQrl$1(obj);
5535
5699
 
5536
- const canSerialize = value => {
5700
+ const canSerialize = (value, seen = new WeakSet) => {
5537
5701
  if (null == value || "string" == typeof value || "number" == typeof value || "boolean" == typeof value || "bigint" == typeof value) {
5538
5702
  return !0;
5539
5703
  }
5540
5704
  if ("object" == typeof value) {
5705
+ if (seen.has(value)) {
5706
+ return !0;
5707
+ }
5708
+ seen.add(value);
5541
5709
  const proto = Object.getPrototypeOf(value);
5542
5710
  if (isStore(value) && (value = getStoreTarget(value)), proto == Object.prototype) {
5543
5711
  for (const key in value) {
5544
- if (!canSerialize(untrack((() => value[key])))) {
5712
+ if (!canSerialize(untrack((() => value[key])), seen)) {
5545
5713
  return !1;
5546
5714
  }
5547
5715
  }
@@ -5549,7 +5717,7 @@ const canSerialize = value => {
5549
5717
  }
5550
5718
  if (proto == Array.prototype) {
5551
5719
  for (let i = 0; i < value.length; i++) {
5552
- if (!canSerialize(value[i])) {
5720
+ if (!canSerialize(value[i], seen)) {
5553
5721
  return !1;
5554
5722
  }
5555
5723
  }
@@ -5597,7 +5765,7 @@ const canSerialize = value => {
5597
5765
  if (isDomRef?.(value)) {
5598
5766
  return !0;
5599
5767
  }
5600
- } else if ("function" == typeof value && (isQrl(value) || isQwikComponent(value))) {
5768
+ } else if ("function" == typeof value && (isQrl$1(value) || isQwikComponent(value))) {
5601
5769
  return !0;
5602
5770
  }
5603
5771
  return !1;
@@ -5629,14 +5797,15 @@ var Constants;
5629
5797
  Constants[Constants.True = 2] = "True", Constants[Constants.False = 3] = "False",
5630
5798
  Constants[Constants.EmptyString = 4] = "EmptyString", Constants[Constants.EMPTY_ARRAY = 5] = "EMPTY_ARRAY",
5631
5799
  Constants[Constants.EMPTY_OBJ = 6] = "EMPTY_OBJ", Constants[Constants.NEEDS_COMPUTATION = 7] = "NEEDS_COMPUTATION",
5632
- Constants[Constants.Slot = 8] = "Slot", Constants[Constants.Fragment = 9] = "Fragment",
5633
- Constants[Constants.NaN = 10] = "NaN", Constants[Constants.PositiveInfinity = 11] = "PositiveInfinity",
5634
- Constants[Constants.NegativeInfinity = 12] = "NegativeInfinity", Constants[Constants.MaxSafeInt = 13] = "MaxSafeInt",
5635
- Constants[Constants.AlmostMaxSafeInt = 14] = "AlmostMaxSafeInt", Constants[Constants.MinSafeInt = 15] = "MinSafeInt";
5800
+ Constants[Constants.STORE_ARRAY_PROP = 8] = "STORE_ARRAY_PROP", Constants[Constants.Slot = 9] = "Slot",
5801
+ Constants[Constants.Fragment = 10] = "Fragment", Constants[Constants.NaN = 11] = "NaN",
5802
+ Constants[Constants.PositiveInfinity = 12] = "PositiveInfinity", Constants[Constants.NegativeInfinity = 13] = "NegativeInfinity",
5803
+ Constants[Constants.MaxSafeInt = 14] = "MaxSafeInt", Constants[Constants.AlmostMaxSafeInt = 15] = "AlmostMaxSafeInt",
5804
+ Constants[Constants.MinSafeInt = 16] = "MinSafeInt";
5636
5805
  }(Constants || (Constants = {}));
5637
5806
 
5638
5807
  const verifySerializable = (value, preMessage) => {
5639
- const seen = new Set;
5808
+ const seen = new WeakSet;
5640
5809
  return _verifySerializable(value, seen, "_", preMessage);
5641
5810
  };
5642
5811
 
@@ -5646,10 +5815,13 @@ const _verifySerializable = (value, seen, ctx, preMessage) => {
5646
5815
  return value;
5647
5816
  }
5648
5817
  if (shouldSerialize(unwrapped)) {
5649
- if (seen.has(unwrapped)) {
5650
- return value;
5818
+ if ("object" == typeof unwrapped) {
5819
+ if (seen.has(unwrapped)) {
5820
+ return value;
5821
+ }
5822
+ seen.add(unwrapped);
5651
5823
  }
5652
- if (seen.add(unwrapped), isSignal(unwrapped)) {
5824
+ if (isSignal(unwrapped)) {
5653
5825
  return value;
5654
5826
  }
5655
5827
  if (canSerialize(unwrapped)) {
@@ -5711,13 +5883,7 @@ const noSerialize = input => (null != input && noSerializeSet.add(input), input)
5711
5883
 
5712
5884
  const _weakSerialize = input => (weakSerializeSet.add(input), input);
5713
5885
 
5714
- const isQrl = value => "function" == typeof value && "function" == typeof value.getSymbol;
5715
-
5716
- const SYNC_QRL = "<sync>";
5717
-
5718
- const isSyncQrl = value => isQrl(value) && "<sync>" == value.$symbol$;
5719
-
5720
- const createQRL = (chunk, symbol, symbolRef, symbolFn, capture, captureRef, refSymbol) => {
5886
+ const createQRL = (chunk, symbol, symbolRef, symbolFn, capture, captureRef) => {
5721
5887
  let _containerEl;
5722
5888
  const qrl = async function(...args) {
5723
5889
  const boundedFn = bindFnToContext.call(this, tryGetInvokeContext());
@@ -5725,9 +5891,14 @@ const createQRL = (chunk, symbol, symbolRef, symbolFn, capture, captureRef, refS
5725
5891
  };
5726
5892
  const setContainer = el => (_containerEl || (_containerEl = el), _containerEl);
5727
5893
  function bindFnToContext(currentCtx, beforeFn) {
5728
- return (...args) => maybeThen(resolveLazy(), (fn => {
5729
- if (!isFunction(fn)) {
5730
- throw qError(QError.qrlIsNotFunction);
5894
+ const bound = (...args) => {
5895
+ if (!qrl.resolved) {
5896
+ return qrl.resolve().then((fn => {
5897
+ if (!isFunction(fn)) {
5898
+ throw qError(QError.qrlIsNotFunction);
5899
+ }
5900
+ return bound(...args);
5901
+ }));
5731
5902
  }
5732
5903
  if (beforeFn && !1 === beforeFn()) {
5733
5904
  return;
@@ -5737,17 +5908,29 @@ const createQRL = (chunk, symbol, symbolRef, symbolFn, capture, captureRef, refS
5737
5908
  const prevEvent = context.$event$;
5738
5909
  context.$qrl$ = qrl, context.$event$ ||= this;
5739
5910
  try {
5740
- return invoke.call(this, context, fn, ...args);
5911
+ return invoke.call(this, context, symbolRef, ...args);
5741
5912
  } finally {
5742
5913
  context.$qrl$ = prevQrl, context.$event$ = prevEvent;
5743
5914
  }
5744
- }));
5915
+ };
5916
+ return bound;
5745
5917
  }
5746
- const resolveLazy = containerEl => null !== symbolRef ? symbolRef : resolve(containerEl);
5747
5918
  const wrapFn = fn => "function" != typeof fn || !capture?.length && !captureRef?.length ? fn : function(...args) {
5748
5919
  let context = tryGetInvokeContext();
5749
- return context ? fn.apply(this, args) : (context = newInvokeContext(), context.$qrl$ = qrl,
5750
- context.$event$ = this, invoke.call(this, context, fn, ...args));
5920
+ if (context) {
5921
+ if (context.$qrl$?.$symbol$ === qrl.$symbol$) {
5922
+ return fn.apply(this, args);
5923
+ }
5924
+ const prevQrl = context.$qrl$;
5925
+ context.$qrl$ = qrl;
5926
+ try {
5927
+ return fn.apply(this, args);
5928
+ } finally {
5929
+ context.$qrl$ = prevQrl;
5930
+ }
5931
+ }
5932
+ return context = newInvokeContext(), context.$qrl$ = qrl, context.$event$ = this,
5933
+ invoke.call(this, context, fn, ...args);
5751
5934
  };
5752
5935
  const resolve = async containerEl => {
5753
5936
  if (null !== symbolRef) {
@@ -5762,49 +5945,38 @@ const createQRL = (chunk, symbol, symbolRef, symbolFn, capture, captureRef, refS
5762
5945
  const start = now();
5763
5946
  const ctx = tryGetInvokeContext();
5764
5947
  if (null !== symbolFn) {
5765
- symbolRef = symbolFn().then((module => qrl.resolved = symbolRef = wrapFn(module[symbol])));
5948
+ symbolRef = symbolFn().then((module => qrl.resolved = wrapFn(symbolRef = module[symbol])));
5766
5949
  } else {
5767
5950
  const imported = getPlatform().importSymbol(_containerEl, chunk, symbol);
5768
- symbolRef = maybeThen(imported, (ref => qrl.resolved = symbolRef = wrapFn(ref)));
5951
+ symbolRef = maybeThen(imported, (ref => qrl.resolved = wrapFn(symbolRef = ref)));
5769
5952
  }
5770
5953
  return "object" == typeof symbolRef && isPromise(symbolRef) && symbolRef.then((() => emitUsedSymbol(symbol, ctx?.$element$, start)), (err => {
5771
5954
  throw console.error(`qrl ${symbol} failed to load`, err), symbolRef = null, err;
5772
5955
  })), symbolRef;
5773
5956
  };
5774
5957
  const createOrReuseInvocationContext = invoke => null == invoke ? newInvokeContext() : isArray(invoke) ? newInvokeContextFromTuple(invoke) : invoke;
5775
- const resolvedSymbol = refSymbol ?? symbol;
5776
- const hash = getSymbolHash(resolvedSymbol);
5958
+ const hash = getSymbolHash(symbol);
5777
5959
  return Object.assign(qrl, {
5778
- getSymbol: () => resolvedSymbol,
5960
+ getSymbol: () => symbol,
5779
5961
  getHash: () => hash,
5780
5962
  getCaptured: () => captureRef,
5781
5963
  resolve,
5782
- $resolveLazy$: resolveLazy,
5964
+ $resolveLazy$: containerEl => null !== symbolRef ? symbolRef : resolve(containerEl),
5783
5965
  $setContainer$: setContainer,
5784
5966
  $chunk$: chunk,
5785
5967
  $symbol$: symbol,
5786
- $refSymbol$: refSymbol,
5787
5968
  $hash$: hash,
5788
5969
  getFn: bindFnToContext,
5789
5970
  $capture$: capture,
5790
5971
  $captureRef$: captureRef,
5791
5972
  dev: null,
5792
5973
  resolved: void 0
5793
- }), symbolRef && (symbolRef = maybeThen(symbolRef, (resolved => qrl.resolved = symbolRef = wrapFn(resolved)))),
5974
+ }), symbolRef && (symbolRef = maybeThen(symbolRef, (resolved => qrl.resolved = wrapFn(symbolRef = resolved)))),
5794
5975
  isDev && Object.defineProperty(qrl, "_devOnlySymbolRef", {
5795
5976
  get: () => symbolRef
5796
5977
  }), qrl;
5797
5978
  };
5798
5979
 
5799
- const getSymbolHash = symbolName => {
5800
- const index = symbolName.lastIndexOf("_");
5801
- return index > -1 ? symbolName.slice(index + 1) : symbolName;
5802
- };
5803
-
5804
- function assertQrl() {
5805
- qDev;
5806
- }
5807
-
5808
5980
  const EMITTED = /*#__PURE__*/ new Set;
5809
5981
 
5810
5982
  const emitUsedSymbol = (symbol, element, reqTime) => {
@@ -5826,17 +5998,17 @@ const now = () => isServerPlatform() ? 0 : "object" == typeof performance ? perf
5826
5998
 
5827
5999
  let runtimeSymbolId = 0;
5828
6000
 
5829
- const $ = expression => createQRL(null, "s" + runtimeSymbolId++, expression, null, null, null, null);
6001
+ const $ = expression => createQRL(null, "s" + runtimeSymbolId++, expression, null, null, null);
5830
6002
 
5831
6003
  const dollar = $;
5832
6004
 
5833
6005
  const eventQrl = qrl => qrl;
5834
6006
 
5835
- const sync$ = fn => createQRL("", "<sync>", fn, null, null, null, null);
6007
+ const sync$ = fn => createQRL("", "<sync>", fn, null, null, null);
5836
6008
 
5837
6009
  const _qrlSync = function(fn, serializedFn) {
5838
6010
  return void 0 === serializedFn && (serializedFn = fn.toString()), fn.serialized = serializedFn,
5839
- createQRL("", "<sync>", fn, null, null, null, null);
6011
+ createQRL("", "<sync>", fn, null, null, null);
5840
6012
  };
5841
6013
 
5842
6014
  const componentQrl = componentQrl => {
@@ -5966,7 +6138,7 @@ const scopeStylesheet = (css, scopeId) => {
5966
6138
  out.push(css.substring(lastIdx, idx)), lastIdx = idx;
5967
6139
  }
5968
6140
  function insertScopingSelector(idx) {
5969
- mode === pseudoGlobal || shouldNotInsertScoping() || (flush(idx), out.push(".", "⭐️", scopeId));
6141
+ mode === pseudoGlobal || shouldNotInsertScoping() || (flush(idx), out.push(".", "⚡️", scopeId));
5970
6142
  }
5971
6143
  function lookAhead(arc) {
5972
6144
  let prefix = 0;
@@ -6117,7 +6289,7 @@ const useStylesQrl = styles => ({
6117
6289
  const useStyles$ = /*#__PURE__*/ implicit$FirstArg(useStylesQrl);
6118
6290
 
6119
6291
  const useStylesScopedQrl = styles => ({
6120
- scopeId: "⭐️" + _useStyles(styles, getScopedStyles, !0)
6292
+ scopeId: "⚡️" + _useStyles(styles, getScopedStyles, !0)
6121
6293
  });
6122
6294
 
6123
6295
  const useStylesScoped$ = /*#__PURE__*/ implicit$FirstArg(useStylesScopedQrl);
@@ -6172,6 +6344,12 @@ const useVisibleTaskQrl = (qrl, opts) => {
6172
6344
  iCtx.$container$.$scheduler$(ChoreType.VISIBLE, task));
6173
6345
  };
6174
6346
 
6347
+ const useRunTask = (task, eagerness) => {
6348
+ "intersection-observer" === eagerness ? useOn("qvisible", getTaskHandlerQrl(task)) : "document-ready" === eagerness ? useOnDocument("qinit", getTaskHandlerQrl(task)) : "document-idle" === eagerness && useOnDocument("qidle", getTaskHandlerQrl(task));
6349
+ };
6350
+
6351
+ const getTaskHandlerQrl = task => createQRL(null, "_task", scheduleTask, null, null, [ task ]);
6352
+
6175
6353
  const useResource$ = (generatorFn, opts) => useResourceQrl(dollar(generatorFn), opts);
6176
6354
 
6177
6355
  const useTask$ = /*#__PURE__*/ implicit$FirstArg(useTaskQrl);
@@ -6244,4 +6422,4 @@ const PrefetchGraph = (opts = {}) => {
6244
6422
  }, null, 0, "prefetch-graph");
6245
6423
  };
6246
6424
 
6247
- export { $, Fragment, PrefetchGraph, PrefetchServiceWorker, RenderOnce, Resource, SSRComment, SSRRaw, SSRStream, SSRStreamBlock, SkipRender, Slot, _CONST_PROPS, DomContainer as _DomContainer, EMPTY_ARRAY as _EMPTY_ARRAY, EffectPropData as _EffectData, _IMMUTABLE, _SharedContainer, _VAR_PROPS, _deserialize, _fnSignal, _getContextElement, _getContextEvent, getDomContainer as _getDomContainer, _getQContainerElement, _hW, isJSXNode as _isJSXNode, isStringifiable as _isStringifiable, _jsxBranch, _jsxC, _jsxQ, _jsxS, _jsxSorted, _jsxSplit, _noopQrl, _noopQrlDEV, _qrlSync, _regSymbol, _restProps, _serialize, verifySerializable as _verifySerializable, _waitUntilRendered, _walkJSX, _weakSerialize, _wrapProp, _wrapSignal, component$, componentQrl, createComputed$, createComputedQrl, createContextId, h as createElement, createSignal, event$, eventQrl, getDomContainer, getLocale, getPlatform, h, implicit$FirstArg, inlinedQrl, inlinedQrlDEV, isSignal, jsx, jsxDEV, jsx as jsxs, noSerialize, qrl, qrlDEV, render, setPlatform, sync$, untrack, unwrapStore, useComputed$, useComputedQrl, useConstant, useContext, useContextProvider, useErrorBoundary, useId, useLexicalScope, useOn, useOnDocument, useOnWindow, useResource$, useResourceQrl, useServerData, useSignal, useStore, useStyles$, useStylesQrl, useStylesScoped$, useStylesScopedQrl, useTask$, useTaskQrl, useVisibleTask$, useVisibleTaskQrl, version, withLocale };
6425
+ export { $, Fragment, PrefetchGraph, PrefetchServiceWorker, RenderOnce, Resource, SSRComment, SSRRaw, SSRStream, SSRStreamBlock, SkipRender, Slot, _CONST_PROPS, DomContainer as _DomContainer, _EFFECT_BACK_REF, EMPTY_ARRAY as _EMPTY_ARRAY, SubscriptionData as _EffectData, _IMMUTABLE, _SharedContainer, _VAR_PROPS, _deserialize, _fnSignal, _getContextElement, _getContextEvent, getDomContainer as _getDomContainer, _getQContainerElement, isJSXNode as _isJSXNode, isStringifiable as _isStringifiable, _jsxBranch, _jsxC, _jsxQ, _jsxS, _jsxSorted, _jsxSplit, _noopQrl, _noopQrlDEV, _qrlSync, _regSymbol, _restProps, queueQRL as _run, _serialize, scheduleTask as _task, verifySerializable as _verifySerializable, _waitUntilRendered, _walkJSX, _weakSerialize, _wrapProp, _wrapSignal, component$, componentQrl, createComputed$, createComputedQrl, createContextId, h as createElement, createSignal, event$, eventQrl, getDomContainer, getLocale, getPlatform, h, implicit$FirstArg, inlinedQrl, inlinedQrlDEV, isSignal, jsx, jsxDEV, jsx as jsxs, noSerialize, qrl, qrlDEV, render, setPlatform, sync$, untrack, unwrapStore, useComputed$, useComputedQrl, useConstant, useContext, useContextProvider, useErrorBoundary, useId, useLexicalScope, useOn, useOnDocument, useOnWindow, useResource$, useResourceQrl, useServerData, useSignal, useStore, useStyles$, useStylesQrl, useStylesScoped$, useStylesScopedQrl, useTask$, useTaskQrl, useVisibleTask$, useVisibleTaskQrl, version, withLocale };