@qwik.dev/core 2.0.0-alpha.1 → 2.0.0-alpha.3

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 (39) hide show
  1. package/bindings/qwik.darwin-arm64.node +0 -0
  2. package/bindings/qwik.darwin-x64.node +0 -0
  3. package/bindings/qwik.linux-x64-gnu.node +0 -0
  4. package/bindings/qwik.wasm.cjs +259 -272
  5. package/bindings/qwik.wasm.mjs +259 -272
  6. package/bindings/qwik.win32-x64-msvc.node +0 -0
  7. package/bindings/qwik_wasm_bg.wasm +0 -0
  8. package/dist/build/package.json +1 -1
  9. package/dist/cli.cjs +1384 -761
  10. package/dist/core-internal.d.ts +14 -4
  11. package/dist/core.cjs +121 -106
  12. package/dist/core.cjs.map +1 -1
  13. package/dist/core.min.mjs +1 -1
  14. package/dist/core.mjs +121 -106
  15. package/dist/core.mjs.map +1 -1
  16. package/dist/core.prod.cjs +80 -63
  17. package/dist/core.prod.mjs +82 -65
  18. package/dist/insights/index.qwik.cjs +1 -1
  19. package/dist/insights/index.qwik.mjs +1 -1
  20. package/dist/loader/index.cjs +2 -2
  21. package/dist/loader/index.mjs +2 -2
  22. package/dist/loader/package.json +1 -1
  23. package/dist/optimizer.cjs +94 -80
  24. package/dist/optimizer.mjs +96 -82
  25. package/dist/prefetch/package.json +1 -1
  26. package/dist/qwikloader.debug.js +1 -0
  27. package/dist/qwikloader.js +2 -2
  28. package/dist/server.cjs +125 -96
  29. package/dist/server.mjs +125 -96
  30. package/dist/starters/features/auth/package.json +3 -1
  31. package/dist/starters/features/drizzle/package.json +2 -1
  32. package/dist/starters/features/postcss/package.json +3 -0
  33. package/dist/starters/features/prisma/package.json +2 -1
  34. package/dist/starters/features/tailwind/package.json +3 -0
  35. package/dist/starters/features/turso/package.json +4 -1
  36. package/dist/testing/index.cjs +121 -92
  37. package/dist/testing/index.mjs +121 -92
  38. package/dist/testing/package.json +1 -1
  39. package/package.json +6 -4
