@lwc/engine-core 8.1.3 → 8.3.0

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.
package/README.md CHANGED
@@ -115,3 +115,9 @@ This experimental API enables the sanitization of HTML content by external servi
115
115
  ### unwrap()
116
116
 
117
117
  This experimental API enables the removal of an object's observable membrane proxy wrapper.
118
+
119
+ ### setTrustedSignalSet()
120
+
121
+ This experimental API enables the addition of a signal as a trusted signal. If the [ENABLE_EXPERIMENTAL_SIGNALS](https://github.com/salesforce/lwc/blob/master/packages/%40lwc/features/README.md#lwcfeatures) feature is enabled, any signal value change will trigger a re-render.
122
+
123
+ If `setTrustedSignalSet` is called more than once, it will throw an error. If it is never called, then no trusted signal validation will be performed. The same `setTrustedSignalSet` API must be called on both `@lwc/engine-dom` and `@lwc/signals`.
@@ -28,3 +28,4 @@ export { default as track } from './decorators/track';
28
28
  export { default as wire } from './decorators/wire';
29
29
  export { readonly } from './readonly';
30
30
  export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
31
+ export { setTrustedSignalSet } from '@lwc/shared';
@@ -1,4 +1,4 @@
1
- import { ShadowMode, ShadowSupportMode } from './vm';
1
+ import { RenderMode, ShadowMode, ShadowSupportMode } from './vm';
2
2
  export declare const enum ReportingEventId {
3
3
  CrossRootAriaInSyntheticShadow = "CrossRootAriaInSyntheticShadow",
4
4
  CompilerRuntimeVersionMismatch = "CompilerRuntimeVersionMismatch",
@@ -7,7 +7,8 @@ export declare const enum ReportingEventId {
7
7
  StylesheetMutation = "StylesheetMutation",
8
8
  ConnectedCallbackWhileDisconnected = "ConnectedCallbackWhileDisconnected",
9
9
  ShadowModeUsage = "ShadowModeUsage",
10
- ShadowSupportModeUsage = "ShadowSupportModeUsage"
10
+ ShadowSupportModeUsage = "ShadowSupportModeUsage",
11
+ RenderModeMismatch = "RenderModeMismatch"
11
12
  }
12
13
  export interface BasePayload {
13
14
  tagName?: string;
@@ -32,6 +33,9 @@ export interface StylesheetMutationPayload extends BasePayload {
32
33
  }
33
34
  export interface ConnectedCallbackWhileDisconnectedPayload extends BasePayload {
34
35
  }
36
+ export interface RenderModeMismatchPayload extends BasePayload {
37
+ mode: RenderMode;
38
+ }
35
39
  export interface ShadowModeUsagePayload extends BasePayload {
36
40
  mode: ShadowMode;
37
41
  }
@@ -47,6 +51,7 @@ export type ReportingPayloadMapping = {
47
51
  [ReportingEventId.ConnectedCallbackWhileDisconnected]: ConnectedCallbackWhileDisconnectedPayload;
48
52
  [ReportingEventId.ShadowModeUsage]: ShadowModeUsagePayload;
49
53
  [ReportingEventId.ShadowSupportModeUsage]: ShadowSupportModeUsagePayload;
54
+ [ReportingEventId.RenderModeMismatch]: RenderModeMismatchPayload;
50
55
  };
51
56
  export type ReportingDispatcher<T extends ReportingEventId = ReportingEventId> = (reportingEventId: T, payload: ReportingPayloadMapping[T]) => void;
52
57
  /** Callbacks to invoke when reporting is enabled */
package/dist/index.cjs.js CHANGED
@@ -602,6 +602,7 @@ function componentValueObserved(vm, key, target = {}) {
602
602
  'value' in target &&
603
603
  'subscribe' in target &&
604
604
  shared.isFunction(target.subscribe) &&
605
+ shared.isTrustedSignal(target) &&
605
606
  // Only subscribe if a template is being rendered by the engine
606
607
  tro.isObserving()) {
607
608
  // Subscribe the template reactive observer's notify method, which will mark the vm as dirty and schedule hydration.
@@ -3920,6 +3921,12 @@ function isVStaticPartText(vnode) {
3920
3921
  return vnode.type === 0 /* VStaticPartType.Text */;
3921
3922
  }
3922
3923
 
3924
+ /*
3925
+ * Copyright (c) 2024, Salesforce, Inc.
3926
+ * All rights reserved.
3927
+ * SPDX-License-Identifier: MIT
3928
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3929
+ */
3923
3930
  const sanitizedHtmlContentSymbol = Symbol('lwc-get-sanitized-html-content');
3924
3931
  function isSanitizedHtmlContent(object) {
3925
3932
  return shared.isObject(object) && !shared.isNull(object) && sanitizedHtmlContentSymbol in object;
@@ -6176,19 +6183,30 @@ function validateSlots(vm) {
6176
6183
  shared.assert.isTrue(shared.isArray(cmpSlots.slotAssignments[slotName]), `Slots can only be set to an array, instead received ${shared.toString(cmpSlots.slotAssignments[slotName])} for slot "${slotName}" in ${vm}.`);
6177
6184
  }
6178
6185
  }
6179
- function validateLightDomTemplate(template, vm) {
6180
- assertNotProd(); // should never leak to prod mode
6181
- if (template === defaultEmptyTemplate) {
6186
+ function checkHasMatchingRenderMode(template, vm) {
6187
+ // don't validate in prod environments where reporting is disabled
6188
+ if (process.env.NODE_ENV === 'production' && !isReportingEnabled()) {
6182
6189
  return;
6183
6190
  }
6184
- if (vm.renderMode === 0 /* RenderMode.Light */) {
6185
- if (template.renderMode !== 'light') {
6186
- logError(`Light DOM components can't render shadow DOM templates. Add an 'lwc:render-mode="light"' directive to the root template tag of ${getComponentTag(vm)}.`);
6187
- }
6191
+ // don't validate the default empty template - it is not inherently light or shadow
6192
+ if (template === defaultEmptyTemplate) {
6193
+ return;
6188
6194
  }
6189
- else {
6190
- if (!shared.isUndefined(template.renderMode)) {
6191
- logError(`Shadow DOM components template can't render light DOM templates. Either remove the 'lwc:render-mode' directive from ${getComponentTag(vm)} or set it to 'lwc:render-mode="shadow"`);
6195
+ // TODO [#4663]: `renderMode` mismatch between template and component causes `console.error` but no error
6196
+ // Note that `undefined` means shadow in this case, because shadow is the default.
6197
+ const vmIsLight = vm.renderMode === 0 /* RenderMode.Light */;
6198
+ const templateIsLight = template.renderMode === 'light';
6199
+ if (vmIsLight !== templateIsLight) {
6200
+ report("RenderModeMismatch" /* ReportingEventId.RenderModeMismatch */, {
6201
+ tagName: vm.tagName,
6202
+ mode: vm.renderMode,
6203
+ });
6204
+ if (process.env.NODE_ENV !== 'production') {
6205
+ const tagName = getComponentTag(vm);
6206
+ const message = vmIsLight
6207
+ ? `Light DOM components can't render shadow DOM templates. Add an 'lwc:render-mode="light"' directive to the root template tag of ${tagName}.`
6208
+ : `Shadow DOM components template can't render light DOM templates. Either remove the 'lwc:render-mode' directive from ${tagName} or set it to 'lwc:render-mode="shadow"`;
6209
+ logError(message);
6192
6210
  }
6193
6211
  }
6194
6212
  }
@@ -6403,9 +6421,7 @@ function evaluateTemplate(vm, html) {
6403
6421
  if (!isTemplateRegistered(html)) {
6404
6422
  throw new TypeError(`Invalid template returned by the render() method on ${vm.tagName}. It must return an imported template (e.g.: \`import html from "./${vm.def.name}.html"\`), instead, it has returned: ${shared.toString(html)}.`);
6405
6423
  }
6406
- if (process.env.NODE_ENV !== 'production') {
6407
- validateLightDomTemplate(html, vm);
6408
- }
6424
+ checkHasMatchingRenderMode(html, vm);
6409
6425
  // Perf opt: do not reset the shadow root during the first rendering (there is
6410
6426
  // nothing to reset).
6411
6427
  if (!shared.isNull(cmpTemplate)) {
@@ -8131,13 +8147,15 @@ function haveCompatibleStaticParts(vnode, renderer) {
8131
8147
  // Explicitly skip hydration validation when static parts don't contain `style` or `className`.
8132
8148
  // This means the style/class attributes are either static or don't exist on the element and
8133
8149
  // cannot be affected by hydration.
8134
- const hasMatchingStyleAttr = shouldValidateAttr(data, 'style')
8135
- ? validateStyleAttr(vnode, elm, data, renderer)
8136
- : true;
8150
+ // We need to do class first, style second to match the ordering of non-static-optimized nodes,
8151
+ // otherwise the ordering of console errors is different between the two.
8137
8152
  const hasMatchingClass = shouldValidateAttr(data, 'className')
8138
8153
  ? validateClassAttr(vnode, elm, data, renderer)
8139
8154
  : true;
8140
- if (shared.isFalse(hasMatchingAttrs && hasMatchingStyleAttr && hasMatchingClass)) {
8155
+ const hasMatchingStyleAttr = shouldValidateAttr(data, 'style')
8156
+ ? validateStyleAttr(vnode, elm, data, renderer)
8157
+ : true;
8158
+ if (shared.isFalse(hasMatchingAttrs && hasMatchingClass && hasMatchingStyleAttr)) {
8141
8159
  return false;
8142
8160
  }
8143
8161
  }
@@ -8427,6 +8445,10 @@ function readonly(obj) {
8427
8445
  return getReadOnlyProxy(obj);
8428
8446
  }
8429
8447
 
8448
+ Object.defineProperty(exports, "setTrustedSignalSet", {
8449
+ enumerable: true,
8450
+ get: function () { return shared.setTrustedSignalSet; }
8451
+ });
8430
8452
  Object.defineProperty(exports, "setFeatureFlag", {
8431
8453
  enumerable: true,
8432
8454
  get: function () { return features.setFeatureFlag; }
@@ -8471,5 +8493,5 @@ exports.swapTemplate = swapTemplate;
8471
8493
  exports.track = track;
8472
8494
  exports.unwrap = unwrap;
8473
8495
  exports.wire = wire;
8474
- /** version: 8.1.3 */
8496
+ /** version: 8.3.0 */
8475
8497
  //# sourceMappingURL=index.cjs.js.map