@qwik.dev/core 2.0.0-beta.1 → 2.0.0-beta.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.
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qwik.dev/core/build",
3
- "version": "2.0.0-beta.1-dev+495e8d9",
3
+ "version": "2.0.0-beta.3-dev+aa098fc",
4
4
  "main": "index.mjs",
5
5
  "types": "index.d.ts",
6
6
  "private": true,
package/dist/cli.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * @qwik.dev/core/cli 2.0.0-beta.1-dev+495e8d9
3
+ * @qwik.dev/core/cli 2.0.0-beta.3-dev+aa098fc
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
@@ -5536,7 +5536,7 @@ async function printHelp(app) {
5536
5536
  await runCommand2(Object.assign(app, { task: args[0], args }));
5537
5537
  }
5538
5538
  function printVersion() {
5539
- console.log("2.0.0-beta.1-dev+495e8d9");
5539
+ console.log("2.0.0-beta.3-dev+aa098fc");
5540
5540
  }
5541
5541
  // Annotate the CommonJS export names for ESM import in node:
5542
5542
  0 && (module.exports = {
@@ -2049,13 +2049,12 @@ declare type QRLInternalMethods<TYPE> = {
2049
2049
  $captureRef$: unknown[] | null;
2050
2050
  dev: QRLDev | null;
2051
2051
  resolved: undefined | TYPE;
2052
- resolve(): Promise<TYPE>;
2052
+ resolve(containerEl?: Element): Promise<TYPE>;
2053
2053
  getSymbol(): string;
2054
2054
  getHash(): string;
2055
2055
  getCaptured(): unknown[] | null;
2056
2056
  getFn(currentCtx?: InvokeContext | InvokeTuple, beforeFn?: () => void): TYPE extends (...args: any) => any ? (...args: Parameters<TYPE>) => ValueOrPromise<ReturnType<TYPE>> : unknown;
2057
2057
  $setContainer$(containerEl: Element | undefined): Element | undefined;
2058
- $resolveLazy$(containerEl?: Element): ValueOrPromise<TYPE>;
2059
2058
  };
2060
2059
 
2061
2060
  declare type QrlReturn<T> = T extends (...args: any) => infer R ? Awaited<R> : unknown;
@@ -4250,7 +4249,7 @@ export declare const _VAR_PROPS: unique symbol;
4250
4249
  export declare const _verifySerializable: <T>(value: T, preMessage?: string) => T;
4251
4250
 
4252
4251
  /**
4253
- * 2.0.0-beta.1-dev+495e8d9
4252
+ * 2.0.0-beta.3-dev+aa098fc
4254
4253
  *
4255
4254
  * @public
4256
4255
  */
package/dist/core.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * @qwik.dev/core 2.0.0-beta.1-dev+495e8d9
3
+ * @qwik.dev/core 2.0.0-beta.3-dev+aa098fc
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
@@ -644,8 +644,6 @@
644
644
  $invalidate$() {
645
645
  this.$flags$ |= 1 /* SignalFlags.INVALID */;
646
646
  this.$forceRunEffects$ = false;
647
- // We should only call subscribers if the calculation actually changed.
648
- // Therefore, we need to calculate the value now.
649
647
  this.$container$?.$scheduler$(7 /* ChoreType.RECOMPUTE_AND_SCHEDULE_EFFECTS */, this.$hostElement$, this, this.$effects$);
650
648
  }
651
649
  /**
@@ -1232,7 +1230,7 @@
1232
1230
  *
1233
1231
  * @public
1234
1232
  */
1235
- const version = "2.0.0-beta.1-dev+495e8d9";
1233
+ const version = "2.0.0-beta.3-dev+aa098fc";
1236
1234
 
1237
1235
  /** @internal */
1238
1236
  const EMPTY_ARRAY = [];
@@ -2423,7 +2421,6 @@
2423
2421
  if (!isInlineComponent) {
2424
2422
  container.setHostProp(renderHost, ELEMENT_SEQ_IDX, null);
2425
2423
  container.setHostProp(renderHost, USE_ON_LOCAL_SEQ_IDX, null);
2426
- container.setHostProp(renderHost, ELEMENT_PROPS, props);
2427
2424
  }
2428
2425
  if (vnode_isVNode(renderHost)) {
2429
2426
  clearAllEffects(container, renderHost);
@@ -4542,16 +4539,36 @@
4542
4539
  shouldRender = true;
4543
4540
  }
4544
4541
  if (host) {
4545
- const vNodeProps = vnode_getProp(host, ELEMENT_PROPS, container.$getObjectById$);
4546
- shouldRender = shouldRender || propsDiffer(jsxProps, vNodeProps);
4542
+ let vNodeProps = vnode_getProp(host, ELEMENT_PROPS, container.$getObjectById$);
4543
+ const propsAreDifferent = propsDiffer(jsxProps, vNodeProps);
4544
+ shouldRender = shouldRender || propsAreDifferent;
4547
4545
  if (shouldRender) {
4546
+ if (propsAreDifferent) {
4547
+ if (vNodeProps) {
4548
+ // Reuse the same props instance, qrls can use the current props instance
4549
+ // as a capture ref, so we can't change it.
4550
+ // We need to do this directly, because normally we would subscribe to the signals
4551
+ // if any signal is there.
4552
+ vNodeProps[_CONST_PROPS] = jsxProps[_CONST_PROPS];
4553
+ vNodeProps[_VAR_PROPS] = jsxProps[_VAR_PROPS];
4554
+ }
4555
+ else if (jsxProps) {
4556
+ // If there is no props instance, create a new one.
4557
+ // We can do this because we are not using the props instance for anything else.
4558
+ vnode_setProp(host, ELEMENT_PROPS, jsxProps);
4559
+ vNodeProps = jsxProps;
4560
+ }
4561
+ }
4562
+ // Assign the new QRL instance to the host.
4563
+ // Unfortunately it is created every time, something to fix in the optimizer.
4564
+ vnode_setProp(host, OnRenderProp, componentQRL);
4548
4565
  /**
4549
4566
  * Mark host as not deleted. The host could have been marked as deleted if it there was a
4550
4567
  * cleanup run. Now we found it and want to reuse it, so we need to mark it as not
4551
4568
  * deleted.
4552
4569
  */
4553
4570
  host[0 /* VNodeProps.flags */] &= -33 /* VNodeFlags.Deleted */;
4554
- container.$scheduler$(6 /* ChoreType.COMPONENT */, host, componentQRL, jsxProps);
4571
+ container.$scheduler$(6 /* ChoreType.COMPONENT */, host, componentQRL, vNodeProps);
4555
4572
  }
4556
4573
  }
4557
4574
  descendContentToProject(jsxNode.children, host);
@@ -5511,22 +5528,23 @@
5511
5528
  {
5512
5529
  const target = chore.$target$;
5513
5530
  const effects = chore.$payload$;
5531
+ const ctx = newInvokeContext();
5532
+ ctx.$container$ = container;
5514
5533
  if (target instanceof ComputedSignalImpl || target instanceof WrappedSignalImpl) {
5515
5534
  const forceRunEffects = target.$forceRunEffects$;
5516
5535
  target.$forceRunEffects$ = false;
5517
- if (!target.$effects$?.size) {
5536
+ if (!effects?.size) {
5518
5537
  break;
5519
5538
  }
5520
- returnValue = retryOnPromise(() => {
5521
- if (target.$computeIfNeeded$() || forceRunEffects) {
5522
- triggerEffects(container, target, effects);
5539
+ // needed for computed signals and throwing QRLs
5540
+ returnValue = maybeThen(retryOnPromise(() => invoke.call(target, ctx, target.$computeIfNeeded$)), (didChange) => {
5541
+ if (didChange || forceRunEffects) {
5542
+ return retryOnPromise(() => triggerEffects(container, target, effects));
5523
5543
  }
5524
5544
  });
5525
5545
  }
5526
5546
  else {
5527
- returnValue = retryOnPromise(() => {
5528
- triggerEffects(container, target, effects);
5529
- });
5547
+ returnValue = retryOnPromise(() => triggerEffects(container, target, effects));
5530
5548
  }
5531
5549
  }
5532
5550
  break;
@@ -5608,7 +5626,10 @@
5608
5626
  return idxDiff;
5609
5627
  }
5610
5628
  // If the host is the same (or missing), and the type is the same, we need to compare the target.
5611
- if (a.$target$ !== b.$target$ || a.$payload$ !== b.$payload$) {
5629
+ if (a.$target$ !== b.$target$) {
5630
+ if (isQrl(a.$target$) && isQrl(b.$target$) && a.$target$.$hash$ === b.$target$.$hash$) {
5631
+ return 0;
5632
+ }
5612
5633
  // 1 means that we are going to process chores as FIFO
5613
5634
  return 1;
5614
5635
  }
@@ -5656,7 +5677,7 @@
5656
5677
  * multiple times during component execution. For this reason it is necessary for us to update
5657
5678
  * the chore with the latest result of the signal.
5658
5679
  */
5659
- if (existing.$type$ === 4 /* ChoreType.NODE_DIFF */) {
5680
+ if (existing.$payload$ !== value.$payload$) {
5660
5681
  existing.$payload$ = value.$payload$;
5661
5682
  }
5662
5683
  if (existing.$executed$) {
@@ -7788,12 +7809,15 @@
7788
7809
  let nextToConsumeIdx = 0;
7789
7810
  let ch = 0;
7790
7811
  let peekCh = 0;
7812
+ const getChar = (idx) => {
7813
+ return idx < vData.length ? vData.charCodeAt(idx) : 0;
7814
+ };
7791
7815
  const peek = () => {
7792
7816
  if (peekCh !== 0) {
7793
7817
  return peekCh;
7794
7818
  }
7795
7819
  else {
7796
- return (peekCh = nextToConsumeIdx < vData.length ? vData.charCodeAt(nextToConsumeIdx) : 0);
7820
+ return (peekCh = getChar(nextToConsumeIdx));
7797
7821
  }
7798
7822
  };
7799
7823
  const consume = () => {
@@ -7814,7 +7838,7 @@
7814
7838
  return vData.substring(start, nextToConsumeIdx);
7815
7839
  };
7816
7840
  while (peek() !== 0) {
7817
- callback(peek, consumeValue, consume, nextToConsumeIdx);
7841
+ callback(peek, consumeValue, consume, getChar, nextToConsumeIdx);
7818
7842
  }
7819
7843
  };
7820
7844
  const vnode_getNextSibling = (vnode) => {
@@ -8028,21 +8052,19 @@
8028
8052
  let textIdx = 0;
8029
8053
  let combinedText = null;
8030
8054
  let container = null;
8031
- processVNodeData(vData, (peek, consumeValue, consume, nextToConsumeIdx) => {
8055
+ processVNodeData(vData, (peek, consumeValue, consume, getChar, nextToConsumeIdx) => {
8032
8056
  if (isNumber(peek())) {
8033
8057
  // Element counts get encoded as numbers.
8034
- while (!isElement(child)) {
8058
+ while (!isElement(child) ||
8059
+ // We pretend that style element's don't exist as they can get moved out.
8060
+ // skip over style elements, as those need to be moved to the head
8061
+ // and are not included in the counts.
8062
+ isQStyleElement(child)) {
8035
8063
  child = fastNextSibling(child);
8036
8064
  if (!child) {
8037
8065
  throw qError(27 /* QError.materializeVNodeDataError */, [vData, peek(), nextToConsumeIdx]);
8038
8066
  }
8039
8067
  }
8040
- // We pretend that style element's don't exist as they can get moved out.
8041
- while (isQStyleElement(child)) {
8042
- // skip over style elements, as those need to be moved to the head
8043
- // and are not included in the counts.
8044
- child = fastNextSibling(child);
8045
- }
8046
8068
  combinedText = null;
8047
8069
  previousTextNode = null;
8048
8070
  let value = 0;
@@ -8074,7 +8096,17 @@
8074
8096
  vnode_setAttr(null, vParent, ELEMENT_PROPS, consumeValue());
8075
8097
  }
8076
8098
  else if (peek() === VNodeDataChar.KEY) {
8077
- vnode_setAttr(null, vParent, ELEMENT_KEY, consumeValue());
8099
+ const isEscapedValue = getChar(nextToConsumeIdx + 1) === VNodeDataChar.SEPARATOR;
8100
+ let value;
8101
+ if (isEscapedValue) {
8102
+ consume();
8103
+ value = decodeURI(consumeValue());
8104
+ consume();
8105
+ }
8106
+ else {
8107
+ value = consumeValue();
8108
+ }
8109
+ vnode_setAttr(null, vParent, ELEMENT_KEY, value);
8078
8110
  }
8079
8111
  else if (peek() === VNodeDataChar.SEQ) {
8080
8112
  vnode_setAttr(null, vParent, ELEMENT_SEQ, consumeValue());
@@ -8120,6 +8152,10 @@
8120
8152
  vnode_setAttr(null, vParent, QSlot, consumeValue());
8121
8153
  }
8122
8154
  else {
8155
+ // skip over style elements in front of text nodes, where text node is the first child (except the style node)
8156
+ while (isQStyleElement(child)) {
8157
+ child = fastNextSibling(child);
8158
+ }
8123
8159
  const textNode = child && fastNodeType(child) === /* Node.TEXT_NODE */ 3 ? child : null;
8124
8160
  // must be alphanumeric
8125
8161
  if (combinedText === null) {
@@ -10078,6 +10114,7 @@
10078
10114
  const SerializerSymbol = Symbol('serialize');
10079
10115
 
10080
10116
  // keep these imports above the rest to prevent circular dep issues
10117
+ const resolvedSymbol = Symbol('resolved');
10081
10118
  const createQRL = (chunk, symbol, symbolRef, symbolFn, capture, captureRef) => {
10082
10119
  if (qDev && qSerialize) {
10083
10120
  if (captureRef) {
@@ -10130,9 +10167,6 @@
10130
10167
  };
10131
10168
  return bound;
10132
10169
  }
10133
- const resolveLazy = (containerEl) => {
10134
- return symbolRef !== null ? symbolRef : resolve(containerEl);
10135
- };
10136
10170
  // Wrap functions to provide their lexical scope
10137
10171
  const wrapFn = (fn) => {
10138
10172
  if (typeof fn !== 'function' || (!capture?.length && !captureRef?.length)) {
@@ -10161,45 +10195,58 @@
10161
10195
  return invoke.call(this, context, fn, ...args);
10162
10196
  };
10163
10197
  };
10164
- const resolve = async (containerEl) => {
10165
- if (symbolRef !== null) {
10166
- // Resolving (Promise) or already resolved (value)
10198
+ // Retrieve memoized result from symbolFn
10199
+ if (symbolFn && resolvedSymbol in symbolFn) {
10200
+ symbolRef = symbolFn[resolvedSymbol];
10201
+ }
10202
+ const resolve = symbolRef
10203
+ ? async () => symbolRef
10204
+ : async (containerEl) => {
10205
+ if (symbolRef !== null) {
10206
+ // Resolving (Promise) or already resolved (value)
10207
+ return symbolRef;
10208
+ }
10209
+ if (containerEl) {
10210
+ setContainer(containerEl);
10211
+ }
10212
+ if (chunk === '') {
10213
+ // Sync QRL
10214
+ assertDefined(_containerEl, 'Sync QRL must have container element');
10215
+ const hash = _containerEl.getAttribute(QInstanceAttr);
10216
+ const doc = _containerEl.ownerDocument;
10217
+ const qFuncs = getQFuncs(doc, hash);
10218
+ // No need to wrap, syncQRLs can't have captured scope
10219
+ return (qrl.resolved = symbolRef = qFuncs[Number(symbol)]);
10220
+ }
10221
+ if (build.isBrowser && chunk) {
10222
+ /** We run the QRL, so now the probability of the chunk is 100% */
10223
+ preloader.p(chunk, 1);
10224
+ }
10225
+ const start = now();
10226
+ const ctx = tryGetInvokeContext();
10227
+ if (symbolFn !== null) {
10228
+ symbolRef = symbolFn().then((module) => {
10229
+ const resolved = wrapFn((symbolRef = module[symbol]));
10230
+ // We memoize the result on the symbolFn
10231
+ symbolFn[resolvedSymbol] = resolved;
10232
+ qrl.resolved = resolved;
10233
+ return resolved;
10234
+ });
10235
+ }
10236
+ else {
10237
+ // TODO cache the imported symbol but watch out for dev mode
10238
+ const imported = getPlatform().importSymbol(_containerEl, chunk, symbol);
10239
+ symbolRef = maybeThen(imported, (ref) => (qrl.resolved = wrapFn((symbolRef = ref))));
10240
+ }
10241
+ if (isPromise(symbolRef)) {
10242
+ symbolRef.then(() => emitUsedSymbol(symbol, ctx?.$element$, start), (err) => {
10243
+ console.error(`qrl ${symbol} failed to load`, err);
10244
+ // We shouldn't cache rejections, we can try again later
10245
+ symbolRef = null;
10246
+ });
10247
+ }
10167
10248
  return symbolRef;
10168
- }
10169
- if (containerEl) {
10170
- setContainer(containerEl);
10171
- }
10172
- if (chunk === '') {
10173
- // Sync QRL
10174
- assertDefined(_containerEl, 'Sync QRL must have container element');
10175
- const hash = _containerEl.getAttribute(QInstanceAttr);
10176
- const doc = _containerEl.ownerDocument;
10177
- const qFuncs = getQFuncs(doc, hash);
10178
- // No need to wrap, syncQRLs can't have captured scope
10179
- return (qrl.resolved = symbolRef = qFuncs[Number(symbol)]);
10180
- }
10181
- if (build.isBrowser && chunk) {
10182
- /** We run the QRL, so now the probability of the chunk is 100% */
10183
- preloader.p(chunk, 1);
10184
- }
10185
- const start = now();
10186
- const ctx = tryGetInvokeContext();
10187
- if (symbolFn !== null) {
10188
- symbolRef = symbolFn().then((module) => (qrl.resolved = wrapFn((symbolRef = module[symbol]))));
10189
- }
10190
- else {
10191
- const imported = getPlatform().importSymbol(_containerEl, chunk, symbol);
10192
- symbolRef = maybeThen(imported, (ref) => (qrl.resolved = wrapFn((symbolRef = ref))));
10193
- }
10194
- if (typeof symbolRef === 'object' && isPromise(symbolRef)) {
10195
- symbolRef.then(() => emitUsedSymbol(symbol, ctx?.$element$, start), (err) => {
10196
- console.error(`qrl ${symbol} failed to load`, err);
10197
- // We shouldn't cache rejections, we can try again later
10198
- symbolRef = null;
10199
- });
10200
- }
10201
- return symbolRef;
10202
- };
10249
+ };
10203
10250
  const createOrReuseInvocationContext = (invoke) => {
10204
10251
  if (invoke == null) {
10205
10252
  return newInvokeContext();
@@ -10217,7 +10264,6 @@
10217
10264
  getHash: () => hash,
10218
10265
  getCaptured: () => captureRef,
10219
10266
  resolve,
10220
- $resolveLazy$: resolveLazy,
10221
10267
  $setContainer$: setContainer,
10222
10268
  $chunk$: chunk,
10223
10269
  $symbol$: symbol,
@@ -11058,13 +11104,13 @@
11058
11104
  const styleId = styleKey(styleQrl, i);
11059
11105
  const host = iCtx.$hostElement$;
11060
11106
  set(styleId);
11061
- const value = styleQrl.$resolveLazy$(iCtx.$element$);
11062
- if (isPromise(value)) {
11063
- value.then((val) => iCtx.$container$.$appendStyle$(transform(val, styleId), styleId, host, scoped));
11064
- throw value;
11107
+ if (styleQrl.resolved) {
11108
+ iCtx.$container$.$appendStyle$(transform(styleQrl.resolved, styleId), styleId, host, scoped);
11065
11109
  }
11066
11110
  else {
11067
- iCtx.$container$.$appendStyle$(transform(value, styleId), styleId, host, scoped);
11111
+ throw styleQrl
11112
+ .resolve()
11113
+ .then((val) => iCtx.$container$.$appendStyle$(transform(val, styleId), styleId, host, scoped));
11068
11114
  }
11069
11115
  return styleId;
11070
11116
  };
@@ -11355,7 +11401,7 @@
11355
11401
  set(task);
11356
11402
  useRunTask(task, eagerness);
11357
11403
  if (!isServerPlatform()) {
11358
- qrl.$resolveLazy$(iCtx.$element$);
11404
+ qrl.resolve(iCtx.$element$);
11359
11405
  iCtx.$container$.$scheduler$(32 /* ChoreType.VISIBLE */, task);
11360
11406
  }
11361
11407
  };