@qwik.dev/core 2.0.0-alpha.0 → 2.0.0-alpha.2

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 (38) 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 +1384 -761
  8. package/dist/core-internal.d.ts +15 -2
  9. package/dist/core.cjs +75 -61
  10. package/dist/core.cjs.map +1 -1
  11. package/dist/core.min.mjs +1 -1
  12. package/dist/core.mjs +75 -61
  13. package/dist/core.mjs.map +1 -1
  14. package/dist/core.prod.cjs +56 -46
  15. package/dist/core.prod.mjs +58 -49
  16. package/dist/insights/index.qwik.cjs +1 -1
  17. package/dist/insights/index.qwik.mjs +1 -1
  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 +57 -60
  22. package/dist/optimizer.mjs +59 -63
  23. package/dist/prefetch/package.json +1 -1
  24. package/dist/qwikloader.debug.js +1 -0
  25. package/dist/qwikloader.js +2 -2
  26. package/dist/server.cjs +81 -53
  27. package/dist/server.mjs +81 -53
  28. package/dist/starters/features/auth/package.json +3 -1
  29. package/dist/starters/features/drizzle/package.json +2 -1
  30. package/dist/starters/features/postcss/package.json +3 -0
  31. package/dist/starters/features/prisma/package.json +2 -1
  32. package/dist/starters/features/tailwind/package.json +3 -0
  33. package/dist/starters/features/turso/package.json +4 -1
  34. package/dist/testing/index.cjs +77 -49
  35. package/dist/testing/index.mjs +77 -49
  36. package/dist/testing/package.json +1 -1
  37. package/package.json +13 -11
  38. package/public.d.ts +2 -0
package/dist/core.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * @qwik.dev/core 2.0.0-alpha.0-dev+dd93926
3
+ * @qwik.dev/core 2.0.0-alpha.2-dev+58b6f8d
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
@@ -1264,6 +1264,12 @@ function clearEffects(subscriber, value) {
1264
1264
  return subscriptionRemoved;
1265
1265
  }
1266
1266
 
1267
+ /**
1268
+ * Special value used to mark that a given signal needs to be computed. This is essentially a
1269
+ * "marked as dirty" flag.
1270
+ */
1271
+ const NEEDS_COMPUTATION = Symbol('invalid');
1272
+
1267
1273
  /**
1268
1274
  * @file
1269
1275
  *
@@ -1278,11 +1284,6 @@ function clearEffects(subscriber, value) {
1278
1284
  * - It is `Readonly` because it is computed.
1279
1285
  */
1280
1286
  const DEBUG = false;
1281
- /**
1282
- * Special value used to mark that a given signal needs to be computed. This is essentially a
1283
- * "marked as dirty" flag.
1284
- */
1285
- const NEEDS_COMPUTATION = Symbol('invalid');
1286
1287
  // eslint-disable-next-line no-console
1287
1288
  const log = (...args) => console.log('SIGNAL', ...args.map(qwikDebugToString));
