@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
@@ -552,6 +552,10 @@ declare interface Container {
552
552
  nodeType: number;
553
553
  id: string;
554
554
  };
555
+ } | null, DomRefConstructor: {
556
+ new (...rest: any[]): {
557
+ id: string;
558
+ };
555
559
  } | null, symbolToChunkResolver: SymbolToChunkResolver, writer?: StreamWriter): SerializationContext;
556
560
  }
557
561
 
@@ -800,7 +804,7 @@ export declare const createSignal: {
800
804
  };
801
805
 
802
806
  /** @public */
803
- declare interface CSSProperties extends CSS_2.Properties<string | number>, CSS_2.PropertiesHyphen<string | number> {
807
+ export declare interface CSSProperties extends CSS_2.Properties<string | number>, CSS_2.PropertiesHyphen<string | number> {
804
808
  /**
805
809
  * The index signature was removed to enable closed typing for style using CSSType. You're able to
806
810
  * use type assertion or module augmentation to add properties or an index signature of your own.
@@ -885,6 +889,10 @@ declare class DomContainer extends _SharedContainer implements ClientContainer {
885
889
  export { DomContainer }
886
890
  export { DomContainer as _DomContainer }
887
891
 
892
+ declare type DomRef = {
893
+ id: string;
894
+ };
895
+
888
896
  /** @public */
889
897
  export declare type EagernessOptions = 'visible' | 'load' | 'idle';
890
898
 
@@ -2278,6 +2286,7 @@ declare interface SerializationContext {
2278
2286
  $addSyncFn$($funcStr$: string | null, argsCount: number, fn: Function): number;
2279
2287
  $breakCircularDepsAndAwaitPromises$: () => ValueOrPromise<void>;
2280
2288
  $isSsrNode$: (obj: unknown) => obj is SsrNode;
2289
+ $isDomRef$: (obj: unknown) => obj is DomRef;
2281
2290
  $writer$: StreamWriter_2;
2282
2291
  $syncFns$: string[];
2283
2292
  $eventQrls$: Set<QRL>;
@@ -2327,6 +2336,10 @@ export declare abstract class _SharedContainer implements Container {
2327
2336
  nodeType: number;
2328
2337
  id: string;
2329
2338
  };
2339
+ } | null, DomRefConstructor: {
2340
+ new (...rest: any[]): {
2341
+ id: string;
2342
+ };
2330
2343
  } | null, symbolToChunkResolver: SymbolToChunkResolver, writer?: StreamWriter, prepVNodeData?: (vNode: any) => void): SerializationContext;
2331
2344
  abstract ensureProjectionResolved(host: HostElement): void;
2332
2345
  abstract processJsx(host: HostElement, jsx: JSXOutput): ValueOrPromise<void>;
@@ -3708,7 +3721,7 @@ export declare const _VAR_PROPS: unique symbol;
3708
3721
  export declare const _verifySerializable: <T>(value: T, preMessage?: string) => T;
3709
3722
 
3710
3723
  /**
3711
- * 2.0.0-alpha.0-dev+dd93926
3724
+ * 2.0.0-alpha.2-dev+58b6f8d
3712
3725
  *
3713
3726
  * @public
3714
3727
  */
package/dist/core.cjs 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
@@ -1267,6 +1267,12 @@
1267
1267
  return subscriptionRemoved;
1268
1268
  }
1269
1269
 
1270
+ /**
1271
+ * Special value used to mark that a given signal needs to be computed. This is essentially a
1272
+ * "marked as dirty" flag.
1273
+ */
1274
+ const NEEDS_COMPUTATION = Symbol('invalid');
1275
+
1270
1276
  /**
1271
1277
  * @file
1272
1278
  *
@@ -1281,11 +1287,6 @@
1281
1287
  * - It is `Readonly` because it is computed.
1282
1288
  */
1283
1289
  const DEBUG = false;
1284
- /**
1285
- * Special value used to mark that a given signal needs to be computed. This is essentially a
1286
- * "marked as dirty" flag.
1287
- */
1288
- const NEEDS_COMPUTATION = Symbol('invalid');
1289
1290
  // eslint-disable-next-line no-console
1290
1291
  const log = (...args) => console.log('SIGNAL', ...args.map(qwikDebugToString));