package/dist/core.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * @qwik.dev/core 2.0.0-alpha.1-dev+10f5414
3
+ * @qwik.dev/core 2.0.0-alpha.3-dev+418fd6d
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) {
@@ -3282,48 +3292,48 @@ const vnode_diff = (container, jsxNode, vStartNode, scopedStyleIdPrefix) => {
3282
3292
  /////////////////////////////////////////////////////////////////////////////
3283
3293
  /////////////////////////////////////////////////////////////////////////////
3284
3294
  function descendContentToProject(children, host) {
3285
- if (!Array.isArray(children)) {
3286
- children = [children];
3287
- }
3288
- if (children.length) {
3289
- const createProjectionJSXNode = (slotName) => {
3290
- return new JSXNodeImpl(Projection, EMPTY_OBJ, null, [], 0, slotName);
3291
- };
3292
- const projections = [];
3293
- if (host) {
3294
- // we need to create empty projections for all the slots to remove unused slots content
3295
- for (let i = vnode_getPropStartIndex(host); i < host.length; i = i + 2) {
3296
- const prop = host[i];
3297
- if (isSlotProp(prop)) {
3298
- const slotName = prop;
3299
- projections.push(slotName);
3300
- projections.push(createProjectionJSXNode(slotName));
3301
- }
3295
+ const projectionChildren = Array.isArray(children) ? children : [children];
3296
+ const createProjectionJSXNode = (slotName) => {
3297
+ return new JSXNodeImpl(Projection, EMPTY_OBJ, null, [], 0, slotName);
3298
+ };
3299
+ const projections = [];
3300
+ if (host) {
3301
+ // we need to create empty projections for all the slots to remove unused slots content
3302
+ for (let i = vnode_getPropStartIndex(host); i < host.length; i = i + 2) {
3303
+ const prop = host[i];
3304
+ if (isSlotProp(prop)) {
3305
+ const slotName = prop;
3306
+ projections.push(slotName);
3307
+ projections.push(createProjectionJSXNode(slotName));
3302
3308
  }
3303
3309
  }
3304
- /// STEP 1: Bucketize the children based on the projection name.
3305
- for (let i = 0; i < children.length; i++) {
3306
- const child = children[i];
3307
- const slotName = String((isJSXNode(child) && directGetPropsProxyProp(child, QSlot)) || QDefaultSlot);
3308
- const idx = mapApp_findIndx(projections, slotName, 0);
3309
- let jsxBucket;
3310
- if (idx >= 0) {
3311
- jsxBucket = projections[idx + 1];
3312
- }
3313
- else {
3314
- projections.splice(~idx, 0, slotName, (jsxBucket = createProjectionJSXNode(slotName)));
3315
- }
3316
- const removeProjection = child === false;
3317
- if (!removeProjection) {
3318
- jsxBucket.children.push(child);
3319
- }
3310
+ }
3311
+ if (projections.length === 0 && children == null) {
3312
+ // We did not find any existing slots and we don't have any children to project.
3313
+ return;
3314
+ }
3315
+ /// STEP 1: Bucketize the children based on the projection name.
3316
+ for (let i = 0; i < projectionChildren.length; i++) {
3317
+ const child = projectionChildren[i];
3318
+ const slotName = String((isJSXNode(child) && directGetPropsProxyProp(child, QSlot)) || QDefaultSlot);
3319
+ const idx = mapApp_findIndx(projections, slotName, 0);
3320
+ let jsxBucket;
3321
+ if (idx >= 0) {
3322
+ jsxBucket = projections[idx + 1];
3320
3323
  }
3321
- /// STEP 2: remove the names
3322
- for (let i = projections.length - 2; i >= 0; i = i - 2) {
3323
- projections.splice(i, 1);
3324
+ else {
3325
+ projections.splice(~idx, 0, slotName, (jsxBucket = createProjectionJSXNode(slotName)));
3324
3326
  }
3325
- descend(projections, true);
3327
+ const removeProjection = child === false;
3328
+ if (!removeProjection) {
3329
+ jsxBucket.children.push(child);
3330
+ }
3331
+ }
3332
+ /// STEP 2: remove the names
3333
+ for (let i = projections.length - 2; i >= 0; i = i - 2) {
3334
+ projections.splice(i, 1);
3326
3335
  }
3336
+ descend(projections, true);
3327
3337
  }
3328
3338
  function expectProjection() {
3329
3339
  const jsxNode = jsxValue;
@@ -3845,7 +3855,7 @@ const vnode_diff = (container, jsxNode, vStartNode, scopedStyleIdPrefix) => {
3845
3855
  container.$scheduler$(ChoreType.COMPONENT, host, componentQRL, jsxProps);
3846
3856
  }
3847
3857
  }
3848
- jsxNode.children != null && descendContentToProject(jsxNode.children, host);
3858
+ descendContentToProject(jsxNode.children, host);
3849
3859
  }
3850
3860
  else {
3851
3861
  const lookupKey = jsxNode.key;
@@ -4346,9 +4356,13 @@ const createScheduler = (container, scheduleDrain, journalFlush) => {
4346
4356
  case ChoreType.COMPONENT:
4347
4357
  case ChoreType.COMPONENT_SSR:
4348
4358
  returnValue = safeCall(() => executeComponent(container, host, host, chore.$target$, chore.$payload$), (jsx) => {
4349
- return chore.$type$ === ChoreType.COMPONENT
4350
- ? maybeThen(container.processJsx(host, jsx), () => jsx)
4351
- : jsx;
4359
+ if (chore.$type$ === ChoreType.COMPONENT) {
4360
+ const styleScopedId = container.getHostProp(host, QScopedStyle);
4361
+ return vnode_diff(container, jsx, host, addComponentStylePrefix(styleScopedId));
4362
+ }
4363
+ else {
4364
+ return jsx;
4365
+ }
4352
4366
  }, (err) => container.handleError(err, host));
4353
4367
  break;
4354
4368
  case ChoreType.RESOURCE:
@@ -4453,7 +4467,10 @@ function choreComparator(a, b, shouldThrowOnHostMismatch) {
4453
4467
  // On server we can't schedule task for a different host!
4454
4468
  // Server is SSR, and therefore scheduling for anything but the current host
4455
4469
  // implies that things need to be re-run nad that is not supported because of streaming.
4456
- const errorMessage = 'SERVER: during HTML streaming, it is not possible to cause a re-run of tasks on a different host';
4470
+ const errorMessage = `SERVER: during HTML streaming, re-running tasks on a different host is not allowed.
4471
+ You are attempting to change a state that has already been streamed to the client.
4472
+ This can lead to inconsistencies between Server-Side Rendering (SSR) and Client-Side Rendering (CSR).
4473
+ Problematic Node: ${aHost.toString()}`;
4457
4474
  if (shouldThrowOnHostMismatch) {
4458
4475
  throwErrorAndStop(errorMessage);
4459
4476
  }
@@ -4520,7 +4537,7 @@ function sortedInsert(sortedArray, value) {
4520
4537
  *
4521
4538
  * @public
4522
4539
  */
4523
- const version = "2.0.0-alpha.1-dev+10f5414";
4540
+ const version = "2.0.0-alpha.3-dev+418fd6d";
4524
4541
 
4525
4542
  /** @internal */
4526
4543
  class _SharedContainer {
@@ -4547,8 +4564,8 @@ class _SharedContainer {
4547
4564
  trackSignalValue(signal, subscriber, property, data) {
4548
4565
  return trackSignal(() => signal.value, subscriber, property, this, data);
4549
4566
  }
4550
- serializationCtxFactory(NodeConstructor, symbolToChunkResolver, writer, prepVNodeData) {
4551
- return createSerializationContext(NodeConstructor, symbolToChunkResolver, this.getHostProp.bind(this), this.setHostProp.bind(this), this.$storeProxyMap$, writer, prepVNodeData);
4567
+ serializationCtxFactory(NodeConstructor, DomRefConstructor, symbolToChunkResolver, writer, prepVNodeData) {
4568
+ return createSerializationContext(NodeConstructor, DomRefConstructor, symbolToChunkResolver, this.getHostProp.bind(this), this.setHostProp.bind(this), this.$storeProxyMap$, writer, prepVNodeData);
4552
4569
  }
4553
4570
  }
4554
4571
 
@@ -5070,11 +5087,6 @@ class DomContainer extends _SharedContainer {
5070
5087
  parseQRL(qrl) {
5071
5088
  return inflateQRL(this, parseQRL(qrl));
5072
5089
  }
5073
- processJsx(host, jsx) {
5074
- // console.log('>>>> processJsx', String(host));
5075
- const styleScopedId = this.getHostProp(host, QScopedStyle);
5076
- return vnode_diff(this, jsx, host, addComponentStylePrefix(styleScopedId));
5077
- }
5078
5090
  handleError(err, host) {
5079
5091
  if (qDev) {
5080
5092
  // Clean vdom
@@ -8036,7 +8048,10 @@ const inflate = (container, target, typeId, data) => {
8036
8048
  if (valType === TypeIds.RootRef || valType >= TypeIds.Error) {
8037
8049
  Object.defineProperty(target, key, {
8038
8050
  get() {
8039
- return deserializeData(container, valType, valData);
8051
+ const value = deserializeData(container, valType, valData);
8052
+ // after first deserialize, we can replace the Object.defineProperty with the value
8053
+ target[key] = value;
8054
+ return value;
8040
8055
  },
8041
8056
  set(value) {
8042
8057
  Object.defineProperty(target, key, {
@@ -8378,13 +8393,7 @@ function inflateQRL(container, qrl) {
8378
8393
  }
8379
8394
  return qrl;
8380
8395
  }
8381
- /** A ref to a DOM element */
8382
- class DomVRef {
8383
- id;
8384
- constructor(id) {
8385
- this.id = id;
8386
- }
8387
- }
8396
+ let isDomRef = (obj) => false;
8388
8397
  const createSerializationContext = (
8389
8398
  /**
8390
8399
  * Node constructor, for instanceof checks.
@@ -8392,7 +8401,9 @@ const createSerializationContext = (
8392
8401
  * A node constructor can be null. For example on the client we can't serialize DOM nodes as
8393
8402
  * server will not know what to do with them.
8394
8403
  */
8395
- NodeConstructor, symbolToChunkResolver, getProp, setProp, storeProxyMap, writer,
8404
+ NodeConstructor,
8405
+ /** DomRef constructor, for instanceof checks. */
8406
+ DomRefConstructor, symbolToChunkResolver, getProp, setProp, storeProxyMap, writer,
8396
8407
  // temporary until we serdes the vnode data here
8397
8408
  prepVNodeData) => {
8398
8409
  if (!writer) {
@@ -8418,11 +8429,13 @@ prepVNodeData) => {
8418
8429
  return id;
8419
8430
  };
8420
8431
  const isSsrNode = (NodeConstructor ? (obj) => obj instanceof NodeConstructor : () => false);
8432
+ isDomRef = (DomRefConstructor ? (obj) => obj instanceof DomRefConstructor : () => false);
8421
8433
  return {
8422
8434
  $serialize$() {
8423
8435
  serialize(this);
8424
8436
  },
8425
8437
  $isSsrNode$: isSsrNode,
8438
+ $isDomRef$: isDomRef,
8426
8439
  $symbolToChunkResolver$: symbolToChunkResolver,
8427
8440
  $wasSeen$,
8428
8441
  $roots$: roots,
@@ -8568,6 +8581,9 @@ prepVNodeData) => {
8568
8581
  else if (isSsrNode(obj)) {
8569
8582
  discoveredValues.push(obj.vnodeData);
8570
8583
  }
8584
+ else if (isDomRef(obj)) {
8585
+ discoveredValues.push(obj.$ssrNode$.id);
8586
+ }
8571
8587
  else if (isJSXNode(obj)) {
8572
8588
  discoveredValues.push(obj.type, obj.props, obj.constProps, obj.children);
8573
8589
  }
@@ -8641,7 +8657,7 @@ const promiseResults = new WeakMap();
8641
8657
  * - Therefore root indexes need to be doubled to get the actual index.
8642
8658
  */
8643
8659
  function serialize(serializationContext) {
8644
- const { $writer$, $isSsrNode$, $setProp$, $storeProxyMap$ } = serializationContext;
8660
+ const { $writer$, $isSsrNode$, $isDomRef$, $setProp$, $storeProxyMap$ } = serializationContext;
8645
8661
  let depth = -1;
8646
8662
  // Skip the type for the roots output
8647
8663
  let writeType = false;
@@ -8863,23 +8879,19 @@ function serialize(serializationContext) {
8863
8879
  output(TypeIds.Object, out);
8864
8880
  }
8865
8881
  }
8866
- else if (value instanceof DomVRef) {
8867
- output(TypeIds.RefVNode, value.id);
8882
+ else if ($isDomRef$(value)) {
8883
+ value.$ssrNode$.vnodeData[0] |= VNodeDataFlag.SERIALIZE;
8884
+ output(TypeIds.RefVNode, value.$ssrNode$.id);
8868
8885
  }
8869
8886
  else if (value instanceof Signal) {
8870
8887
  /**
8871
8888
  * Special case: when a Signal value is an SSRNode, it always needs to be a DOM ref instead.
8872
8889
  * It can never be meant to become a vNode, because vNodes are internal only.
8873
8890
  */
8874
- let v = value instanceof ComputedSignal &&
8891
+ const v = value instanceof ComputedSignal &&
8875
8892
  (value.$invalid$ || fastSkipSerialize(value.$untrackedValue$))
8876
8893
  ? NEEDS_COMPUTATION
8877
8894
  : value.$untrackedValue$;
8878
- if ($isSsrNode$(v)) {
8879
- // TODO maybe we don't need to store all vnode data if it's only a ref
8880
- serializationContext.$addRoot$(v);
8881
- v = new DomVRef(v.id);
8882
- }
8883
8895
  if (value instanceof WrappedSignal) {
8884
8896
  output(TypeIds.WrappedSignal, [
8885
8897
  ...serializeWrappingFn(serializationContext, value),
@@ -9096,7 +9108,7 @@ function qrlToString(serializationContext, value) {
9096
9108
  * @internal
9097
9109
  */
9098
9110
  async function _serialize(data) {
9099
- const serializationContext = createSerializationContext(null, () => '', () => '', () => { }, new WeakMap());
9111
+ const serializationContext = createSerializationContext(null, null, () => '', () => '', () => { }, new WeakMap());
9100
9112
  for (const root of data) {
9101
9113
  serializationContext.$addRoot$(root);
9102
9114
  }
@@ -9287,6 +9299,9 @@ const canSerialize = (value) => {
9287
9299
  else if (value instanceof Uint8Array) {
9288
9300
  return true;
9289
9301
  }
9302
+ else if (isDomRef?.(value)) {
9303
+ return true;
9304
+ }
9290
9305
  }
9291
9306
  else if (typeof value === 'function') {
9292
9307
  if (isQrl(value) || isQwikComponent(value)) {
@@ -9491,8 +9506,8 @@ const createQRL = (chunk, symbol, symbolRef, symbolFn, capture, captureRef, refS
9491
9506
  }
9492
9507
  let _containerEl;
9493
9508
  const qrl = async function (...args) {
9494
- const fn = invokeFn.call(this, tryGetInvokeContext());
9495
- const result = await fn(...args);
9509
+ const boundedFn = bindFnToContext.call(this, tryGetInvokeContext());
9510
+ const result = await boundedFn(...args);
9496
9511
  return result;
9497
9512
  };
9498
9513
  const setContainer = (el) => {
@@ -9501,6 +9516,34 @@ const createQRL = (chunk, symbol, symbolRef, symbolFn, capture, captureRef, refS
9501
9516
  }
9502
9517
  return _containerEl;
9503
9518
  };
9519
+ function bindFnToContext(currentCtx, beforeFn) {
9520
+ // Note that we bind the current `this`
9521
+ return (...args) => maybeThen(resolveLazy(), (fn) => {
9522
+ if (!isFunction(fn)) {
9523
+ throw qError(QError_qrlIsNotFunction);
9524
+ }
9525
+ if (beforeFn && beforeFn() === false) {
9526
+ return;
9527
+ }
9528
+ const context = createOrReuseInvocationContext(currentCtx);
9529
+ const prevQrl = context.$qrl$;
9530
+ const prevEvent = context.$event$;
9531
+ // Note that we set the qrl here instead of in wrapFn because
9532
+ // it is possible we're called on a copied qrl
9533
+ context.$qrl$ = qrl;
9534
+ context.$event$ ||= this;
9535
+ try {
9536
+ return invoke.call(this, context, fn, ...args);
9537
+ }
9538
+ finally {
9539
+ context.$qrl$ = prevQrl;
9540
+ context.$event$ = prevEvent;
9541
+ }
9542
+ });
9543
+ }
9544
+ const resolveLazy = (containerEl) => {
9545
+ return symbolRef !== null ? symbolRef : resolve(containerEl);
9546
+ };
9504
9547
  // Wrap functions to provide their lexical scope
9505
9548
  const wrapFn = (fn) => {
9506
9549
  if (typeof fn !== 'function' || (!capture?.length && !captureRef?.length)) {
@@ -9553,34 +9596,6 @@ const createQRL = (chunk, symbol, symbolRef, symbolFn, capture, captureRef, refS
9553
9596
  }
9554
9597
  return symbolRef;
9555
9598
  };
9556
- const resolveLazy = (containerEl) => {
9557
- return symbolRef !== null ? symbolRef : resolve(containerEl);
9558
- };
9559
- function invokeFn(currentCtx, beforeFn) {
9560
- // Note that we bind the current `this`
9561
- return (...args) => maybeThen(resolveLazy(), (f) => {
9562
- if (!isFunction(f)) {
9563
- throw qError(QError_qrlIsNotFunction);
9564
- }
9565
- if (beforeFn && beforeFn() === false) {
9566
- return;
9567
- }
9568
- const context = createOrReuseInvocationContext(currentCtx);
9569
- const prevQrl = context.$qrl$;
9570
- const prevEvent = context.$event$;
9571
- // Note that we set the qrl here instead of in wrapFn because
9572
- // it is possible we're called on a copied qrl
9573
- context.$qrl$ = qrl;
9574
- context.$event$ ||= this;
9575
- try {
9576
- return invoke.call(this, context, f, ...args);
9577
- }
9578
- finally {
9579
- context.$qrl$ = prevQrl;
9580
- context.$event$ = prevEvent;
9581
- }
9582
- });
9583
- }
9584
9599
  const createOrReuseInvocationContext = (invoke) => {
9585
9600
  if (invoke == null) {
9586
9601
  return newInvokeContext();
@@ -9605,7 +9620,7 @@ const createQRL = (chunk, symbol, symbolRef, symbolFn, capture, captureRef, refS
9605
9620
  $symbol$: symbol,
9606
9621
  $refSymbol$: refSymbol,
9607
9622
  $hash$: hash,
9608
- getFn: invokeFn,
9623
+ getFn: bindFnToContext,
9609
9624
  $capture$: capture,
9610
9625
  $captureRef$: captureRef,
9611
9626
  dev: null,