1288
1289
  const throwIfQRLNotResolved = (qrl) => {
@@ -2176,6 +2177,15 @@ class StoreHandler {
2176
2177
  if (prop === STORE_TARGET) {
2177
2178
  return true;
2178
2179
  }
2180
+ if (typeof prop === 'string') {
2181
+ const ctx = tryGetInvokeContext();
2182
+ if (ctx) {
2183
+ const effectSubscriber = ctx.$effectSubscriber$;
2184
+ if (effectSubscriber) {
2185
+ addEffect(target, Array.isArray(target) ? STORE_ARRAY_PROP : prop, this, effectSubscriber);
2186
+ }
2187
+ }
2188
+ }
2179
2189
  return Object.prototype.hasOwnProperty.call(target, prop);
2180
2190
  }
2181
2191
  ownKeys(target) {
@@ -2793,6 +2803,7 @@ const executeComponent = (container, renderHost, subscriptionHost, componentQRL,
2793
2803
  iCtx.$container$ = container;
2794
2804
  let componentFn;
2795
2805
  container.ensureProjectionResolved(renderHost);
2806
+ let isInlineComponent = false;
2796
2807
  if (componentQRL === null) {
2797
2808
  componentQRL = componentQRL || container.getHostProp(renderHost, OnRenderProp);
2798
2809
  assertDefined(componentQRL, 'No Component found at this location');
@@ -2809,13 +2820,18 @@ const executeComponent = (container, renderHost, subscriptionHost, componentQRL,
2809
2820
  componentFn = () => invokeApply(iCtx, qComponentFn, [props || EMPTY_OBJ, null, 0]);
2810
2821
  }
2811
2822
  else {
2823
+ isInlineComponent = true;
2812
2824
  const inlineComponent = componentQRL;
2813
2825
  componentFn = () => invokeApply(iCtx, inlineComponent, [props || EMPTY_OBJ]);
2814
2826
  }
2815
2827
  const executeComponentWithPromiseExceptionRetry = (retryCount = 0) => safeCall(() => {
2816
- container.setHostProp(renderHost, ELEMENT_SEQ_IDX, null);
2817
- container.setHostProp(renderHost, USE_ON_LOCAL_SEQ_IDX, null);
2818
- container.setHostProp(renderHost, ELEMENT_PROPS, props);
2828
+ if (!isInlineComponent) {
2829
+ container.setHostProp(renderHost, ELEMENT_SEQ_IDX, null);
2830
+ container.setHostProp(renderHost, USE_ON_LOCAL_SEQ_IDX, null);
2831
+ if (container.getHostProp(renderHost, ELEMENT_PROPS) !== props) {
2832
+ container.setHostProp(renderHost, ELEMENT_PROPS, props);
2833
+ }
2834
+ }
2819
2835
  if (vnode_isVNode(renderHost)) {
2820
2836
  clearVNodeEffectDependencies(renderHost);
2821
2837
  }
@@ -4447,7 +4463,10 @@ function choreComparator(a, b, shouldThrowOnHostMismatch) {
4447
4463
  // On server we can't schedule task for a different host!
4448
4464
  // Server is SSR, and therefore scheduling for anything but the current host
4449
4465
  // implies that things need to be re-run nad that is not supported because of streaming.
4450
- const errorMessage = 'SERVER: during HTML streaming, it is not possible to cause a re-run of tasks on a different host';
4466
+ const errorMessage = `SERVER: during HTML streaming, re-running tasks on a different host is not allowed.
4467
+ You are attempting to change a state that has already been streamed to the client.
4468
+ This can lead to inconsistencies between Server-Side Rendering (SSR) and Client-Side Rendering (CSR).
4469
+ Problematic Node: ${aHost.toString()}`;
4451
4470
  if (shouldThrowOnHostMismatch) {
4452
4471
  throwErrorAndStop(errorMessage);
4453
4472
  }
@@ -4514,7 +4533,7 @@ function sortedInsert(sortedArray, value) {
4514
4533
  *
4515
4534
  * @public
4516
4535
  */
4517
- const version = "2.0.0-alpha.0-dev+dd93926";
4536
+ const version = "2.0.0-alpha.2-dev+58b6f8d";
4518
4537
 
4519
4538
  /** @internal */
4520
4539
  class _SharedContainer {
@@ -4541,8 +4560,8 @@ class _SharedContainer {
4541
4560
  trackSignalValue(signal, subscriber, property, data) {
4542
4561
  return trackSignal(() => signal.value, subscriber, property, this, data);
4543
4562
  }
4544
- serializationCtxFactory(NodeConstructor, symbolToChunkResolver, writer, prepVNodeData) {
4545
- return createSerializationContext(NodeConstructor, symbolToChunkResolver, this.getHostProp.bind(this), this.setHostProp.bind(this), this.$storeProxyMap$, writer, prepVNodeData);
4563
+ serializationCtxFactory(NodeConstructor, DomRefConstructor, symbolToChunkResolver, writer, prepVNodeData) {
4564
+ return createSerializationContext(NodeConstructor, DomRefConstructor, symbolToChunkResolver, this.getHostProp.bind(this), this.setHostProp.bind(this), this.$storeProxyMap$, writer, prepVNodeData);
4546
4565
  }
4547
4566
  }
4548
4567
 
@@ -8372,13 +8391,6 @@ function inflateQRL(container, qrl) {
8372
8391
  }
8373
8392
  return qrl;
8374
8393
  }
8375
- /** A ref to a DOM element */
8376
- class DomVRef {
8377
- id;
8378
- constructor(id) {
8379
- this.id = id;
8380
- }
8381
- }
8382
8394
  const createSerializationContext = (
8383
8395
  /**
8384
8396
  * Node constructor, for instanceof checks.
@@ -8386,7 +8398,9 @@ const createSerializationContext = (
8386
8398
  * A node constructor can be null. For example on the client we can't serialize DOM nodes as
8387
8399
  * server will not know what to do with them.
8388
8400
  */
8389
- NodeConstructor, symbolToChunkResolver, getProp, setProp, storeProxyMap, writer,
8401
+ NodeConstructor,
8402
+ /** DomRef constructor, for instanceof checks. */
8403
+ DomRefConstructor, symbolToChunkResolver, getProp, setProp, storeProxyMap, writer,
8390
8404
  // temporary until we serdes the vnode data here
8391
8405
  prepVNodeData) => {
8392
8406
  if (!writer) {
@@ -8412,11 +8426,13 @@ prepVNodeData) => {
8412
8426
  return id;
8413
8427
  };
8414
8428
  const isSsrNode = (NodeConstructor ? (obj) => obj instanceof NodeConstructor : () => false);
8429
+ const isDomRef = (DomRefConstructor ? (obj) => obj instanceof DomRefConstructor : () => false);
8415
8430
  return {
8416
8431
  $serialize$() {
8417
8432
  serialize(this);
8418
8433
  },
8419
8434
  $isSsrNode$: isSsrNode,
8435
+ $isDomRef$: isDomRef,
8420
8436
  $symbolToChunkResolver$: symbolToChunkResolver,
8421
8437
  $wasSeen$,
8422
8438
  $roots$: roots,
@@ -8562,6 +8578,9 @@ prepVNodeData) => {
8562
8578
  else if (isSsrNode(obj)) {
8563
8579
  discoveredValues.push(obj.vnodeData);
8564
8580
  }
8581
+ else if (isDomRef(obj)) {
8582
+ discoveredValues.push(obj.id);
8583
+ }
8565
8584
  else if (isJSXNode(obj)) {
8566
8585
  discoveredValues.push(obj.type, obj.props, obj.constProps, obj.children);
8567
8586
  }
@@ -8635,7 +8654,7 @@ const promiseResults = new WeakMap();
8635
8654
  * - Therefore root indexes need to be doubled to get the actual index.
8636
8655
  */
8637
8656
  function serialize(serializationContext) {
8638
- const { $writer$, $isSsrNode$, $setProp$, $storeProxyMap$ } = serializationContext;
8657
+ const { $writer$, $isSsrNode$, $isDomRef$, $setProp$, $storeProxyMap$ } = serializationContext;
8639
8658
  let depth = -1;
8640
8659
  // Skip the type for the roots output
8641
8660
  let writeType = false;
@@ -8857,7 +8876,7 @@ function serialize(serializationContext) {
8857
8876
  output(TypeIds.Object, out);
8858
8877
  }
8859
8878
  }
8860
- else if (value instanceof DomVRef) {
8879
+ else if ($isDomRef$(value)) {
8861
8880
  output(TypeIds.RefVNode, value.id);
8862
8881
  }
8863
8882
  else if (value instanceof Signal) {
@@ -8865,15 +8884,10 @@ function serialize(serializationContext) {
8865
8884
  * Special case: when a Signal value is an SSRNode, it always needs to be a DOM ref instead.
8866
8885
  * It can never be meant to become a vNode, because vNodes are internal only.
8867
8886
  */
8868
- let v = value instanceof ComputedSignal &&
8887
+ const v = value instanceof ComputedSignal &&
8869
8888
  (value.$invalid$ || fastSkipSerialize(value.$untrackedValue$))
8870
8889
  ? NEEDS_COMPUTATION
8871
8890
  : value.$untrackedValue$;
8872
- if ($isSsrNode$(v)) {
8873
- // TODO maybe we don't need to store all vnode data if it's only a ref
8874
- serializationContext.$addRoot$(v);
8875
- v = new DomVRef(v.id);
8876
- }
8877
8891
  if (value instanceof WrappedSignal) {
8878
8892
  output(TypeIds.WrappedSignal, [
8879
8893
  ...serializeWrappingFn(serializationContext, value),
@@ -9090,7 +9104,7 @@ function qrlToString(serializationContext, value) {
9090
9104
  * @internal
9091
9105
  */
9092
9106
  async function _serialize(data) {
9093
- const serializationContext = createSerializationContext(null, () => '', () => '', () => { }, new WeakMap());
9107
+ const serializationContext = createSerializationContext(null, null, () => '', () => '', () => { }, new WeakMap());
9094
9108
  for (const root of data) {
9095
9109
  serializationContext.$addRoot$(root);
9096
9110
  }
@@ -9485,8 +9499,8 @@ const createQRL = (chunk, symbol, symbolRef, symbolFn, capture, captureRef, refS
9485
9499
  }
9486
9500
  let _containerEl;
9487
9501
  const qrl = async function (...args) {
9488
- const fn = invokeFn.call(this, tryGetInvokeContext());
9489
- const result = await fn(...args);
9502
+ const boundedFn = bindFnToContext.call(this, tryGetInvokeContext());
9503
+ const result = await boundedFn(...args);
9490
9504
  return result;
9491
9505
  };
9492
9506
  const setContainer = (el) => {
@@ -9495,6 +9509,34 @@ const createQRL = (chunk, symbol, symbolRef, symbolFn, capture, captureRef, refS
9495
9509
  }
9496
9510
  return _containerEl;
9497
9511
  };
9512
+ function bindFnToContext(currentCtx, beforeFn) {
9513
+ // Note that we bind the current `this`
9514
+ return (...args) => maybeThen(resolveLazy(), (fn) => {
9515
+ if (!isFunction(fn)) {
9516
+ throw qError(QError_qrlIsNotFunction);
9517
+ }
9518
+ if (beforeFn && beforeFn() === false) {
9519
+ return;
9520
+ }
9521
+ const context = createOrReuseInvocationContext(currentCtx);
9522
+ const prevQrl = context.$qrl$;
9523
+ const prevEvent = context.$event$;
9524
+ // Note that we set the qrl here instead of in wrapFn because
9525
+ // it is possible we're called on a copied qrl
9526
+ context.$qrl$ = qrl;
9527
+ context.$event$ ||= this;
9528
+ try {
9529
+ return invoke.call(this, context, fn, ...args);
9530
+ }
9531
+ finally {
9532
+ context.$qrl$ = prevQrl;
9533
+ context.$event$ = prevEvent;
9534
+ }
9535
+ });
9536
+ }
9537
+ const resolveLazy = (containerEl) => {
9538
+ return symbolRef !== null ? symbolRef : resolve(containerEl);
9539
+ };
9498
9540
  // Wrap functions to provide their lexical scope
9499
9541
  const wrapFn = (fn) => {
9500
9542
  if (typeof fn !== 'function' || (!capture?.length && !captureRef?.length)) {
@@ -9547,34 +9589,6 @@ const createQRL = (chunk, symbol, symbolRef, symbolFn, capture, captureRef, refS
9547
9589
  }
9548
9590
  return symbolRef;
9549
9591
  };
9550
- const resolveLazy = (containerEl) => {
9551
- return symbolRef !== null ? symbolRef : resolve(containerEl);
9552
- };
9553
- function invokeFn(currentCtx, beforeFn) {
9554
- // Note that we bind the current `this`
9555
- return (...args) => maybeThen(resolveLazy(), (f) => {
9556
- if (!isFunction(f)) {
9557
- throw qError(QError_qrlIsNotFunction);
9558
- }
9559
- if (beforeFn && beforeFn() === false) {
9560
- return;
9561
- }
9562
- const context = createOrReuseInvocationContext(currentCtx);
9563
- const prevQrl = context.$qrl$;
9564
- const prevEvent = context.$event$;
9565
- // Note that we set the qrl here instead of in wrapFn because
9566
- // it is possible we're called on a copied qrl
9567
- context.$qrl$ = qrl;
9568
- context.$event$ ||= this;
9569
- try {
9570
- return invoke.call(this, context, f, ...args);
9571
- }
9572
- finally {
9573
- context.$qrl$ = prevQrl;
9574
- context.$event$ = prevEvent;
9575
- }
9576
- });
9577
- }
9578
9592
  const createOrReuseInvocationContext = (invoke) => {
9579
9593
  if (invoke == null) {
9580
9594
  return newInvokeContext();
@@ -9599,7 +9613,7 @@ const createQRL = (chunk, symbol, symbolRef, symbolFn, capture, captureRef, refS
9599
9613
  $symbol$: symbol,
9600
9614
  $refSymbol$: refSymbol,
9601
9615
  $hash$: hash,
9602
- getFn: invokeFn,
9616
+ getFn: bindFnToContext,
9603
9617
  $capture$: capture,
9604
9618
  $captureRef$: captureRef,
9605
9619
  dev: null,