1291
1292
  const throwIfQRLNotResolved = (qrl) => {
@@ -2179,6 +2180,15 @@
2179
2180
  if (prop === STORE_TARGET) {
2180
2181
  return true;
2181
2182
  }
2183
+ if (typeof prop === 'string') {
2184
+ const ctx = tryGetInvokeContext();
2185
+ if (ctx) {
2186
+ const effectSubscriber = ctx.$effectSubscriber$;
2187
+ if (effectSubscriber) {
2188
+ addEffect(target, Array.isArray(target) ? STORE_ARRAY_PROP : prop, this, effectSubscriber);
2189
+ }
2190
+ }
2191
+ }
2182
2192
  return Object.prototype.hasOwnProperty.call(target, prop);
2183
2193
  }
2184
2194
  ownKeys(target) {
@@ -2796,6 +2806,7 @@
2796
2806
  iCtx.$container$ = container;
2797
2807
  let componentFn;
2798
2808
  container.ensureProjectionResolved(renderHost);
2809
+ let isInlineComponent = false;
2799
2810
  if (componentQRL === null) {
2800
2811
  componentQRL = componentQRL || container.getHostProp(renderHost, OnRenderProp);
2801
2812
  assertDefined(componentQRL, 'No Component found at this location');
@@ -2812,13 +2823,18 @@
2812
2823
  componentFn = () => invokeApply(iCtx, qComponentFn, [props || EMPTY_OBJ, null, 0]);
2813
2824
  }
2814
2825
  else {
2826
+ isInlineComponent = true;
2815
2827
  const inlineComponent = componentQRL;
2816
2828
  componentFn = () => invokeApply(iCtx, inlineComponent, [props || EMPTY_OBJ]);
2817
2829
  }
2818
2830
  const executeComponentWithPromiseExceptionRetry = (retryCount = 0) => safeCall(() => {
2819
- container.setHostProp(renderHost, ELEMENT_SEQ_IDX, null);
2820
- container.setHostProp(renderHost, USE_ON_LOCAL_SEQ_IDX, null);
2821
- container.setHostProp(renderHost, ELEMENT_PROPS, props);
2831
+ if (!isInlineComponent) {
2832
+ container.setHostProp(renderHost, ELEMENT_SEQ_IDX, null);
2833
+ container.setHostProp(renderHost, USE_ON_LOCAL_SEQ_IDX, null);
2834
+ if (container.getHostProp(renderHost, ELEMENT_PROPS) !== props) {
2835
+ container.setHostProp(renderHost, ELEMENT_PROPS, props);
2836
+ }
2837
+ }
2822
2838
  if (vnode_isVNode(renderHost)) {
2823
2839
  clearVNodeEffectDependencies(renderHost);
2824
2840
  }
@@ -4450,7 +4466,10 @@
4450
4466
  // On server we can't schedule task for a different host!
4451
4467
  // Server is SSR, and therefore scheduling for anything but the current host
4452
4468
  // implies that things need to be re-run nad that is not supported because of streaming.
4453
- const errorMessage = 'SERVER: during HTML streaming, it is not possible to cause a re-run of tasks on a different host';
4469
+ const errorMessage = `SERVER: during HTML streaming, re-running tasks on a different host is not allowed.
4470
+ You are attempting to change a state that has already been streamed to the client.
4471
+ This can lead to inconsistencies between Server-Side Rendering (SSR) and Client-Side Rendering (CSR).
4472
+ Problematic Node: ${aHost.toString()}`;
4454
4473
  if (shouldThrowOnHostMismatch) {
4455
4474
  throwErrorAndStop(errorMessage);
4456
4475
  }
@@ -4517,7 +4536,7 @@
4517
4536
  *
4518
4537
  * @public
4519
4538
  */
4520
- const version = "2.0.0-alpha.0-dev+dd93926";
4539
+ const version = "2.0.0-alpha.2-dev+58b6f8d";
4521
4540
 
4522
4541
  /** @internal */
4523
4542
  class _SharedContainer {
@@ -4544,8 +4563,8 @@
4544
4563
  trackSignalValue(signal, subscriber, property, data) {
4545
4564
  return trackSignal(() => signal.value, subscriber, property, this, data);
4546
4565
  }
4547
- serializationCtxFactory(NodeConstructor, symbolToChunkResolver, writer, prepVNodeData) {
4548
- return createSerializationContext(NodeConstructor, symbolToChunkResolver, this.getHostProp.bind(this), this.setHostProp.bind(this), this.$storeProxyMap$, writer, prepVNodeData);
4566
+ serializationCtxFactory(NodeConstructor, DomRefConstructor, symbolToChunkResolver, writer, prepVNodeData) {
4567
+ return createSerializationContext(NodeConstructor, DomRefConstructor, symbolToChunkResolver, this.getHostProp.bind(this), this.setHostProp.bind(this), this.$storeProxyMap$, writer, prepVNodeData);
4549
4568
  }
4550
4569
  }
4551
4570
 
@@ -8375,13 +8394,6 @@
8375
8394
  }
8376
8395
  return qrl;
8377
8396
  }
8378
- /** A ref to a DOM element */
8379
- class DomVRef {
8380
- id;
8381
- constructor(id) {
8382
- this.id = id;
8383
- }
8384
- }
8385
8397
  const createSerializationContext = (
8386
8398
  /**
8387
8399
  * Node constructor, for instanceof checks.
@@ -8389,7 +8401,9 @@
8389
8401
  * A node constructor can be null. For example on the client we can't serialize DOM nodes as
8390
8402
  * server will not know what to do with them.
8391
8403
  */
8392
- NodeConstructor, symbolToChunkResolver, getProp, setProp, storeProxyMap, writer,
8404
+ NodeConstructor,
8405
+ /** DomRef constructor, for instanceof checks. */
8406
+ DomRefConstructor, symbolToChunkResolver, getProp, setProp, storeProxyMap, writer,
8393
8407
  // temporary until we serdes the vnode data here
8394
8408
  prepVNodeData) => {
8395
8409
  if (!writer) {
@@ -8415,11 +8429,13 @@
8415
8429
  return id;
8416
8430
  };
8417
8431
  const isSsrNode = (NodeConstructor ? (obj) => obj instanceof NodeConstructor : () => false);
8432
+ const isDomRef = (DomRefConstructor ? (obj) => obj instanceof DomRefConstructor : () => false);
8418
8433
  return {
8419
8434
  $serialize$() {
8420
8435
  serialize(this);
8421
8436
  },
8422
8437
  $isSsrNode$: isSsrNode,
8438
+ $isDomRef$: isDomRef,
8423
8439
  $symbolToChunkResolver$: symbolToChunkResolver,
8424
8440
  $wasSeen$,
8425
8441
  $roots$: roots,
@@ -8565,6 +8581,9 @@
8565
8581
  else if (isSsrNode(obj)) {
8566
8582
  discoveredValues.push(obj.vnodeData);
8567
8583
  }
8584
+ else if (isDomRef(obj)) {
8585
+ discoveredValues.push(obj.id);
8586
+ }
8568
8587
  else if (isJSXNode(obj)) {
8569
8588
  discoveredValues.push(obj.type, obj.props, obj.constProps, obj.children);
8570
8589
  }
@@ -8638,7 +8657,7 @@
8638
8657
  * - Therefore root indexes need to be doubled to get the actual index.
8639
8658
  */
8640
8659
  function serialize(serializationContext) {
8641
- const { $writer$, $isSsrNode$, $setProp$, $storeProxyMap$ } = serializationContext;
8660
+ const { $writer$, $isSsrNode$, $isDomRef$, $setProp$, $storeProxyMap$ } = serializationContext;
8642
8661
  let depth = -1;
8643
8662
  // Skip the type for the roots output
8644
8663
  let writeType = false;
@@ -8860,7 +8879,7 @@
8860
8879
  output(TypeIds.Object, out);
8861
8880
  }
8862
8881
  }
8863
- else if (value instanceof DomVRef) {
8882
+ else if ($isDomRef$(value)) {
8864
8883
  output(TypeIds.RefVNode, value.id);
8865
8884
  }
8866
8885
  else if (value instanceof Signal) {
@@ -8868,15 +8887,10 @@
8868
8887
  * Special case: when a Signal value is an SSRNode, it always needs to be a DOM ref instead.
8869
8888
  * It can never be meant to become a vNode, because vNodes are internal only.
8870
8889
  */
8871
- let v = value instanceof ComputedSignal &&
8890
+ const v = value instanceof ComputedSignal &&
8872
8891
  (value.$invalid$ || fastSkipSerialize(value.$untrackedValue$))
8873
8892
  ? NEEDS_COMPUTATION
8874
8893
  : value.$untrackedValue$;
8875
- if ($isSsrNode$(v)) {
8876
- // TODO maybe we don't need to store all vnode data if it's only a ref
8877
- serializationContext.$addRoot$(v);
8878
- v = new DomVRef(v.id);
8879
- }
8880
8894
  if (value instanceof WrappedSignal) {
8881
8895
  output(TypeIds.WrappedSignal, [
8882
8896
  ...serializeWrappingFn(serializationContext, value),
@@ -9093,7 +9107,7 @@
9093
9107
  * @internal
9094
9108
  */
9095
9109
  async function _serialize(data) {
9096
- const serializationContext = createSerializationContext(null, () => '', () => '', () => { }, new WeakMap());
9110
+ const serializationContext = createSerializationContext(null, null, () => '', () => '', () => { }, new WeakMap());
9097
9111
  for (const root of data) {
9098
9112
  serializationContext.$addRoot$(root);
9099
9113
  }
@@ -9488,8 +9502,8 @@
9488
9502
  }
9489
9503
  let _containerEl;
9490
9504
  const qrl = async function (...args) {
9491
- const fn = invokeFn.call(this, tryGetInvokeContext());
9492
- const result = await fn(...args);
9505
+ const boundedFn = bindFnToContext.call(this, tryGetInvokeContext());
9506
+ const result = await boundedFn(...args);
9493
9507
  return result;
9494
9508
  };
9495
9509
  const setContainer = (el) => {
@@ -9498,6 +9512,34 @@
9498
9512
  }
9499
9513
  return _containerEl;
9500
9514
  };
9515
+ function bindFnToContext(currentCtx, beforeFn) {
9516
+ // Note that we bind the current `this`
9517
+ return (...args) => maybeThen(resolveLazy(), (fn) => {
9518
+ if (!isFunction(fn)) {
9519
+ throw qError(QError_qrlIsNotFunction);
9520
+ }
9521
+ if (beforeFn && beforeFn() === false) {
9522
+ return;
9523
+ }
9524
+ const context = createOrReuseInvocationContext(currentCtx);
9525
+ const prevQrl = context.$qrl$;
9526
+ const prevEvent = context.$event$;
9527
+ // Note that we set the qrl here instead of in wrapFn because
9528
+ // it is possible we're called on a copied qrl
9529
+ context.$qrl$ = qrl;
9530
+ context.$event$ ||= this;
9531
+ try {
9532
+ return invoke.call(this, context, fn, ...args);
9533
+ }
9534
+ finally {
9535
+ context.$qrl$ = prevQrl;
9536
+ context.$event$ = prevEvent;
9537
+ }
9538
+ });
9539
+ }
9540
+ const resolveLazy = (containerEl) => {
9541
+ return symbolRef !== null ? symbolRef : resolve(containerEl);
9542
+ };
9501
9543
  // Wrap functions to provide their lexical scope
9502
9544
  const wrapFn = (fn) => {
9503
9545
  if (typeof fn !== 'function' || (!capture?.length && !captureRef?.length)) {
@@ -9550,34 +9592,6 @@
9550
9592
  }
9551
9593
  return symbolRef;
9552
9594
  };
9553
- const resolveLazy = (containerEl) => {
9554
- return symbolRef !== null ? symbolRef : resolve(containerEl);
9555
- };
9556
- function invokeFn(currentCtx, beforeFn) {
9557
- // Note that we bind the current `this`
9558
- return (...args) => maybeThen(resolveLazy(), (f) => {
9559
- if (!isFunction(f)) {
9560
- throw qError(QError_qrlIsNotFunction);
9561
- }
9562
- if (beforeFn && beforeFn() === false) {
9563
- return;
9564
- }
9565
- const context = createOrReuseInvocationContext(currentCtx);
9566
- const prevQrl = context.$qrl$;
9567
- const prevEvent = context.$event$;
9568
- // Note that we set the qrl here instead of in wrapFn because
9569
- // it is possible we're called on a copied qrl
9570
- context.$qrl$ = qrl;
9571
- context.$event$ ||= this;
9572
- try {
9573
- return invoke.call(this, context, f, ...args);
9574
- }
9575
- finally {
9576
- context.$qrl$ = prevQrl;
9577
- context.$event$ = prevEvent;
9578
- }
9579
- });
9580
- }
9581
9595
  const createOrReuseInvocationContext = (invoke) => {
9582
9596
  if (invoke == null) {
9583
9597
  return newInvokeContext();
@@ -9602,7 +9616,7 @@
9602
9616
  $symbol$: symbol,
9603
9617
  $refSymbol$: refSymbol,
9604
9618
  $hash$: hash,
9605
- getFn: invokeFn,
9619
+ getFn: bindFnToContext,
9606
9620
  $capture$: capture,
9607
9621
  $captureRef$: captureRef,
9608
9622
  dev: null,