@lwc/synthetic-shadow 9.4.6-alpha.0 → 9.5.1

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.
@@ -1,2 +1,8 @@
1
+ export declare const NativeShadowRoot: {
2
+ new (): ShadowRoot;
3
+ prototype: ShadowRoot;
4
+ };
1
5
  export declare const isInstanceOfNativeShadowRoot: (node: any) => node is ShadowRoot;
6
+ export declare const nativeShadowRootInnerHTMLDescriptor: PropertyDescriptor | undefined;
7
+ export declare const nativeShadowRootSetHTMLUnsafe: (html: string) => void;
2
8
  //# sourceMappingURL=shadow-root.d.ts.map
package/dist/index.cjs CHANGED
@@ -194,7 +194,8 @@ const KEY__SHADOW_TOKEN_PRIVATE = '$$ShadowTokenKey$$';
194
194
  const KEY__SYNTHETIC_MODE = '$$lwc-synthetic-mode';
195
195
  const KEY__NATIVE_GET_ELEMENT_BY_ID = '$nativeGetElementById$';
196
196
  const KEY__NATIVE_QUERY_SELECTOR_ALL = '$nativeQuerySelectorAll$';
197
- /** version: 9.4.6-alpha.0 */
197
+ const KEY__SANITIZE_HTML_CONTENT = '$sanitizeHtmlContent$';
198
+ /** version: 9.5.1 */
198
199
 
199
200
  /**
200
201
  * Copyright (c) 2026 Salesforce, Inc.
@@ -202,7 +203,7 @@ const KEY__NATIVE_QUERY_SELECTOR_ALL = '$nativeQuerySelectorAll$';
202
203
  if (!globalThis.lwcRuntimeFlags) {
203
204
  Object.defineProperty(globalThis, 'lwcRuntimeFlags', { value: create(null) });
204
205
  }
205
- /** version: 9.4.6-alpha.0 */
206
+ /** version: 9.5.1 */
206
207
 
207
208
  /*
208
209
  * Copyright (c) 2018, salesforce.com, inc.
@@ -360,6 +361,9 @@ const MutationObserverObserve = MO.prototype.observe;
360
361
  // Capture the global `ShadowRoot` since synthetic shadow will override it later
361
362
  const NativeShadowRoot = ShadowRoot;
362
363
  const isInstanceOfNativeShadowRoot = (node) => node instanceof NativeShadowRoot;
364
+ // Captured before synthetic shadow overrides the prototype, so the wrappers wrap the real native accessors.
365
+ const nativeShadowRootInnerHTMLDescriptor = getOwnPropertyDescriptor(NativeShadowRoot.prototype, 'innerHTML');
366
+ const nativeShadowRootSetHTMLUnsafe = NativeShadowRoot.prototype.setHTMLUnsafe;
363
367
 
364
368
  /*
365
369
  * Copyright (c) 2023, Salesforce.com, inc.
@@ -2584,6 +2588,50 @@ Object.defineProperty(window, 'ShadowRoot', {
2584
2588
  writable: true,
2585
2589
  });
2586
2590
 
2591
+ /*
2592
+ * Copyright (c) 2026, Salesforce, Inc.
2593
+ * All rights reserved.
2594
+ * SPDX-License-Identifier: MIT
2595
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2596
+ */
2597
+ // This hook is set as a global because this package bundles a separate copy of `@lwc/shared` from the runtime,
2598
+ // so the `setHooks` it has access to is not the one where hooks are set.
2599
+ function maybeSanitize(value) {
2600
+ if (lwcRuntimeFlags.DISABLE_NATIVE_SHADOWROOT_SINK_SANITIZATION) {
2601
+ return value;
2602
+ }
2603
+ const sanitize = globalThis[KEY__SANITIZE_HTML_CONTENT];
2604
+ return isFunction(sanitize) ? sanitize(value) : value;
2605
+ }
2606
+ // Our wrappers install as non-configurable, so a non-configurable descriptor already means one is
2607
+ // in place — use that as the idempotency signal instead of a separate marker property.
2608
+ function isLocked(proto, name) {
2609
+ const descriptor = getOwnPropertyDescriptor(proto, name);
2610
+ return descriptor?.configurable === false;
2611
+ }
2612
+ if (isFunction(nativeShadowRootInnerHTMLDescriptor?.set) &&
2613
+ !isLocked(NativeShadowRoot.prototype, 'innerHTML')) {
2614
+ const nativeInnerHTMLSetter = nativeShadowRootInnerHTMLDescriptor.set;
2615
+ defineProperty(NativeShadowRoot.prototype, 'innerHTML', {
2616
+ ...nativeShadowRootInnerHTMLDescriptor,
2617
+ configurable: false,
2618
+ set(value) {
2619
+ nativeInnerHTMLSetter.call(this, maybeSanitize(value));
2620
+ },
2621
+ });
2622
+ }
2623
+ if (isFunction(nativeShadowRootSetHTMLUnsafe) &&
2624
+ !isLocked(NativeShadowRoot.prototype, 'setHTMLUnsafe')) {
2625
+ defineProperty(NativeShadowRoot.prototype, 'setHTMLUnsafe', {
2626
+ writable: false,
2627
+ enumerable: true,
2628
+ configurable: false,
2629
+ value(html) {
2630
+ return nativeShadowRootSetHTMLUnsafe.call(this, maybeSanitize(html));
2631
+ },
2632
+ });
2633
+ }
2634
+
2587
2635
  /*
2588
2636
  * Copyright (c) 2018, salesforce.com, inc.
2589
2637
  * All rights reserved.
@@ -4359,6 +4407,6 @@ defineProperty(Element.prototype, '$domManual$', {
4359
4407
  },
4360
4408
  configurable: true,
4361
4409
  });
4362
- /** version: 9.4.6-alpha.0 */
4410
+ /** version: 9.5.1 */
4363
4411
  }
