@lwc/synthetic-shadow 6.3.4 → 6.4.1

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -208,7 +208,7 @@ const KEY__LEGACY_SHADOW_TOKEN_PRIVATE = '$$LegacyShadowTokenKey$$';
208
208
  const KEY__SYNTHETIC_MODE = '$$lwc-synthetic-mode';
209
209
  const KEY__NATIVE_GET_ELEMENT_BY_ID = '$nativeGetElementById$';
210
210
  const KEY__NATIVE_QUERY_SELECTOR_ALL = '$nativeQuerySelectorAll$';
211
- /** version: 6.3.4 */
211
+ /** version: 6.4.1 */
212
212
 
213
213
  /**
214
214
  * Copyright (c) 2024 Salesforce, Inc.
@@ -216,7 +216,7 @@ const KEY__NATIVE_QUERY_SELECTOR_ALL = '$nativeQuerySelectorAll$';
216
216
  if (!globalThis.lwcRuntimeFlags) {
217
217
  Object.defineProperty(globalThis, 'lwcRuntimeFlags', { value: create(null) });
218
218
  }
219
- /** version: 6.3.4 */
219
+ /** version: 6.4.1 */
220
220
 
221
221
  /*
222
222
  * Copyright (c) 2018, salesforce.com, inc.
@@ -239,6 +239,7 @@ const ownerDocumentGetter = getOwnPropertyDescriptor(nodePrototype, 'ownerDocume
239
239
  const parentElementGetter = getOwnPropertyDescriptor(nodePrototype, 'parentElement').get;
240
240
  const textContextSetter = getOwnPropertyDescriptor(nodePrototype, 'textContent').set;
241
241
  const childNodesGetter = getOwnPropertyDescriptor(nodePrototype, 'childNodes').get;
242
+ const nextSiblingGetter = getOwnPropertyDescriptor(nodePrototype, 'nextSibling').get;
242
243
  const isConnected = hasOwnProperty.call(nodePrototype, 'isConnected')
243
244
  ? getOwnPropertyDescriptor(nodePrototype, 'isConnected').get
244
245
  : function () {
@@ -425,6 +426,8 @@ function getNodeNearestOwnerKey(node) {
425
426
  return hostKey;
426
427
  }
427
428
  host = parentNodeGetter.call(host);
429
+ // Elements slotted from top level light DOM into synthetic shadow
430
+ // reach the slot tag from the shadow element first
428
431
  if (!isNull(host) && isSyntheticSlotElement(host)) {
429
432
  return undefined;
430
433
  }
@@ -1225,7 +1228,11 @@ function cloneNodePatched(deep) {
1225
1228
  function childNodesGetterPatched() {
1226
1229
  if (isSyntheticShadowHost(this)) {
1227
1230
  const owner = getNodeOwner(this);
1228
- const childNodes = isNull(owner) ? [] : getAllMatches(owner, getFilteredChildNodes(this));
1231
+ const filteredChildNodes = getFilteredChildNodes(this);
1232
+ // No need to filter by owner for non-shadowed nodes
1233
+ const childNodes = isNull(owner)
1234
+ ? filteredChildNodes
1235
+ : getAllMatches(owner, filteredChildNodes);
1229
1236
  return createStaticNodeList(childNodes);
1230
1237
  }
1231
1238
  // nothing to do here since this does not have a synthetic shadow attached to it
@@ -3354,7 +3361,11 @@ function shadowRootGetterPatched() {
3354
3361
  }
3355
3362
  function childrenGetterPatched() {
3356
3363
  const owner = getNodeOwner(this);
3357
- const childNodes = isNull(owner) ? [] : getAllMatches(owner, getFilteredChildNodes(this));
3364
+ const filteredChildNodes = getFilteredChildNodes(this);
3365
+ // No need to filter by owner for non-shadowed nodes
3366
+ const childNodes = isNull(owner)
3367
+ ? filteredChildNodes
3368
+ : getAllMatches(owner, filteredChildNodes);
3358
3369
  return createStaticHTMLCollection(ArrayFilter.call(childNodes, (node) => node instanceof Element));
3359
3370
  }
3360
3371
  function childElementCountGetterPatched() {
@@ -4190,9 +4201,13 @@ defineProperty(Element.prototype, KEY__SHADOW_TOKEN, {
4190
4201
  });
4191
4202
  function recursivelySetShadowResolver(node, fn) {
4192
4203
  node[KEY__SHADOW_RESOLVER] = fn;
4193
- const childNodes = childNodesGetter.call(node);
4194
- for (let i = 0, n = childNodes.length; i < n; i++) {
4195
- recursivelySetShadowResolver(childNodes[i], fn);
4204
+ // Recurse using firstChild/nextSibling because browsers use a linked list under the hood to
4205
+ // represent the DOM, so childNodes/children would cause an unnecessary array allocation.
4206
+ // https://viethung.space/blog/2020/09/01/Browser-from-Scratch-DOM-API/#Choosing-DOM-tree-data-structure
4207
+ let child = firstChildGetter.call(node);
4208
+ while (!isNull(child)) {
4209
+ recursivelySetShadowResolver(child, fn);
4210
+ child = nextSiblingGetter.call(child);
4196
4211
  }
4197
4212
  }
4198
4213
  defineProperty(Element.prototype, KEY__SHADOW_STATIC, {
@@ -4361,6 +4376,6 @@ defineProperty(Element.prototype, '$domManual$', {
4361
4376
  },
4362
4377
  configurable: true,
4363
4378
  });
4364
- /** version: 6.3.4 */
4379
+ /** version: 6.4.1 */
4365
4380
  }
4366
4381
  //# sourceMappingURL=index.js.map