@stencil/core 5.0.0-rc.1 → 5.0.0-rc.11

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.
@@ -238,7 +238,11 @@ const HOST_FLAGS = {
238
238
  * coming from the runtime's own reflection aren't applied back to the prop.
239
239
  */
240
240
  isReflecting: 16384,
241
- devOnRender: 4096,
241
+ /**
242
+ * Set by `forceUpdate()` so the next update renders even if `componentShouldUpdate` returns `false`.
243
+ */
244
+ isUpdateForced: 4096,
245
+ devOnRender: 32768,
242
246
  devOnDidLoad: 8192
243
247
  };
244
248
  const CF_scopedCssEncapsulation = 2;
@@ -1044,7 +1048,7 @@ const patchSlotPrepend = (HostElementPrototype) => {
1044
1048
  return toReturn;
1045
1049
  }
1046
1050
  if (newChild.nodeType === 1 && !!newChild.getAttribute("slot")) newChild.hidden = true;
1047
- return HostElementPrototype.__prepend(newChild);
1051
+ return HostElementPrototype.__prepend.call(this, newChild);
1048
1052
  });
1049
1053
  };
1050
1054
  };
@@ -1713,7 +1717,7 @@ const attachStyles = (hostRef) => {
1713
1717
  else if (BUILD.hydrateServerSide && BUILD.shadowModeClosed && flags & CMP_FLAGS.shadowNeedsScopedCss && flags & CMP_FLAGS.shadowModeClosed) styleContainerNode = elm;
1714
1718
  else styleContainerNode = elm.getRootNode();
1715
1719
  const scopeId = addStyle(styleContainerNode, cmpMeta, hostRef.$modeName$);
1716
- if ((BUILD.shadowDom || BUILD.scoped) && BUILD.cssAnnotations && flags & CMP_FLAGS.needsScopedEncapsulation) {
1720
+ if ((BUILD.shadowDom || BUILD.scoped) && BUILD.cssAnnotations && flags & (CMP_FLAGS.needsScopedEncapsulation | CMP_FLAGS.shadowNeedsScopedCss)) {
1717
1721
  elm["s-sc"] = scopeId;
1718
1722
  elm.classList.add(scopeId + "-h");
1719
1723
  }
@@ -1800,12 +1804,51 @@ const isComplexType = (o) => {
1800
1804
  return o === "object" || o === "function";
1801
1805
  };
1802
1806
  //#endregion
1803
- //#region src/runtime/signals-core.ts
1804
- const getCore = () => globalThis[Symbol.for("stencil.preact-signals-core")] ??= SignalsCore;
1805
- const effect = (fn, options) => getCore().effect(fn, options);
1806
- function signal(value, options) {
1807
- return getCore().signal(value, options);
1808
- }
1807
+ //#region src/runtime/parse-property-value.ts
1808
+ /**
1809
+ * Parse a new property value for a given property type.
1810
+ *
1811
+ * While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
1812
+ * it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
1813
+ * 1. `any`, the type given to `propValue` in the function signature
1814
+ * 2. the type stored from `propType`.
1815
+ *
1816
+ * This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
1817
+ *
1818
+ * Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
1819
+ * a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
1820
+ * based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
1821
+ * ```tsx
1822
+ * <my-cmp prop-val={0}></my-cmp>
1823
+ * ```
1824
+ *
1825
+ * HTML prop values on the other hand, will always a string
1826
+ *
1827
+ * @param propValue the new value to coerce to some type
1828
+ * @param propType the type of the prop, expressed as a binary number
1829
+ * @returns the parsed/coerced value
1830
+ */
1831
+ const parsePropertyValue = (propValue, propType) => {
1832
+ if (propValue != null && !isComplexType(propValue)) {
1833
+ /**
1834
+ * ensure this value is of the correct prop type
1835
+ */
1836
+ if (BUILD.propBoolean && propType & MEMBER_FLAGS.Boolean) return propValue === "" || !!propValue;
1837
+ /**
1838
+ * force it to be a number
1839
+ */
1840
+ if (BUILD.propNumber && propType & MEMBER_FLAGS.Number) return typeof propValue === "string" ? parseFloat(propValue) : typeof propValue === "number" ? propValue : NaN;
1841
+ /**
1842
+ * could have been passed as a number or boolean but we still want it as a string
1843
+ */
1844
+ if (BUILD.propString && propType & MEMBER_FLAGS.String) return String(propValue);
1845
+ return propValue;
1846
+ }
1847
+ /**
1848
+ * not sure exactly what type we want so no need to change to a different type
1849
+ */
1850
+ return propValue;
1851
+ };
1809
1852
  //#endregion
1810
1853
  //#region src/runtime/event-emitter.ts
1811
1854
  const createEvent = (ref, name, flags) => {
@@ -2869,24 +2912,24 @@ const markFirstConnected = (hostRef) => {
2869
2912
  hostRef.$onFirstConnectResolve$ = void 0;
2870
2913
  };
2871
2914
  /**
2872
- * Wait for `ancestorElm` to be defined and its real `connectedCallback` to have completed.
2873
- * Shared by the lazy ({@link initializeComponent}) and standalone (`bootstrap-standalone.ts`)
2874
- * `connectedCallback` paths so a component never connects before its nearest Stencil
2875
- * ancestor, regardless of load order. Both call sites already check `BUILD.asyncLoading` and
2876
- * that an ancestor exists before calling this. Lazy's proxy classes are always pre-defined,
2877
- * so the `whenDefined` wait is a no-op there - it only does real work for standalone's
2878
- * autoloader, where the ancestor tag may not be defined yet.
2915
+ * Get a promise for `ancestorElm` to be defined and its real `connectedCallback` to have
2916
+ * completed, or `undefined` if it already has. Shared by the lazy ({@link initializeComponent})
2917
+ * and standalone (`bootstrap-standalone.ts`) `connectedCallback` paths so a component never
2918
+ * connects before its nearest Stencil ancestor, regardless of load order. Callers only `await`
2919
+ * a returned promise, so a component whose ancestor is already connected carries on
2920
+ * synchronously instead of losing a microtask. Lazy's proxy classes are always pre-defined, so
2921
+ * the `whenDefined` wait only does real work for standalone's autoloader, where the ancestor
2922
+ * tag may not be defined yet.
2879
2923
  *
2880
2924
  * @param ancestorElm the nearest Stencil ancestor element
2881
2925
  * @param registry the registry the waiting component is defined in
2926
+ * @returns a promise to await, or `undefined` if there's nothing to wait for
2882
2927
  */
2883
- const awaitAncestorConnected = async (ancestorElm, registry) => {
2884
- let ancestorHostRef = getHostRef(ancestorElm);
2885
- if (!BUILD.lazyLoad && !ancestorHostRef) {
2886
- await registry.whenDefined(ancestorElm.tagName.toLowerCase());
2887
- ancestorHostRef = getHostRef(ancestorElm);
2888
- }
2889
- if (ancestorHostRef && !(ancestorHostRef.$flags$ & HOST_FLAGS.hasFiredConnected)) await ensureFirstConnectPromise(ancestorHostRef);
2928
+ const whenAncestorConnected = (ancestorElm, registry) => {
2929
+ const pendingConnect = (hostRef) => hostRef && !(hostRef.$flags$ & HOST_FLAGS.hasFiredConnected) ? ensureFirstConnectPromise(hostRef) : void 0;
2930
+ const ancestorHostRef = getHostRef(ancestorElm);
2931
+ if (!BUILD.lazyLoad && !ancestorHostRef) return registry.whenDefined(ancestorElm.tagName.toLowerCase()).then(() => pendingConnect(getHostRef(ancestorElm)));
2932
+ return pendingConnect(ancestorHostRef);
2890
2933
  };
2891
2934
  const attachToAncestor = (hostRef, ancestorComponent) => {
2892
2935
  if (BUILD.asyncLoading && ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent["s-p"]) {
@@ -2897,6 +2940,17 @@ const attachToAncestor = (hostRef, ancestorComponent) => {
2897
2940
  if (ancestorComponent["s-pc"]) ancestorComponent["s-pc"].push(ensureFirstConnectPromise(hostRef));
2898
2941
  }
2899
2942
  };
2943
+ /**
2944
+ * Release the ancestor waiting on this component's update (registered by {@link attachToAncestor}).
2945
+ *
2946
+ * @param hostRef the component's host reference
2947
+ */
2948
+ const resolveAncestorWait = (hostRef) => {
2949
+ if (BUILD.asyncLoading && hostRef.$onRenderResolve$) {
2950
+ hostRef.$onRenderResolve$();
2951
+ hostRef.$onRenderResolve$ = void 0;
2952
+ }
2953
+ };
2900
2954
  const scheduleUpdate = (hostRef, isInitialLoad) => {
2901
2955
  if (BUILD.updatable) hostRef.$flags$ |= HOST_FLAGS.isQueuedForUpdate;
2902
2956
  if (BUILD.asyncLoading && hostRef.$flags$ & HOST_FLAGS.isWaitingForChildren) {
@@ -2906,10 +2960,10 @@ const scheduleUpdate = (hostRef, isInitialLoad) => {
2906
2960
  attachToAncestor(hostRef, hostRef.$ancestorComponent$);
2907
2961
  const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
2908
2962
  if (isInitialLoad) {
2909
- const pendingConnects = BUILD.asyncLoading ? hostRef.$hostElement$["s-pc"] : void 0;
2910
- if (pendingConnects && pendingConnects.length > 0) return Promise.all(pendingConnects).then(dispatch).catch(dispatch);
2911
2963
  queueMicrotask(() => {
2912
- dispatch();
2964
+ const pendingConnects = BUILD.asyncLoading ? hostRef.$hostElement$["s-pc"] : void 0;
2965
+ if (pendingConnects && pendingConnects.length > 0) Promise.all(pendingConnects).then(dispatch, dispatch);
2966
+ else dispatch();
2913
2967
  });
2914
2968
  return;
2915
2969
  }
@@ -2962,8 +3016,9 @@ const dispatchHooks = (hostRef, isInitialLoad) => {
2962
3016
  if (BUILD.updatable && hostRef.$queuedPropChanges$) {
2963
3017
  const changes = hostRef.$queuedPropChanges$;
2964
3018
  hostRef.$queuedPropChanges$ = void 0;
2965
- if (safeCall(instance, "componentShouldUpdate", changes, elm) === false) {
3019
+ if (safeCall(instance, "componentShouldUpdate", changes, elm) === false && !(hostRef.$flags$ & HOST_FLAGS.isUpdateForced)) {
2966
3020
  hostRef.$flags$ &= ~HOST_FLAGS.isQueuedForUpdate;
3021
+ resolveAncestorWait(hostRef);
2967
3022
  return;
2968
3023
  }
2969
3024
  }
@@ -3089,7 +3144,10 @@ const callRender = (hostRef, instance, elm, isInitialLoad) => {
3089
3144
  * method, so we can call the method immediately. If not, check before calling it.
3090
3145
  */
3091
3146
  instance = allRenderFn ? instance.render() : instance.render && instance.render();
3092
- if (updatable) hostRef.$flags$ &= ~HOST_FLAGS.isQueuedForUpdate;
3147
+ if (updatable) {
3148
+ hostRef.$flags$ &= ~(HOST_FLAGS.isQueuedForUpdate | HOST_FLAGS.isUpdateForced);
3149
+ hostRef.$queuedPropChanges$ = void 0;
3150
+ }
3093
3151
  if (updatable || lazyLoad) hostRef.$flags$ |= HOST_FLAGS.hasRendered;
3094
3152
  if (BUILD.hasRenderFn || BUILD.reflect) {
3095
3153
  if (BUILD.vdomRender || BUILD.reflect) {
@@ -3140,10 +3198,7 @@ const postUpdateComponent = (hostRef) => {
3140
3198
  }
3141
3199
  if (BUILD.method && BUILD.lazyLoad) hostRef.$onInstanceResolve$(elm);
3142
3200
  if (BUILD.asyncLoading) {
3143
- if (hostRef.$onRenderResolve$) {
3144
- hostRef.$onRenderResolve$();
3145
- hostRef.$onRenderResolve$ = void 0;
3146
- }
3201
+ resolveAncestorWait(hostRef);
3147
3202
  if (hostRef.$flags$ & HOST_FLAGS.needsRerender) nextTick(() => scheduleUpdate(hostRef, false));
3148
3203
  hostRef.$flags$ &= ~(HOST_FLAGS.isWaitingForChildren | HOST_FLAGS.needsRerender);
3149
3204
  }
@@ -3152,7 +3207,10 @@ const forceUpdate = (ref) => {
3152
3207
  if (BUILD.updatable && (Build.isBrowser || Build.isTesting)) {
3153
3208
  const hostRef = getHostRef(ref);
3154
3209
  const isConnected = hostRef?.$hostElement$?.isConnected;
3155
- if (isConnected && (hostRef.$flags$ & (HOST_FLAGS.hasRendered | HOST_FLAGS.isQueuedForUpdate)) === HOST_FLAGS.hasRendered) scheduleUpdate(hostRef, false);
3210
+ if (isConnected && hostRef.$flags$ & HOST_FLAGS.hasRendered) {
3211
+ hostRef.$flags$ |= HOST_FLAGS.isUpdateForced;
3212
+ if (!(hostRef.$flags$ & HOST_FLAGS.isQueuedForUpdate)) scheduleUpdate(hostRef, false);
3213
+ }
3156
3214
  return isConnected;
3157
3215
  }
3158
3216
  return false;
@@ -3212,6 +3270,121 @@ const serverSideConnected = (elm) => {
3212
3270
  }
3213
3271
  };
3214
3272
  //#endregion
3273
+ //#region src/runtime/set-value.ts
3274
+ /**
3275
+ * The value a reflected prop writes to its attribute: the serialized value if it has one.
3276
+ * @param hostRef the component's host ref
3277
+ * @param propName the prop
3278
+ * @param val the prop's value
3279
+ * @returns the value to reflect
3280
+ */
3281
+ const getReflectedValue = (hostRef, propName, val) => BUILD.serializer && hostRef.$serializerValues$.has(propName) ? hostRef.$serializerValues$.get(propName) : val;
3282
+ /**
3283
+ * Write a reflected prop's attribute as soon as the prop changes, like native elements do,
3284
+ * so it agrees with the prop before watchers run. Until the first render, rendering reflects it.
3285
+ * @param hostRef the component's host ref
3286
+ * @param cmpMeta the component's runtime metadata
3287
+ * @param elm the host element
3288
+ * @param propName the prop that changed
3289
+ * @param oldAttrVal the previously reflected value
3290
+ * @param newAttrVal the value to reflect
3291
+ */
3292
+ const reflectProp = (hostRef, cmpMeta, elm, propName, oldAttrVal, newAttrVal) => {
3293
+ if (!(hostRef.$flags$ & HOST_FLAGS.hasRendered) || !(cmpMeta.$members$[propName][0] & MEMBER_FLAGS.ReflectAttr)) return;
3294
+ const attrName = cmpMeta.$attrsToReflect$?.find(([p]) => p === propName)?.[1];
3295
+ if (!attrName) return;
3296
+ if (BUILD.serializer) hostRef.$flags$ |= HOST_FLAGS.isReflecting;
3297
+ setAccessor(elm, attrName, oldAttrVal, newAttrVal, false, VNODE_FLAGS.isHost);
3298
+ if (BUILD.serializer) hostRef.$flags$ &= ~HOST_FLAGS.isReflecting;
3299
+ };
3300
+ const applySerializers = (hostRef, cmpMeta, propName, val, instance) => {
3301
+ const run = (inst) => {
3302
+ let attrVal = val;
3303
+ for (const serializer of cmpMeta.$serializers$[propName]) {
3304
+ const [[methodName]] = Object.entries(serializer);
3305
+ attrVal = inst[methodName](attrVal, propName);
3306
+ }
3307
+ hostRef.$serializerValues$.set(propName, attrVal);
3308
+ };
3309
+ if (instance) run(instance);
3310
+ else hostRef.$fetchedCbList$.push(() => run(hostRef.$lazyInstance$));
3311
+ };
3312
+ const getValue = (ref, propName) => {
3313
+ if (BUILD.signalBacking) {
3314
+ const sig = getHostRef(ref)?.$signalValues$?.get(propName);
3315
+ if (sig !== void 0) return sig.value;
3316
+ }
3317
+ return getHostRef(ref).$instanceValues$.get(propName);
3318
+ };
3319
+ const setValue = (ref, propName, newVal, cmpMeta) => {
3320
+ const hostRef = getHostRef(ref);
3321
+ if (BUILD.serializer && hostRef?.$flags$ & HOST_FLAGS.isReflecting && hostRef.$serializerValues$.has(propName) && hostRef.$serializerValues$.get(propName) === newVal) return;
3322
+ if (BUILD.signalBacking) {
3323
+ const sig = hostRef?.$signalValues$?.get(propName);
3324
+ if (sig !== void 0) {
3325
+ const parsed = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
3326
+ if (BUILD.serializer && BUILD.reflect && cmpMeta.$attrsToReflect$ && cmpMeta.$serializers$?.[propName]) {
3327
+ const elm = BUILD.lazyLoad ? hostRef.$hostElement$ : ref;
3328
+ applySerializers(hostRef, cmpMeta, propName, parsed, BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm);
3329
+ }
3330
+ if (!(Number.isNaN(sig.peek()) && Number.isNaN(parsed))) sig.value = parsed;
3331
+ return;
3332
+ }
3333
+ }
3334
+ if (!hostRef) {
3335
+ if (BUILD.lazyLoad) throw new Error(BUILD.isDev ? `Couldn't find host element for "${cmpMeta.$tagName$}". This usually happens when integrating a 3rd party Stencil component with another Stencil runtime. See https://github.com/stenciljs/core/issues/5457` : `Host element not found for "${cmpMeta.$tagName$}"`);
3336
+ return;
3337
+ }
3338
+ const elm = BUILD.lazyLoad ? hostRef.$hostElement$ : ref;
3339
+ const oldVal = hostRef.$instanceValues$.get(propName);
3340
+ const flags = hostRef.$flags$;
3341
+ const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
3342
+ newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
3343
+ const didValueChange = newVal !== oldVal && !(Number.isNaN(oldVal) && Number.isNaN(newVal));
3344
+ if ((!BUILD.lazyLoad || !(flags & HOST_FLAGS.isConstructingInstance) || oldVal === void 0) && didValueChange) {
3345
+ hostRef.$instanceValues$.set(propName, newVal);
3346
+ const oldAttrVal = BUILD.reflect && getReflectedValue(hostRef, propName, oldVal);
3347
+ if (BUILD.serializer && BUILD.reflect && cmpMeta.$attrsToReflect$ && cmpMeta.$serializers$?.[propName]) applySerializers(hostRef, cmpMeta, propName, newVal, instance);
3348
+ if (BUILD.reflect) reflectProp(hostRef, cmpMeta, elm, propName, oldAttrVal, getReflectedValue(hostRef, propName, newVal));
3349
+ if (BUILD.isDev) {
3350
+ if (hostRef.$flags$ & HOST_FLAGS.devOnRender) consoleDevWarn(`The state/prop "${propName}" changed during rendering. This can potentially lead to infinite-loops and other bugs.`, "\nElement", elm, "\nNew value", newVal, "\nOld value", oldVal);
3351
+ else if (hostRef.$flags$ & HOST_FLAGS.devOnDidLoad) consoleDevWarn(`The state/prop "${propName}" changed during "componentDidLoad()", this triggers extra re-renders, try to setup on "componentWillLoad()"`, "\nElement", elm, "\nNew value", newVal, "\nOld value", oldVal);
3352
+ }
3353
+ if (BUILD.propChangeCallback && cmpMeta.$watchers$) {
3354
+ const watchMethods = cmpMeta.$watchers$[propName];
3355
+ if (watchMethods) watchMethods.map((watcher) => {
3356
+ try {
3357
+ const [[watchMethodName, watcherFlags]] = Object.entries(watcher);
3358
+ if (flags & HOST_FLAGS.isWatchReady || watcherFlags & WATCH_FLAGS.Immediate) {
3359
+ if (BUILD.signalBacking && !hostRef.$signalValues$) return;
3360
+ if (!instance) hostRef.$fetchedCbList$.push(() => {
3361
+ hostRef.$lazyInstance$[watchMethodName](newVal, oldVal, propName);
3362
+ });
3363
+ else instance[watchMethodName](newVal, oldVal, propName);
3364
+ }
3365
+ } catch (e) {
3366
+ consoleError(e, elm);
3367
+ }
3368
+ });
3369
+ }
3370
+ if (BUILD.updatable && flags & HOST_FLAGS.hasRendered) {
3371
+ if (instance.componentShouldUpdate) ((hostRef.$queuedPropChanges$ ||= {})[propName] ||= {
3372
+ oldVal,
3373
+ newVal
3374
+ }).newVal = newVal;
3375
+ if (!(flags & HOST_FLAGS.isQueuedForUpdate)) scheduleUpdate(hostRef, false);
3376
+ }
3377
+ }
3378
+ };
3379
+ //#endregion
3380
+ //#region src/runtime/signals-core.ts
3381
+ const getCore = () => globalThis[Symbol.for("stencil.preact-signals-core")] ??= SignalsCore;
3382
+ const effect = (fn, options) => getCore().effect(fn, options);
3383
+ const untracked = (fn) => getCore().untracked(fn);
3384
+ function signal(value, options) {
3385
+ return getCore().signal(value, options);
3386
+ }
3387
+ //#endregion
3215
3388
  //#region src/runtime/signals.ts
3216
3389
  const STENCIL_SIGNALS_SYMBOL = Symbol.for("stencil.signals");
3217
3390
  /**
@@ -3245,17 +3418,22 @@ const initializeSignals = (elm, hostRef, cmpMeta) => {
3245
3418
  disposers.push(effect(() => {
3246
3419
  const newVal = sig.value;
3247
3420
  if (hostRef.$flags$ & HOST_FLAGS.hasRendered) {
3248
- if (instance?.componentShouldUpdate) {
3249
- const changes = hostRef.$queuedPropChanges$ ||= {};
3250
- changes[memberName] = {
3251
- newVal,
3252
- oldVal: changes[memberName]?.oldVal ?? prevScheduleVal
3253
- };
3254
- }
3421
+ if (instance?.componentShouldUpdate) ((hostRef.$queuedPropChanges$ ||= {})[memberName] ||= {
3422
+ oldVal: prevScheduleVal,
3423
+ newVal
3424
+ }).newVal = newVal;
3255
3425
  if (!(hostRef.$flags$ & HOST_FLAGS.isQueuedForUpdate)) scheduleUpdate(hostRef, false);
3256
3426
  }
3257
3427
  prevScheduleVal = newVal;
3258
3428
  }));
3429
+ if (BUILD.reflect && memberFlags & MEMBER_FLAGS.ReflectAttr) {
3430
+ let prevAttrVal = getReflectedValue(hostRef, memberName, sig.peek());
3431
+ disposers.push(effect(() => {
3432
+ const attrVal = getReflectedValue(hostRef, memberName, sig.value);
3433
+ untracked(() => reflectProp(hostRef, cmpMeta, elm, memberName, prevAttrVal, attrVal));
3434
+ prevAttrVal = attrVal;
3435
+ }));
3436
+ }
3259
3437
  if (BUILD.propChangeCallback && cmpMeta.$watchers$?.[memberName]) {
3260
3438
  const watchMethods = cmpMeta.$watchers$[memberName];
3261
3439
  let prevWatchVal = sig.peek();
@@ -3324,7 +3502,7 @@ const initializeEffects = (elm, hostRef) => {
3324
3502
  * Modified for Stencil's compiler and vdom
3325
3503
  */
3326
3504
  const h = (nodeName, vnodeData, ...children) => {
3327
- if (typeof nodeName === "string") nodeName = transformTag(nodeName);
3505
+ if (typeof nodeName === "string" && nodeName.includes("-")) nodeName = transformTag(nodeName);
3328
3506
  let child = null;
3329
3507
  let key = null;
3330
3508
  let slotName = null;
@@ -3502,7 +3680,7 @@ const initializeClientHydrate = (hostElm, tagName, hostId, hostRef) => {
3502
3680
  let scopeId;
3503
3681
  if (BUILD.scoped) {
3504
3682
  const cmpMeta = hostRef.$cmpMeta$;
3505
- if (cmpMeta && cmpMeta.$flags$ & CMP_FLAGS.needsScopedEncapsulation && hostElm["s-sc"]) {
3683
+ if (cmpMeta && cmpMeta.$flags$ & (CMP_FLAGS.needsScopedEncapsulation | CMP_FLAGS.shadowNeedsScopedCss) && hostElm["s-sc"]) {
3506
3684
  scopeId = hostElm["s-sc"];
3507
3685
  hostElm.classList.add(scopeId + "-h");
3508
3686
  } else if (hostElm["s-sc"]) delete hostElm["s-sc"];
@@ -3798,7 +3976,7 @@ const addSlottedNodes = (slottedNodes, slotNodeId, slotName, slotNode, hostId) =
3798
3976
  if (!slottedNode || slottedNode.nodeValue?.startsWith("s.")) return;
3799
3977
  do {
3800
3978
  const sa = slottedNode["getAttribute"] && slottedNode.getAttribute("slot");
3801
- if ((sa || slottedNode["s-sn"]) === slotName || slotName === "" && !slottedNode["s-sn"] && !sa && (slottedNode.nodeType === NODE_TYPE.CommentNode || slottedNode.nodeType === NODE_TYPE.TextNode)) {
3979
+ if ((slottedNode["getAttribute"] && slottedNode.getAttribute("s-sn")) === slotName || (sa || slottedNode["s-sn"]) === slotName || slotName === "" && !slottedNode["s-sn"] && !sa && (slottedNode.nodeType === NODE_TYPE.CommentNode || slottedNode.nodeType === NODE_TYPE.TextNode)) {
3802
3980
  slottedNode["s-sn"] = slotName;
3803
3981
  group.push({
3804
3982
  slot: slotNode,
@@ -4320,134 +4498,6 @@ const normalizeWatchers = (raw) => {
4320
4498
  return out;
4321
4499
  };
4322
4500
  //#endregion
4323
- //#region src/runtime/parse-property-value.ts
4324
- /**
4325
- * Parse a new property value for a given property type.
4326
- *
4327
- * While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
4328
- * it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
4329
- * 1. `any`, the type given to `propValue` in the function signature
4330
- * 2. the type stored from `propType`.
4331
- *
4332
- * This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
4333
- *
4334
- * Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
4335
- * a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
4336
- * based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
4337
- * ```tsx
4338
- * <my-cmp prop-val={0}></my-cmp>
4339
- * ```
4340
- *
4341
- * HTML prop values on the other hand, will always a string
4342
- *
4343
- * @param propValue the new value to coerce to some type
4344
- * @param propType the type of the prop, expressed as a binary number
4345
- * @returns the parsed/coerced value
4346
- */
4347
- const parsePropertyValue = (propValue, propType) => {
4348
- if (propValue != null && !isComplexType(propValue)) {
4349
- /**
4350
- * ensure this value is of the correct prop type
4351
- */
4352
- if (BUILD.propBoolean && propType & MEMBER_FLAGS.Boolean) return propValue === "" || !!propValue;
4353
- /**
4354
- * force it to be a number
4355
- */
4356
- if (BUILD.propNumber && propType & MEMBER_FLAGS.Number) return typeof propValue === "string" ? parseFloat(propValue) : typeof propValue === "number" ? propValue : NaN;
4357
- /**
4358
- * could have been passed as a number or boolean but we still want it as a string
4359
- */
4360
- if (BUILD.propString && propType & MEMBER_FLAGS.String) return String(propValue);
4361
- return propValue;
4362
- }
4363
- /**
4364
- * not sure exactly what type we want so no need to change to a different type
4365
- */
4366
- return propValue;
4367
- };
4368
- //#endregion
4369
- //#region src/runtime/set-value.ts
4370
- const applySerializers = (hostRef, cmpMeta, propName, val, instance) => {
4371
- const run = (inst) => {
4372
- let attrVal = val;
4373
- for (const serializer of cmpMeta.$serializers$[propName]) {
4374
- const [[methodName]] = Object.entries(serializer);
4375
- attrVal = inst[methodName](attrVal, propName);
4376
- }
4377
- hostRef.$serializerValues$.set(propName, attrVal);
4378
- };
4379
- if (instance) run(instance);
4380
- else hostRef.$fetchedCbList$.push(() => run(hostRef.$lazyInstance$));
4381
- };
4382
- const getValue = (ref, propName) => {
4383
- if (BUILD.signalBacking) {
4384
- const sig = getHostRef(ref)?.$signalValues$?.get(propName);
4385
- if (sig !== void 0) return sig.value;
4386
- }
4387
- return getHostRef(ref).$instanceValues$.get(propName);
4388
- };
4389
- const setValue = (ref, propName, newVal, cmpMeta) => {
4390
- const hostRef = getHostRef(ref);
4391
- if (BUILD.serializer && hostRef?.$flags$ & HOST_FLAGS.isReflecting && hostRef.$serializerValues$.has(propName) && hostRef.$serializerValues$.get(propName) === newVal) return;
4392
- if (BUILD.signalBacking) {
4393
- const sig = hostRef?.$signalValues$?.get(propName);
4394
- if (sig !== void 0) {
4395
- const parsed = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
4396
- if (BUILD.serializer && BUILD.reflect && cmpMeta.$attrsToReflect$ && cmpMeta.$serializers$?.[propName]) {
4397
- const elm = BUILD.lazyLoad ? hostRef.$hostElement$ : ref;
4398
- applySerializers(hostRef, cmpMeta, propName, parsed, BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm);
4399
- }
4400
- if (!(Number.isNaN(sig.peek()) && Number.isNaN(parsed))) sig.value = parsed;
4401
- return;
4402
- }
4403
- }
4404
- if (!hostRef) {
4405
- if (BUILD.lazyLoad) throw new Error(BUILD.isDev ? `Couldn't find host element for "${cmpMeta.$tagName$}". This usually happens when integrating a 3rd party Stencil component with another Stencil runtime. See https://github.com/stenciljs/core/issues/5457` : `Host element not found for "${cmpMeta.$tagName$}"`);
4406
- return;
4407
- }
4408
- const elm = BUILD.lazyLoad ? hostRef.$hostElement$ : ref;
4409
- const oldVal = hostRef.$instanceValues$.get(propName);
4410
- const flags = hostRef.$flags$;
4411
- const instance = BUILD.lazyLoad ? hostRef.$lazyInstance$ : elm;
4412
- newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
4413
- const didValueChange = newVal !== oldVal && !(Number.isNaN(oldVal) && Number.isNaN(newVal));
4414
- if ((!BUILD.lazyLoad || !(flags & HOST_FLAGS.isConstructingInstance) || oldVal === void 0) && didValueChange) {
4415
- hostRef.$instanceValues$.set(propName, newVal);
4416
- if (BUILD.serializer && BUILD.reflect && cmpMeta.$attrsToReflect$ && cmpMeta.$serializers$?.[propName]) applySerializers(hostRef, cmpMeta, propName, newVal, instance);
4417
- if (BUILD.isDev) {
4418
- if (hostRef.$flags$ & HOST_FLAGS.devOnRender) consoleDevWarn(`The state/prop "${propName}" changed during rendering. This can potentially lead to infinite-loops and other bugs.`, "\nElement", elm, "\nNew value", newVal, "\nOld value", oldVal);
4419
- else if (hostRef.$flags$ & HOST_FLAGS.devOnDidLoad) consoleDevWarn(`The state/prop "${propName}" changed during "componentDidLoad()", this triggers extra re-renders, try to setup on "componentWillLoad()"`, "\nElement", elm, "\nNew value", newVal, "\nOld value", oldVal);
4420
- }
4421
- if (BUILD.propChangeCallback && cmpMeta.$watchers$) {
4422
- const watchMethods = cmpMeta.$watchers$[propName];
4423
- if (watchMethods) watchMethods.map((watcher) => {
4424
- try {
4425
- const [[watchMethodName, watcherFlags]] = Object.entries(watcher);
4426
- if (flags & HOST_FLAGS.isWatchReady || watcherFlags & WATCH_FLAGS.Immediate) {
4427
- if (BUILD.signalBacking && !hostRef.$signalValues$) return;
4428
- if (!instance) hostRef.$fetchedCbList$.push(() => {
4429
- hostRef.$lazyInstance$[watchMethodName](newVal, oldVal, propName);
4430
- });
4431
- else instance[watchMethodName](newVal, oldVal, propName);
4432
- }
4433
- } catch (e) {
4434
- consoleError(e, elm);
4435
- }
4436
- });
4437
- }
4438
- if (BUILD.updatable && flags & HOST_FLAGS.hasRendered) {
4439
- if (instance.componentShouldUpdate) {
4440
- const changes = hostRef.$queuedPropChanges$ ||= {};
4441
- changes[propName] = {
4442
- newVal,
4443
- oldVal: changes[propName]?.oldVal ?? oldVal
4444
- };
4445
- }
4446
- if (!(flags & HOST_FLAGS.isQueuedForUpdate)) scheduleUpdate(hostRef, false);
4447
- }
4448
- }
4449
- };
4450
- //#endregion
4451
4501
  //#region src/runtime/proxy-component.ts
4452
4502
  /**
4453
4503
  * Serialize a prop value the way `setAccessor()` does when it reflects it, so the runtime can
@@ -4690,7 +4740,10 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
4690
4740
  replayPendingSetterValues(hostRef, cmpMeta);
4691
4741
  }
4692
4742
  endNewInstance();
4693
- if (BUILD.asyncLoading && hostRef.$ancestorComponent$) await awaitAncestorConnected(hostRef.$ancestorComponent$, getHostRegistry(elm));
4743
+ if (BUILD.asyncLoading && hostRef.$ancestorComponent$) {
4744
+ const ancestorConnected = whenAncestorConnected(hostRef.$ancestorComponent$, getHostRegistry(elm));
4745
+ if (ancestorConnected) await ancestorConnected;
4746
+ }
4694
4747
  if (!(BUILD.slotRelocation && cmpMeta.$flags$ & CMP_FLAGS.hasSlotRelocation)) {
4695
4748
  fireConnectedCallback(hostRef.$lazyInstance$, elm);
4696
4749
  if (BUILD.asyncLoading) markFirstConnected(hostRef);
@@ -4752,10 +4805,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
4752
4805
  else schedule();
4753
4806
  } catch (e) {
4754
4807
  consoleError(e, elm);
4755
- if (BUILD.asyncLoading && hostRef.$onRenderResolve$) {
4756
- hostRef.$onRenderResolve$();
4757
- hostRef.$onRenderResolve$ = void 0;
4758
- }
4808
+ resolveAncestorWait(hostRef);
4759
4809
  if (BUILD.asyncLoading) markFirstConnected(hostRef);
4760
4810
  if (BUILD.asyncLoading && hostRef.$onReadyResolve$ && !(hostRef.$flags$ & HOST_FLAGS.hasFailedLoad)) hostRef.$onReadyResolve$(elm);
4761
4811
  }
@@ -5091,8 +5141,11 @@ const proxyCustomElement = (Cstr, compactMeta) => {
5091
5141
  }
5092
5142
  connectedCallback(this);
5093
5143
  if (BUILD.asyncLoading && hostRef && hostRef.$ancestorComponent$) {
5094
- await awaitAncestorConnected(hostRef.$ancestorComponent$, getHostRegistry(this));
5095
- if (!this.isConnected) return;
5144
+ const ancestorConnected = whenAncestorConnected(hostRef.$ancestorComponent$, getHostRegistry(this));
5145
+ if (ancestorConnected) {
5146
+ await ancestorConnected;
5147
+ if (!this.isConnected) return;
5148
+ }
5096
5149
  }
5097
5150
  if (originalConnectedCallback && (plt.$flags$ & PLATFORM_FLAGS.isTmpDisconnected) === 0) originalConnectedCallback.call(this);
5098
5151
  if (BUILD.asyncLoading && hostRef) markFirstConnected(hostRef);