4364
4412
  //# sourceMappingURL=index.cjs.map
package/dist/index.js CHANGED
@@ -192,7 +192,8 @@ const KEY__SHADOW_TOKEN_PRIVATE = '$$ShadowTokenKey$$';
192
192
  const KEY__SYNTHETIC_MODE = '$$lwc-synthetic-mode';
193
193
  const KEY__NATIVE_GET_ELEMENT_BY_ID = '$nativeGetElementById$';
194
194
  const KEY__NATIVE_QUERY_SELECTOR_ALL = '$nativeQuerySelectorAll$';
195
- /** version: 9.4.6-alpha.0 */
195
+ const KEY__SANITIZE_HTML_CONTENT = '$sanitizeHtmlContent$';
196
+ /** version: 9.5.1 */
196
197
 
197
198
  /**
198
199
  * Copyright (c) 2026 Salesforce, Inc.
@@ -200,7 +201,7 @@ const KEY__NATIVE_QUERY_SELECTOR_ALL = '$nativeQuerySelectorAll$';
200
201
  if (!globalThis.lwcRuntimeFlags) {
201
202
  Object.defineProperty(globalThis, 'lwcRuntimeFlags', { value: create(null) });
202
203
  }
203
- /** version: 9.4.6-alpha.0 */
204
+ /** version: 9.5.1 */
204
205
 
