@stencil/core 5.0.0-rc.15 → 5.0.0-rc.17

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.
@@ -33,7 +33,7 @@ import "@rollup/pluginutils";
33
33
  import { createHash } from "crypto";
34
34
  import { afterAll, vi } from "vitest";
35
35
  //#region src/version.ts
36
- const version = "5.0.0-rc.15";
36
+ const version = "5.0.0-rc.17";
37
37
  const MEMBER_FLAGS = {
38
38
  String: 1,
39
39
  Number: 2,
@@ -582,7 +582,6 @@ const escapeRegExpSpecialCharacters = (text) => {
582
582
  */
583
583
  const BUILD = {
584
584
  allRenderFn: false,
585
- element: true,
586
585
  event: true,
587
586
  hasRenderFn: true,
588
587
  hostListener: true,
@@ -1282,19 +1281,28 @@ const getSlottedChildNodes = (childNodes) => {
1282
1281
  * @returns a reference to the slot node that matches the provided name, `null` otherwise
1283
1282
  */
1284
1283
  function getHostSlotNodes(childNodes, hostName, slotName) {
1285
- let i = 0;
1286
- let slottedNodes = [];
1287
- let childNode;
1288
- for (; i < childNodes.length; i++) {
1289
- childNode = childNodes[i];
1284
+ const slotNodes = [];
1285
+ collectHostSlotNodes(childNodes, hostName, slotName, slotNodes);
1286
+ return slotNodes;
1287
+ }
1288
+ /**
1289
+ * Pre-order walk for {@link getHostSlotNodes}, appending to `out`.
1290
+ * @param childNodes the nodes to search
1291
+ * @param hostName the host name of the slot to match on
1292
+ * @param slotName the name of the slot to match on; stops at the first match when given
1293
+ * @param out the matching slot nodes, in document order
1294
+ * @returns true once a named slot has been found
1295
+ */
1296
+ function collectHostSlotNodes(childNodes, hostName, slotName, out) {
1297
+ for (let i = 0; i < childNodes.length; i++) {
1298
+ const childNode = childNodes[i];
1290
1299
  if (childNode["s-sr"] && (!hostName || childNode["s-hn"] === hostName) && (slotName === void 0 || getSlotName(childNode) === slotName)) {
1291
- slottedNodes.push(childNode);
1292
- if (typeof slotName !== "undefined") return slottedNodes;
1300
+ out.push(childNode);
1301
+ if (slotName !== void 0) return true;
1293
1302
  }
1294
- slottedNodes = [...slottedNodes, ...getHostSlotNodes(internalCall(childNode, "childNodes"), hostName, slotName)];
1295
- if (typeof slotName !== "undefined" && slottedNodes.length) return slottedNodes;
1303
+ if (collectHostSlotNodes(internalCall(childNode, "childNodes"), hostName, slotName, out) && slotName !== void 0) return true;
1296
1304
  }
1297
- return slottedNodes;
1305
+ return false;
1298
1306
  }
1299
1307
  /**
1300
1308
  * Get all 'child' sibling nodes of a slot node
@@ -1413,11 +1421,40 @@ function findSlotFromSlottedNode(slottedNode, parentHost) {
1413
1421
  slotName: ""
1414
1422
  };
1415
1423
  const slotName = slottedNode["s-sn"] = getSlotName(slottedNode) || "";
1424
+ let hostSlots = slotNodeCache.get(parentHost);
1425
+ const cached = hostSlots?.get(slotName);
1426
+ if (cached && isHostSlot(cached, parentHost, slotName)) return {
1427
+ slotNode: cached,
1428
+ slotName
1429
+ };
1430
+ const slotNode = getHostSlotNodes(internalCall(parentHost, "childNodes"), parentHost.tagName, slotName)[0];
1431
+ if (slotNode) {
1432
+ if (!hostSlots) slotNodeCache.set(parentHost, hostSlots = /* @__PURE__ */ new Map());
1433
+ hostSlots.set(slotName, slotNode);
1434
+ }
1416
1435
  return {
1417
- slotNode: getHostSlotNodes(internalCall(parentHost, "childNodes"), parentHost.tagName, slotName)[0],
1436
+ slotNode,
1418
1437
  slotName
1419
1438
  };
1420
1439
  }
1440
+ /**
1441
+ * The slot node last found per host and slot name. Each slotted child of a host looks up its
1442
+ * slot, and a full search walks the host's whole internal tree, so a host with many slotted
1443
+ * children would otherwise cost O(children × tree).
1444
+ */
1445
+ const slotNodeCache = /* @__PURE__ */ new WeakMap();
1446
+ /**
1447
+ * Whether a cached slot node is still the host's slot of that name.
1448
+ * @param slotNode the cached slot node
1449
+ * @param host the host element
1450
+ * @param slotName the slot name
1451
+ * @returns true if `slotNode` is still a slot of `host` named `slotName`, inside its internal tree
1452
+ */
1453
+ const isHostSlot = (slotNode, host, slotName) => {
1454
+ if (!slotNode["s-sr"] || slotNode["s-hn"] !== host.tagName || getSlotName(slotNode) !== slotName) return false;
1455
+ for (let n = internalCall(slotNode, "parentNode"); n; n = internalCall(n, "parentNode")) if (n === host) return true;
1456
+ return false;
1457
+ };
1421
1458
  //#endregion
1422
1459
  //#region src/runtime/dom-extras.ts
1423
1460
  const applyLightDomPatches = (hostElementPrototype) => {
@@ -3090,8 +3127,7 @@ const insertBefore = (parent, newNode, reference, isInitialLoad) => {
3090
3127
  if (parent?.["s-cr"]) checkSlotRelocate = true;
3091
3128
  if (BUILD.scoped && typeof newNode["s-sn"] === "string" && !!newNode["s-sr"] && !!newNode["s-cr"]) addRemoveSlotScopedClass(newNode["s-cr"], newNode, parent, newNode.parentElement);
3092
3129
  else if (typeof newNode["s-sn"] === "string") {
3093
- const hostElm = newNode["s-hn"] && parent.closest?.(newNode["s-hn"]);
3094
- if ((BUILD.lightDomPatches || BUILD.slotChildNodes || BUILD.patchAll && !!(hostElm && getHostRef(hostElm)?.$cmpMeta$.$flags$ & CMP_FLAGS.patchAll)) && parent.getRootNode().nodeType !== NODE_TYPES.DOCUMENT_FRAGMENT_NODE) patchSlottedNode(newNode);
3130
+ if ((BUILD.lightDomPatches || BUILD.slotChildNodes || BUILD.patchAll && hostPatchesAll(newNode, parent)) && parent.getRootNode().nodeType !== NODE_TYPES.DOCUMENT_FRAGMENT_NODE) patchSlottedNode(newNode);
3095
3131
  parent.insertBefore(newNode, reference);
3096
3132
  const { slotNode } = findSlotFromSlottedNode(newNode);
3097
3133
  if (slotNode) {
@@ -3105,6 +3141,16 @@ const insertBefore = (parent, newNode, reference, isInitialLoad) => {
3105
3141
  else return parent?.insertBefore(newNode, reference);
3106
3142
  };
3107
3143
  /**
3144
+ * Whether the host a slotted node belongs to opted into `patchAll`.
3145
+ * @param newNode the slotted node
3146
+ * @param parent the node it is being inserted into
3147
+ * @returns true if the host component has the `patchAll` flag
3148
+ */
3149
+ const hostPatchesAll = (newNode, parent) => {
3150
+ const hostElm = newNode["s-hn"] && parent.closest?.(newNode["s-hn"]);
3151
+ return !!(hostElm && getHostRef(hostElm)?.$cmpMeta$.$flags$ & CMP_FLAGS.patchAll);
3152
+ };
3153
+ /**
3108
3154
  * Adds or removes a scoped class to the parent element of a slotted node.
3109
3155
  * This is used for styling slotted content (e.g. with `::scoped(...) {...}` selectors )
3110
3156
  * in `scoped: true` components.
@@ -4325,6 +4371,11 @@ const initializeDocumentHydrate = (node, orgLocNodes) => {
4325
4371
  const createSimpleVNode = (vnode) => ({
4326
4372
  $flags$: 0,
4327
4373
  $index$: "0",
4374
+ $tag$: null,
4375
+ $text$: null,
4376
+ $key$: null,
4377
+ $name$: null,
4378
+ $attrs$: null,
4328
4379
  $children$: null,
4329
4380
  ...vnode
4330
4381
  });
@@ -4589,7 +4640,7 @@ const insertPolyfillHostInCssText = (cssText) => {
4589
4640
  const _colonHostContextRe = createSupportsRuleRe(":host-context");
4590
4641
  cssText = cssText.replace(_colonHostContextRe, `$1${_polyfillHostContext}`).replace(_colonHostRe, `$1${_polyfillHost}`).replace(_colonSlottedRe, `$1${_polyfillSlotted}`);
4591
4642
  supportsBlocks.forEach((originalSelector, index) => {
4592
- cssText = cssText.replace(`__supports_${index}__`, originalSelector);
4643
+ cssText = cssText.replace(`__supports_${index}__`, () => originalSelector);
4593
4644
  });
4594
4645
  return cssText;
4595
4646
  };
@@ -4822,11 +4873,11 @@ const scopeCss = (cssText, scopeId, commentOriginalSelector) => {
4822
4873
  const scoped = scopeCssText(cssText, scopeId, hostScopeId, slotScopeId, commentOriginalSelector);
4823
4874
  cssText = [scoped.cssText, ...commentsWithHash].join("\n");
4824
4875
  if (commentOriginalSelector) orgSelectors.forEach(({ placeholder, comment }) => {
4825
- cssText = cssText.replace(placeholder, comment);
4876
+ cssText = cssText.replace(placeholder, () => comment);
4826
4877
  });
4827
4878
  scoped.slottedSelectors.forEach((slottedSelector) => {
4828
4879
  const regex = new RegExp(escapeRegExpSpecialCharacters(slottedSelector.orgSelector) + "(?=\\s*[,{]|$)", "g");
4829
- cssText = cssText.replace(regex, slottedSelector.updatedSelector);
4880
+ cssText = cssText.replace(regex, () => slottedSelector.updatedSelector);
4830
4881
  });
4831
4882
  cssText = expandPartSelectors(cssText);
4832
4883
  return cssText;
@@ -5067,6 +5118,28 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
5067
5118
  };
5068
5119
  //#endregion
5069
5120
  //#region src/runtime/initialize-component.ts
5121
+ /** Distinct style texts kept; an app has one per component and mode. */
5122
+ const SSR_CSS_CACHE_MAX = 1e3;
5123
+ /**
5124
+ * Memoizes a server-side rewrite of a component's style text. The rewrites are pure, but the
5125
+ * platform (and its `styles` registry) is rebuilt per render, so without this they'd rerun on
5126
+ * every render.
5127
+ * @param style the component's style text
5128
+ * @param key what the rewrite depends on besides the text
5129
+ * @param rewrite computes the result
5130
+ * @returns the rewritten style
5131
+ */
5132
+ const ssrCachedCss = (style, key, rewrite) => {
5133
+ if (typeof $stencilSsrCssCache === "undefined" || typeof style !== "string") return rewrite();
5134
+ let byKey = $stencilSsrCssCache.get(style);
5135
+ if (!byKey) {
5136
+ if ($stencilSsrCssCache.size >= SSR_CSS_CACHE_MAX) $stencilSsrCssCache.clear();
5137
+ $stencilSsrCssCache.set(style, byKey = /* @__PURE__ */ new Map());
5138
+ }
5139
+ let result = byKey.get(key);
5140
+ if (result === void 0) byKey.set(key, result = rewrite());
5141
+ return result;
5142
+ };
5070
5143
  /**
5071
5144
  * Initialize a Stencil component given a reference to its host element, its
5072
5145
  * runtime bookkeeping data structure, runtime metadata about the component,
@@ -5167,8 +5240,8 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
5167
5240
  if (!styles.has(scopeId) || BUILD.hotModuleReplacement && hmrVersionId) {
5168
5241
  const endRegisterStyles = createTime("registerStyles", cmpMeta.$tagName$);
5169
5242
  if (BUILD.hydrateServerSide && BUILD.shadowDom) {
5170
- if (cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss) style = scopeCss(style, scopeId, true);
5171
- else if (needsScopedSSR()) style = expandPartSelectors(style);
5243
+ if (cmpMeta.$flags$ & CMP_FLAGS.shadowNeedsScopedCss) style = ssrCachedCss(style, `s:${scopeId}`, () => scopeCss(style, scopeId, true));
5244
+ else if (needsScopedSSR()) style = ssrCachedCss(style, "p", () => expandPartSelectors(style));
5172
5245
  }
5173
5246
  registerStyle(scopeId, style, !!(cmpMeta.$flags$ & CMP_FLAGS.shadowDomEncapsulation));
5174
5247
  endRegisterStyles();
@@ -6070,7 +6143,6 @@ const getBuildFeatures = (cmps) => {
6070
6143
  allRenderFn: cmps.every((c) => c.hasRenderFn),
6071
6144
  formAssociated: cmps.some((c) => c.formAssociated),
6072
6145
  deserializer: cmps.some((c) => c.hasDeserializer),
6073
- element: cmps.some((c) => c.hasElement),
6074
6146
  event: cmps.some((c) => c.hasEvent),
6075
6147
  hasRenderFn: cmps.some((c) => c.hasRenderFn),
6076
6148
  lifecycle: cmps.some((c) => c.hasLifecycle),
@@ -7960,7 +8032,6 @@ const mockComponentMeta = (overrides = {}) => ({
7960
8032
  hasConnectedCallbackFn: false,
7961
8033
  hasDeserializer: false,
7962
8034
  hasDisconnectedCallbackFn: false,
7963
- hasElement: false,
7964
8035
  hasEvent: false,
7965
8036
  hasLifecycle: false,
7966
8037
  hasListener: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/core",
3
- "version": "5.0.0-rc.15",
3
+ "version": "5.0.0-rc.17",
4
4
  "description": "A Compiler for Web Components and Progressive Web Apps",
5
5
  "keywords": [
6
6
  "components",
@@ -92,10 +92,6 @@
92
92
  "types": "./dist/runtime/server/index.d.mts",
93
93
  "import": "./dist/runtime/server/index.mjs"
94
94
  },
95
- "./runtime/server/runner": {
96
- "types": "./dist/runtime/server/runner.d.mts",
97
- "import": "./dist/runtime/server/runner.mjs"
98
- },
99
95
  "./sys/node": {
100
96
  "types": "./dist/sys/node/index.d.mts",
101
97
  "import": "./dist/sys/node/index.mjs"
@@ -126,9 +122,9 @@
126
122
  "terser": "^5.50.0",
127
123
  "tinyglobby": "^0.2.17",
128
124
  "typescript": ">5.0.0 <7.0.0",
129
- "@stencil/cli": "5.0.0-rc.15",
130
- "@stencil/dev-server": "5.0.0-rc.15",
131
- "@stencil/mock-doc": "5.0.0-rc.15"
125
+ "@stencil/mock-doc": "5.0.0-rc.17",
126
+ "@stencil/cli": "5.0.0-rc.17",
127
+ "@stencil/dev-server": "5.0.0-rc.17"
132
128
  },
133
129
  "devDependencies": {
134
130
  "@ionic/prettier-config": "^4.0.0",