205
206
  /*
206
207
  * Copyright (c) 2018, salesforce.com, inc.
@@ -358,6 +359,9 @@ const MutationObserverObserve = MO.prototype.observe;
358
359
  // Capture the global `ShadowRoot` since synthetic shadow will override it later
359
360
  const NativeShadowRoot = ShadowRoot;
360
361
  const isInstanceOfNativeShadowRoot = (node) => node instanceof NativeShadowRoot;
362
+ // Captured before synthetic shadow overrides the prototype, so the wrappers wrap the real native accessors.
363
+ const nativeShadowRootInnerHTMLDescriptor = getOwnPropertyDescriptor(NativeShadowRoot.prototype, 'innerHTML');
364
+ const nativeShadowRootSetHTMLUnsafe = NativeShadowRoot.prototype.setHTMLUnsafe;
361
365
 
362
366
  /*
363
367
  * Copyright (c) 2023, Salesforce.com, inc.
@@ -2582,6 +2586,50 @@ Object.defineProperty(window, 'ShadowRoot', {
2582
2586
  writable: true,
2583
2587
  });
2584
2588
 
2589
+ /*
2590
+ * Copyright (c) 2026, Salesforce, Inc.
2591
+ * All rights reserved.
2592
+ * SPDX-License-Identifier: MIT
2593
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2594
+ */
2595
+ // This hook is set as a global because this package bundles a separate copy of `@lwc/shared` from the runtime,
2596
+ // so the `setHooks` it has access to is not the one where hooks are set.
2597
+ function maybeSanitize(value) {
2598
+ if (lwcRuntimeFlags.DISABLE_NATIVE_SHADOWROOT_SINK_SANITIZATION) {
2599
+ return value;
2600
+ }
2601
+ const sanitize = globalThis[KEY__SANITIZE_HTML_CONTENT];
2602
+ return isFunction(sanitize) ? sanitize(value) : value;
2603
+ }
2604
+ // Our wrappers install as non-configurable, so a non-configurable descriptor already means one is
2605
+ // in place — use that as the idempotency signal instead of a separate marker property.
2606
+ function isLocked(proto, name) {
2607
+ const descriptor = getOwnPropertyDescriptor(proto, name);
2608
+ return descriptor?.configurable === false;
2609
+ }
2610
+ if (isFunction(nativeShadowRootInnerHTMLDescriptor?.set) &&
2611
+ !isLocked(NativeShadowRoot.prototype, 'innerHTML')) {
2612
+ const nativeInnerHTMLSetter = nativeShadowRootInnerHTMLDescriptor.set;
2613
+ defineProperty(NativeShadowRoot.prototype, 'innerHTML', {
2614
+ ...nativeShadowRootInnerHTMLDescriptor,
2615
+ configurable: false,
2616
+ set(value) {
2617
+ nativeInnerHTMLSetter.call(this, maybeSanitize(value));
2618
+ },
2619
+ });
2620
+ }
2621
+ if (isFunction(nativeShadowRootSetHTMLUnsafe) &&
2622
+ !isLocked(NativeShadowRoot.prototype, 'setHTMLUnsafe')) {
2623
+ defineProperty(NativeShadowRoot.prototype, 'setHTMLUnsafe', {
2624
+ writable: false,
2625
+ enumerable: true,
2626
+ configurable: false,
2627
+ value(html) {
2628
+ return nativeShadowRootSetHTMLUnsafe.call(this, maybeSanitize(html));
2629
+ },
2630
+ });
2631
+ }
2632
+
2585
2633
  /*
2586
2634
  * Copyright (c) 2018, salesforce.com, inc.
2587
2635
  * All rights reserved.
@@ -4357,6 +4405,6 @@ defineProperty(Element.prototype, '$domManual$', {
4357
4405
  },
4358
4406
  configurable: true,
4359
4407
  });
4360
- /** version: 9.4.6-alpha.0 */
4408
+ /** version: 9.5.1 */
4361
4409
  }
4362
4410
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,3 @@
1
1
  import './polyfill';
2
+ import './sanitize-native-sink';
2
3
  //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=sanitize-native-sink.d.ts.map
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "You can safely modify dependencies, devDependencies, keywords, etc., but other props will be overwritten."
5
5
  ],
6
6
  "name": "@lwc/synthetic-shadow",
7
- "version": "9.4.6-alpha.0",
7
+ "version": "9.5.1",
8
8
  "description": "Synthetic Shadow Root for LWC",
9
9
  "keywords": [
10
10
  "lwc"
@@ -51,8 +51,8 @@
51
51
  }
52
52
  },
53
53
  "devDependencies": {
54
- "@lwc/features": "9.4.6-alpha.0",
55
- "@lwc/shared": "9.4.6-alpha.0"
54
+ "@lwc/features": "9.5.1",
55
+ "@lwc/shared": "9.5.1"
56
56
  },
57
57
  "lwc": {
58
58
  "modules": [