@lwc/engine-core 2.20.2 → 2.21.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.
@@ -2878,6 +2878,175 @@ function getComponentDef(Ctor) {
2878
2878
  };
2879
2879
  }
2880
2880
 
2881
+ /*
2882
+ * Copyright (c) 2018, salesforce.com, inc.
2883
+ * All rights reserved.
2884
+ * SPDX-License-Identifier: MIT
2885
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2886
+ */
2887
+ function makeHostToken(token) {
2888
+ return `${token}-host`;
2889
+ }
2890
+ function createInlineStyleVNode(content) {
2891
+ return api.h('style', {
2892
+ key: 'style',
2893
+ attrs: {
2894
+ type: 'text/css',
2895
+ },
2896
+ }, [api.t(content)]);
2897
+ }
2898
+ function updateStylesheetToken(vm, template) {
2899
+ const { elm, context, renderMode, shadowMode, renderer: { getClassList, removeAttribute, setAttribute }, } = vm;
2900
+ const { stylesheets: newStylesheets, stylesheetToken: newStylesheetToken } = template;
2901
+ const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
2902
+ const { hasScopedStyles } = context;
2903
+ let newToken;
2904
+ let newHasTokenInClass;
2905
+ let newHasTokenInAttribute;
2906
+ // Reset the styling token applied to the host element.
2907
+ const { stylesheetToken: oldToken, hasTokenInClass: oldHasTokenInClass, hasTokenInAttribute: oldHasTokenInAttribute, } = context;
2908
+ if (!shared.isUndefined(oldToken)) {
2909
+ if (oldHasTokenInClass) {
2910
+ getClassList(elm).remove(makeHostToken(oldToken));
2911
+ }
2912
+ if (oldHasTokenInAttribute) {
2913
+ removeAttribute(elm, makeHostToken(oldToken));
2914
+ }
2915
+ }
2916
+ // Apply the new template styling token to the host element, if the new template has any
2917
+ // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
2918
+ if (!shared.isUndefined(newStylesheets) && newStylesheets.length !== 0) {
2919
+ newToken = newStylesheetToken;
2920
+ }
2921
+ // Set the new styling token on the host element
2922
+ if (!shared.isUndefined(newToken)) {
2923
+ if (hasScopedStyles) {
2924
+ getClassList(elm).add(makeHostToken(newToken));
2925
+ newHasTokenInClass = true;
2926
+ }
2927
+ if (isSyntheticShadow) {
2928
+ setAttribute(elm, makeHostToken(newToken), '');
2929
+ newHasTokenInAttribute = true;
2930
+ }
2931
+ }
2932
+ // Update the styling tokens present on the context object.
2933
+ context.stylesheetToken = newToken;
2934
+ context.hasTokenInClass = newHasTokenInClass;
2935
+ context.hasTokenInAttribute = newHasTokenInAttribute;
2936
+ }
2937
+ function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
2938
+ const content = [];
2939
+ let root;
2940
+ for (let i = 0; i < stylesheets.length; i++) {
2941
+ let stylesheet = stylesheets[i];
2942
+ if (shared.isArray(stylesheet)) {
2943
+ shared.ArrayPush.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
2944
+ }
2945
+ else {
2946
+ if (process.env.NODE_ENV !== 'production') {
2947
+ // Check for compiler version mismatch in dev mode only
2948
+ checkVersionMismatch(stylesheet, 'stylesheet');
2949
+ // in dev-mode, we support hot swapping of stylesheet, which means that
2950
+ // the component instance might be attempting to use an old version of
2951
+ // the stylesheet, while internally, we have a replacement for it.
2952
+ stylesheet = getStyleOrSwappedStyle(stylesheet);
2953
+ }
2954
+ const isScopedCss = stylesheet[shared.KEY__SCOPED_CSS];
2955
+ // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
2956
+ const scopeToken = isScopedCss ||
2957
+ (vm.shadowMode === 1 /* ShadowMode.Synthetic */ && vm.renderMode === 1 /* RenderMode.Shadow */)
2958
+ ? stylesheetToken
2959
+ : undefined;
2960
+ // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
2961
+ // native shadow DOM. Synthetic shadow DOM never uses `:host`.
2962
+ const useActualHostSelector = vm.renderMode === 0 /* RenderMode.Light */
2963
+ ? !isScopedCss
2964
+ : vm.shadowMode === 0 /* ShadowMode.Native */;
2965
+ // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
2966
+ // we use an attribute selector on the host to simulate :dir().
2967
+ let useNativeDirPseudoclass;
2968
+ if (vm.renderMode === 1 /* RenderMode.Shadow */) {
2969
+ useNativeDirPseudoclass = vm.shadowMode === 0 /* ShadowMode.Native */;
2970
+ }
2971
+ else {
2972
+ // Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
2973
+ // At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
2974
+ if (shared.isUndefined(root)) {
2975
+ // Only calculate the root once as necessary
2976
+ root = getNearestShadowComponent(vm);
2977
+ }
2978
+ useNativeDirPseudoclass = shared.isNull(root) || root.shadowMode === 0 /* ShadowMode.Native */;
2979
+ }
2980
+ shared.ArrayPush.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
2981
+ }
2982
+ }
2983
+ return content;
2984
+ }
2985
+ function getStylesheetsContent(vm, template) {
2986
+ const { stylesheets, stylesheetToken } = template;
2987
+ let content = [];
2988
+ if (!shared.isUndefined(stylesheets) && stylesheets.length !== 0) {
2989
+ content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
2990
+ }
2991
+ return content;
2992
+ }
2993
+ // It might be worth caching this to avoid doing the lookup repeatedly, but
2994
+ // perf testing has not shown it to be a huge improvement yet:
2995
+ // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
2996
+ function getNearestShadowComponent(vm) {
2997
+ let owner = vm;
2998
+ while (!shared.isNull(owner)) {
2999
+ if (owner.renderMode === 1 /* RenderMode.Shadow */) {
3000
+ return owner;
3001
+ }
3002
+ owner = owner.owner;
3003
+ }
3004
+ return owner;
3005
+ }
3006
+ /**
3007
+ * If the component that is currently being rendered uses scoped styles,
3008
+ * this returns the unique token for that scoped stylesheet. Otherwise
3009
+ * it returns null.
3010
+ */
3011
+ function getScopeTokenClass(owner) {
3012
+ const { cmpTemplate, context } = owner;
3013
+ return (context.hasScopedStyles && (cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken)) || null;
3014
+ }
3015
+ function getNearestNativeShadowComponent(vm) {
3016
+ const owner = getNearestShadowComponent(vm);
3017
+ if (!shared.isNull(owner) && owner.shadowMode === 1 /* ShadowMode.Synthetic */) {
3018
+ // Synthetic-within-native is impossible. So if the nearest shadow component is
3019
+ // synthetic, we know we won't find a native component if we go any further.
3020
+ return null;
3021
+ }
3022
+ return owner;
3023
+ }
3024
+ function createStylesheet(vm, stylesheets) {
3025
+ const { renderMode, shadowMode, renderer: { ssr, insertStylesheet }, } = vm;
3026
+ if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
3027
+ for (let i = 0; i < stylesheets.length; i++) {
3028
+ insertStylesheet(stylesheets[i]);
3029
+ }
3030
+ }
3031
+ else if (ssr || vm.hydrated) {
3032
+ // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
3033
+ // This works in the client, because the stylesheets are created, and cached in the VM
3034
+ // the first time the VM renders.
3035
+ // native shadow or light DOM, SSR
3036
+ return shared.ArrayMap.call(stylesheets, createInlineStyleVNode);
3037
+ }
3038
+ else {
3039
+ // native shadow or light DOM, DOM renderer
3040
+ const root = getNearestNativeShadowComponent(vm);
3041
+ // null root means a global style
3042
+ const target = shared.isNull(root) ? undefined : root.shadowRoot;
3043
+ for (let i = 0; i < stylesheets.length; i++) {
3044
+ insertStylesheet(stylesheets[i], target);
3045
+ }
3046
+ }
3047
+ return null;
3048
+ }
3049
+
2881
3050
  /*
2882
3051
  * Copyright (c) 2020, salesforce.com, inc.
2883
3052
  * All rights reserved.
@@ -3389,10 +3558,9 @@ function setElementShadowToken(elm, token) {
3389
3558
  }
3390
3559
  // Set the scope token class for *.scoped.css styles
3391
3560
  function setScopeTokenClassIfNecessary(elm, owner, renderer) {
3392
- const { cmpTemplate, context } = owner;
3393
- const { getClassList } = renderer;
3394
- const token = cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken;
3395
- if (!shared.isUndefined(token) && context.hasScopedStyles) {
3561
+ const token = getScopeTokenClass(owner);
3562
+ if (!shared.isNull(token)) {
3563
+ const { getClassList } = renderer;
3396
3564
  // TODO [#2762]: this dot notation with add is probably problematic
3397
3565
  // probably we should have a renderer api for just the add operation
3398
3566
  getClassList(elm).add(token);
@@ -4155,166 +4323,6 @@ const api = shared.freeze({
4155
4323
  shc,
4156
4324
  });
4157
4325
 
4158
- /*
4159
- * Copyright (c) 2018, salesforce.com, inc.
4160
- * All rights reserved.
4161
- * SPDX-License-Identifier: MIT
4162
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4163
- */
4164
- function makeHostToken(token) {
4165
- return `${token}-host`;
4166
- }
4167
- function createInlineStyleVNode(content) {
4168
- return api.h('style', {
4169
- key: 'style',
4170
- attrs: {
4171
- type: 'text/css',
4172
- },
4173
- }, [api.t(content)]);
4174
- }
4175
- function updateStylesheetToken(vm, template) {
4176
- const { elm, context, renderMode, shadowMode, renderer: { getClassList, removeAttribute, setAttribute }, } = vm;
4177
- const { stylesheets: newStylesheets, stylesheetToken: newStylesheetToken } = template;
4178
- const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
4179
- const { hasScopedStyles } = context;
4180
- let newToken;
4181
- let newHasTokenInClass;
4182
- let newHasTokenInAttribute;
4183
- // Reset the styling token applied to the host element.
4184
- const { stylesheetToken: oldToken, hasTokenInClass: oldHasTokenInClass, hasTokenInAttribute: oldHasTokenInAttribute, } = context;
4185
- if (!shared.isUndefined(oldToken)) {
4186
- if (oldHasTokenInClass) {
4187
- getClassList(elm).remove(makeHostToken(oldToken));
4188
- }
4189
- if (oldHasTokenInAttribute) {
4190
- removeAttribute(elm, makeHostToken(oldToken));
4191
- }
4192
- }
4193
- // Apply the new template styling token to the host element, if the new template has any
4194
- // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
4195
- if (!shared.isUndefined(newStylesheets) && newStylesheets.length !== 0) {
4196
- newToken = newStylesheetToken;
4197
- }
4198
- // Set the new styling token on the host element
4199
- if (!shared.isUndefined(newToken)) {
4200
- if (hasScopedStyles) {
4201
- getClassList(elm).add(makeHostToken(newToken));
4202
- newHasTokenInClass = true;
4203
- }
4204
- if (isSyntheticShadow) {
4205
- setAttribute(elm, makeHostToken(newToken), '');
4206
- newHasTokenInAttribute = true;
4207
- }
4208
- }
4209
- // Update the styling tokens present on the context object.
4210
- context.stylesheetToken = newToken;
4211
- context.hasTokenInClass = newHasTokenInClass;
4212
- context.hasTokenInAttribute = newHasTokenInAttribute;
4213
- }
4214
- function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
4215
- const content = [];
4216
- let root;
4217
- for (let i = 0; i < stylesheets.length; i++) {
4218
- let stylesheet = stylesheets[i];
4219
- if (shared.isArray(stylesheet)) {
4220
- shared.ArrayPush.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
4221
- }
4222
- else {
4223
- if (process.env.NODE_ENV !== 'production') {
4224
- // Check for compiler version mismatch in dev mode only
4225
- checkVersionMismatch(stylesheet, 'stylesheet');
4226
- // in dev-mode, we support hot swapping of stylesheet, which means that
4227
- // the component instance might be attempting to use an old version of
4228
- // the stylesheet, while internally, we have a replacement for it.
4229
- stylesheet = getStyleOrSwappedStyle(stylesheet);
4230
- }
4231
- const isScopedCss = stylesheet[shared.KEY__SCOPED_CSS];
4232
- // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
4233
- const scopeToken = isScopedCss ||
4234
- (vm.shadowMode === 1 /* ShadowMode.Synthetic */ && vm.renderMode === 1 /* RenderMode.Shadow */)
4235
- ? stylesheetToken
4236
- : undefined;
4237
- // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
4238
- // native shadow DOM. Synthetic shadow DOM never uses `:host`.
4239
- const useActualHostSelector = vm.renderMode === 0 /* RenderMode.Light */
4240
- ? !isScopedCss
4241
- : vm.shadowMode === 0 /* ShadowMode.Native */;
4242
- // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
4243
- // we use an attribute selector on the host to simulate :dir().
4244
- let useNativeDirPseudoclass;
4245
- if (vm.renderMode === 1 /* RenderMode.Shadow */) {
4246
- useNativeDirPseudoclass = vm.shadowMode === 0 /* ShadowMode.Native */;
4247
- }
4248
- else {
4249
- // Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
4250
- // At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
4251
- if (shared.isUndefined(root)) {
4252
- // Only calculate the root once as necessary
4253
- root = getNearestShadowComponent(vm);
4254
- }
4255
- useNativeDirPseudoclass = shared.isNull(root) || root.shadowMode === 0 /* ShadowMode.Native */;
4256
- }
4257
- shared.ArrayPush.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
4258
- }
4259
- }
4260
- return content;
4261
- }
4262
- function getStylesheetsContent(vm, template) {
4263
- const { stylesheets, stylesheetToken } = template;
4264
- let content = [];
4265
- if (!shared.isUndefined(stylesheets) && stylesheets.length !== 0) {
4266
- content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
4267
- }
4268
- return content;
4269
- }
4270
- // It might be worth caching this to avoid doing the lookup repeatedly, but
4271
- // perf testing has not shown it to be a huge improvement yet:
4272
- // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
4273
- function getNearestShadowComponent(vm) {
4274
- let owner = vm;
4275
- while (!shared.isNull(owner)) {
4276
- if (owner.renderMode === 1 /* RenderMode.Shadow */) {
4277
- return owner;
4278
- }
4279
- owner = owner.owner;
4280
- }
4281
- return owner;
4282
- }
4283
- function getNearestNativeShadowComponent(vm) {
4284
- const owner = getNearestShadowComponent(vm);
4285
- if (!shared.isNull(owner) && owner.shadowMode === 1 /* ShadowMode.Synthetic */) {
4286
- // Synthetic-within-native is impossible. So if the nearest shadow component is
4287
- // synthetic, we know we won't find a native component if we go any further.
4288
- return null;
4289
- }
4290
- return owner;
4291
- }
4292
- function createStylesheet(vm, stylesheets) {
4293
- const { renderMode, shadowMode, renderer: { ssr, insertStylesheet }, } = vm;
4294
- if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
4295
- for (let i = 0; i < stylesheets.length; i++) {
4296
- insertStylesheet(stylesheets[i]);
4297
- }
4298
- }
4299
- else if (ssr || vm.hydrated) {
4300
- // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
4301
- // This works in the client, because the stylesheets are created, and cached in the VM
4302
- // the first time the VM renders.
4303
- // native shadow or light DOM, SSR
4304
- return shared.ArrayMap.call(stylesheets, createInlineStyleVNode);
4305
- }
4306
- else {
4307
- // native shadow or light DOM, DOM renderer
4308
- const root = getNearestNativeShadowComponent(vm);
4309
- // null root means a global style
4310
- const target = shared.isNull(root) ? undefined : root.shadowRoot;
4311
- for (let i = 0; i < stylesheets.length; i++) {
4312
- insertStylesheet(stylesheets[i], target);
4313
- }
4314
- }
4315
- return null;
4316
- }
4317
-
4318
4326
  /*
4319
4327
  * Copyright (c) 2018, salesforce.com, inc.
4320
4328
  * All rights reserved.
@@ -6092,8 +6100,24 @@ function validateAttrs(vnode, elm, renderer) {
6092
6100
  return nodesAreCompatible;
6093
6101
  }
6094
6102
  function validateClassAttr(vnode, elm, renderer) {
6095
- const { data: { className, classMap }, } = vnode;
6103
+ const { data, owner } = vnode;
6104
+ let { className, classMap } = data;
6096
6105
  const { getProperty, getClassList } = renderer;
6106
+ const scopedToken = getScopeTokenClass(owner);
6107
+ // Classnames for scoped CSS are added directly to the DOM during rendering,
6108
+ // or to the VDOM on the server in the case of SSR. As such, these classnames
6109
+ // are never present in VDOM nodes in the browser.
6110
+ //
6111
+ // Consequently, hydration mismatches will occur if scoped CSS token classnames
6112
+ // are rendered during SSR. This needs to be accounted for when validating.
6113
+ if (scopedToken) {
6114
+ if (!shared.isUndefined(className)) {
6115
+ className = `${scopedToken} ${className}`;
6116
+ }
6117
+ else if (!shared.isUndefined(classMap)) {
6118
+ classMap = Object.assign(Object.assign({}, classMap), { [scopedToken]: true });
6119
+ }
6120
+ }
6097
6121
  let nodesAreCompatible = true;
6098
6122
  let vnodeClassName;
6099
6123
  if (!shared.isUndefined(className) && String(className) !== getProperty(elm, 'className')) {
@@ -6372,4 +6396,4 @@ exports.swapTemplate = swapTemplate;
6372
6396
  exports.track = track;
6373
6397
  exports.unwrap = unwrap;
6374
6398
  exports.wire = wire;
6375
- /* version: 2.20.2 */
6399
+ /* version: 2.21.0 */
@@ -1,7 +1,7 @@
1
1
  /* proxy-compat-disable */
2
2
  import { runtimeFlags } from '@lwc/features';
3
3
  export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
4
- import { seal, create, isFunction as isFunction$1, ArrayPush as ArrayPush$1, isUndefined as isUndefined$1, ArrayIndexOf, ArraySplice, StringToLowerCase, ArrayJoin, isNull, isFrozen, defineProperty, hasOwnProperty as hasOwnProperty$1, assign, forEach, keys, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getOwnPropertyNames as getOwnPropertyNames$1, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, isObject, assert, KEY__SYNTHETIC_MODE, toString as toString$1, isFalse, isTrue, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, freeze, htmlPropertyToAttribute, ArraySlice, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, isString, StringSlice, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, isArray as isArray$1, isNumber, StringReplace, ArrayMap, KEY__SCOPED_CSS, noop, ArrayUnshift, ArrayCopyWithin, ArrayFill, ArraySort, ArrayReverse, ArrayShift, ArrayPop } from '@lwc/shared';
4
+ import { seal, create, isFunction as isFunction$1, ArrayPush as ArrayPush$1, isUndefined as isUndefined$1, ArrayIndexOf, ArraySplice, StringToLowerCase, isNull, ArrayJoin, isFrozen, defineProperty, hasOwnProperty as hasOwnProperty$1, assign, forEach, keys, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getOwnPropertyNames as getOwnPropertyNames$1, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, isObject, assert, KEY__SYNTHETIC_MODE, toString as toString$1, isFalse, isTrue, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, freeze, htmlPropertyToAttribute, ArraySlice, ArrayMap, isArray as isArray$1, KEY__SCOPED_CSS, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, isString, StringSlice, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, isNumber, StringReplace, noop, ArrayUnshift, ArrayCopyWithin, ArrayFill, ArraySort, ArrayReverse, ArrayShift, ArrayPop } from '@lwc/shared';
5
5
 
6
6
  /*
7
7
  * Copyright (c) 2018, salesforce.com, inc.
@@ -2875,6 +2875,175 @@ function getComponentDef(Ctor) {
2875
2875
  };
2876
2876
  }
2877
2877
 
2878
+ /*
2879
+ * Copyright (c) 2018, salesforce.com, inc.
2880
+ * All rights reserved.
2881
+ * SPDX-License-Identifier: MIT
2882
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2883
+ */
2884
+ function makeHostToken(token) {
2885
+ return `${token}-host`;
2886
+ }
2887
+ function createInlineStyleVNode(content) {
2888
+ return api.h('style', {
2889
+ key: 'style',
2890
+ attrs: {
2891
+ type: 'text/css',
2892
+ },
2893
+ }, [api.t(content)]);
2894
+ }
2895
+ function updateStylesheetToken(vm, template) {
2896
+ const { elm, context, renderMode, shadowMode, renderer: { getClassList, removeAttribute, setAttribute }, } = vm;
2897
+ const { stylesheets: newStylesheets, stylesheetToken: newStylesheetToken } = template;
2898
+ const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
2899
+ const { hasScopedStyles } = context;
2900
+ let newToken;
2901
+ let newHasTokenInClass;
2902
+ let newHasTokenInAttribute;
2903
+ // Reset the styling token applied to the host element.
2904
+ const { stylesheetToken: oldToken, hasTokenInClass: oldHasTokenInClass, hasTokenInAttribute: oldHasTokenInAttribute, } = context;
2905
+ if (!isUndefined$1(oldToken)) {
2906
+ if (oldHasTokenInClass) {
2907
+ getClassList(elm).remove(makeHostToken(oldToken));
2908
+ }
2909
+ if (oldHasTokenInAttribute) {
2910
+ removeAttribute(elm, makeHostToken(oldToken));
2911
+ }
2912
+ }
2913
+ // Apply the new template styling token to the host element, if the new template has any
2914
+ // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
2915
+ if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
2916
+ newToken = newStylesheetToken;
2917
+ }
2918
+ // Set the new styling token on the host element
2919
+ if (!isUndefined$1(newToken)) {
2920
+ if (hasScopedStyles) {
2921
+ getClassList(elm).add(makeHostToken(newToken));
2922
+ newHasTokenInClass = true;
2923
+ }
2924
+ if (isSyntheticShadow) {
2925
+ setAttribute(elm, makeHostToken(newToken), '');
2926
+ newHasTokenInAttribute = true;
2927
+ }
2928
+ }
2929
+ // Update the styling tokens present on the context object.
2930
+ context.stylesheetToken = newToken;
2931
+ context.hasTokenInClass = newHasTokenInClass;
2932
+ context.hasTokenInAttribute = newHasTokenInAttribute;
2933
+ }
2934
+ function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
2935
+ const content = [];
2936
+ let root;
2937
+ for (let i = 0; i < stylesheets.length; i++) {
2938
+ let stylesheet = stylesheets[i];
2939
+ if (isArray$1(stylesheet)) {
2940
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
2941
+ }
2942
+ else {
2943
+ if (process.env.NODE_ENV !== 'production') {
2944
+ // Check for compiler version mismatch in dev mode only
2945
+ checkVersionMismatch(stylesheet, 'stylesheet');
2946
+ // in dev-mode, we support hot swapping of stylesheet, which means that
2947
+ // the component instance might be attempting to use an old version of
2948
+ // the stylesheet, while internally, we have a replacement for it.
2949
+ stylesheet = getStyleOrSwappedStyle(stylesheet);
2950
+ }
2951
+ const isScopedCss = stylesheet[KEY__SCOPED_CSS];
2952
+ // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
2953
+ const scopeToken = isScopedCss ||
2954
+ (vm.shadowMode === 1 /* ShadowMode.Synthetic */ && vm.renderMode === 1 /* RenderMode.Shadow */)
2955
+ ? stylesheetToken
2956
+ : undefined;
2957
+ // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
2958
+ // native shadow DOM. Synthetic shadow DOM never uses `:host`.
2959
+ const useActualHostSelector = vm.renderMode === 0 /* RenderMode.Light */
2960
+ ? !isScopedCss
2961
+ : vm.shadowMode === 0 /* ShadowMode.Native */;
2962
+ // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
2963
+ // we use an attribute selector on the host to simulate :dir().
2964
+ let useNativeDirPseudoclass;
2965
+ if (vm.renderMode === 1 /* RenderMode.Shadow */) {
2966
+ useNativeDirPseudoclass = vm.shadowMode === 0 /* ShadowMode.Native */;
2967
+ }
2968
+ else {
2969
+ // Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
2970
+ // At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
2971
+ if (isUndefined$1(root)) {
2972
+ // Only calculate the root once as necessary
2973
+ root = getNearestShadowComponent(vm);
2974
+ }
2975
+ useNativeDirPseudoclass = isNull(root) || root.shadowMode === 0 /* ShadowMode.Native */;
2976
+ }
2977
+ ArrayPush$1.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
2978
+ }
2979
+ }
2980
+ return content;
2981
+ }
2982
+ function getStylesheetsContent(vm, template) {
2983
+ const { stylesheets, stylesheetToken } = template;
2984
+ let content = [];
2985
+ if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
2986
+ content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
2987
+ }
2988
+ return content;
2989
+ }
2990
+ // It might be worth caching this to avoid doing the lookup repeatedly, but
2991
+ // perf testing has not shown it to be a huge improvement yet:
2992
+ // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
2993
+ function getNearestShadowComponent(vm) {
2994
+ let owner = vm;
2995
+ while (!isNull(owner)) {
2996
+ if (owner.renderMode === 1 /* RenderMode.Shadow */) {
2997
+ return owner;
2998
+ }
2999
+ owner = owner.owner;
3000
+ }
3001
+ return owner;
3002
+ }
3003
+ /**
3004
+ * If the component that is currently being rendered uses scoped styles,
3005
+ * this returns the unique token for that scoped stylesheet. Otherwise
3006
+ * it returns null.
3007
+ */
3008
+ function getScopeTokenClass(owner) {
3009
+ const { cmpTemplate, context } = owner;
3010
+ return (context.hasScopedStyles && (cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken)) || null;
3011
+ }
3012
+ function getNearestNativeShadowComponent(vm) {
3013
+ const owner = getNearestShadowComponent(vm);
3014
+ if (!isNull(owner) && owner.shadowMode === 1 /* ShadowMode.Synthetic */) {
3015
+ // Synthetic-within-native is impossible. So if the nearest shadow component is
3016
+ // synthetic, we know we won't find a native component if we go any further.
3017
+ return null;
3018
+ }
3019
+ return owner;
3020
+ }
3021
+ function createStylesheet(vm, stylesheets) {
3022
+ const { renderMode, shadowMode, renderer: { ssr, insertStylesheet }, } = vm;
3023
+ if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
3024
+ for (let i = 0; i < stylesheets.length; i++) {
3025
+ insertStylesheet(stylesheets[i]);
3026
+ }
3027
+ }
3028
+ else if (ssr || vm.hydrated) {
3029
+ // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
3030
+ // This works in the client, because the stylesheets are created, and cached in the VM
3031
+ // the first time the VM renders.
3032
+ // native shadow or light DOM, SSR
3033
+ return ArrayMap.call(stylesheets, createInlineStyleVNode);
3034
+ }
3035
+ else {
3036
+ // native shadow or light DOM, DOM renderer
3037
+ const root = getNearestNativeShadowComponent(vm);
3038
+ // null root means a global style
3039
+ const target = isNull(root) ? undefined : root.shadowRoot;
3040
+ for (let i = 0; i < stylesheets.length; i++) {
3041
+ insertStylesheet(stylesheets[i], target);
3042
+ }
3043
+ }
3044
+ return null;
3045
+ }
3046
+
2878
3047
  /*
2879
3048
  * Copyright (c) 2020, salesforce.com, inc.
2880
3049
  * All rights reserved.
@@ -3386,10 +3555,9 @@ function setElementShadowToken(elm, token) {
3386
3555
  }
3387
3556
  // Set the scope token class for *.scoped.css styles
3388
3557
  function setScopeTokenClassIfNecessary(elm, owner, renderer) {
3389
- const { cmpTemplate, context } = owner;
3390
- const { getClassList } = renderer;
3391
- const token = cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken;
3392
- if (!isUndefined$1(token) && context.hasScopedStyles) {
3558
+ const token = getScopeTokenClass(owner);
3559
+ if (!isNull(token)) {
3560
+ const { getClassList } = renderer;
3393
3561
  // TODO [#2762]: this dot notation with add is probably problematic
3394
3562
  // probably we should have a renderer api for just the add operation
3395
3563
  getClassList(elm).add(token);
@@ -4152,166 +4320,6 @@ const api = freeze({
4152
4320
  shc,
4153
4321
  });
4154
4322
 
4155
- /*
4156
- * Copyright (c) 2018, salesforce.com, inc.
4157
- * All rights reserved.
4158
- * SPDX-License-Identifier: MIT
4159
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4160
- */
4161
- function makeHostToken(token) {
4162
- return `${token}-host`;
4163
- }
4164
- function createInlineStyleVNode(content) {
4165
- return api.h('style', {
4166
- key: 'style',
4167
- attrs: {
4168
- type: 'text/css',
4169
- },
4170
- }, [api.t(content)]);
4171
- }
4172
- function updateStylesheetToken(vm, template) {
4173
- const { elm, context, renderMode, shadowMode, renderer: { getClassList, removeAttribute, setAttribute }, } = vm;
4174
- const { stylesheets: newStylesheets, stylesheetToken: newStylesheetToken } = template;
4175
- const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
4176
- const { hasScopedStyles } = context;
4177
- let newToken;
4178
- let newHasTokenInClass;
4179
- let newHasTokenInAttribute;
4180
- // Reset the styling token applied to the host element.
4181
- const { stylesheetToken: oldToken, hasTokenInClass: oldHasTokenInClass, hasTokenInAttribute: oldHasTokenInAttribute, } = context;
4182
- if (!isUndefined$1(oldToken)) {
4183
- if (oldHasTokenInClass) {
4184
- getClassList(elm).remove(makeHostToken(oldToken));
4185
- }
4186
- if (oldHasTokenInAttribute) {
4187
- removeAttribute(elm, makeHostToken(oldToken));
4188
- }
4189
- }
4190
- // Apply the new template styling token to the host element, if the new template has any
4191
- // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
4192
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
4193
- newToken = newStylesheetToken;
4194
- }
4195
- // Set the new styling token on the host element
4196
- if (!isUndefined$1(newToken)) {
4197
- if (hasScopedStyles) {
4198
- getClassList(elm).add(makeHostToken(newToken));
4199
- newHasTokenInClass = true;
4200
- }
4201
- if (isSyntheticShadow) {
4202
- setAttribute(elm, makeHostToken(newToken), '');
4203
- newHasTokenInAttribute = true;
4204
- }
4205
- }
4206
- // Update the styling tokens present on the context object.
4207
- context.stylesheetToken = newToken;
4208
- context.hasTokenInClass = newHasTokenInClass;
4209
- context.hasTokenInAttribute = newHasTokenInAttribute;
4210
- }
4211
- function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
4212
- const content = [];
4213
- let root;
4214
- for (let i = 0; i < stylesheets.length; i++) {
4215
- let stylesheet = stylesheets[i];
4216
- if (isArray$1(stylesheet)) {
4217
- ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
4218
- }
4219
- else {
4220
- if (process.env.NODE_ENV !== 'production') {
4221
- // Check for compiler version mismatch in dev mode only
4222
- checkVersionMismatch(stylesheet, 'stylesheet');
4223
- // in dev-mode, we support hot swapping of stylesheet, which means that
4224
- // the component instance might be attempting to use an old version of
4225
- // the stylesheet, while internally, we have a replacement for it.
4226
- stylesheet = getStyleOrSwappedStyle(stylesheet);
4227
- }
4228
- const isScopedCss = stylesheet[KEY__SCOPED_CSS];
4229
- // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
4230
- const scopeToken = isScopedCss ||
4231
- (vm.shadowMode === 1 /* ShadowMode.Synthetic */ && vm.renderMode === 1 /* RenderMode.Shadow */)
4232
- ? stylesheetToken
4233
- : undefined;
4234
- // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
4235
- // native shadow DOM. Synthetic shadow DOM never uses `:host`.
4236
- const useActualHostSelector = vm.renderMode === 0 /* RenderMode.Light */
4237
- ? !isScopedCss
4238
- : vm.shadowMode === 0 /* ShadowMode.Native */;
4239
- // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
4240
- // we use an attribute selector on the host to simulate :dir().
4241
- let useNativeDirPseudoclass;
4242
- if (vm.renderMode === 1 /* RenderMode.Shadow */) {
4243
- useNativeDirPseudoclass = vm.shadowMode === 0 /* ShadowMode.Native */;
4244
- }
4245
- else {
4246
- // Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
4247
- // At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
4248
- if (isUndefined$1(root)) {
4249
- // Only calculate the root once as necessary
4250
- root = getNearestShadowComponent(vm);
4251
- }
4252
- useNativeDirPseudoclass = isNull(root) || root.shadowMode === 0 /* ShadowMode.Native */;
4253
- }
4254
- ArrayPush$1.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
4255
- }
4256
- }
4257
- return content;
4258
- }
4259
- function getStylesheetsContent(vm, template) {
4260
- const { stylesheets, stylesheetToken } = template;
4261
- let content = [];
4262
- if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
4263
- content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
4264
- }
4265
- return content;
4266
- }
4267
- // It might be worth caching this to avoid doing the lookup repeatedly, but
4268
- // perf testing has not shown it to be a huge improvement yet:
4269
- // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
4270
- function getNearestShadowComponent(vm) {
4271
- let owner = vm;
4272
- while (!isNull(owner)) {
4273
- if (owner.renderMode === 1 /* RenderMode.Shadow */) {
4274
- return owner;
4275
- }
4276
- owner = owner.owner;
4277
- }
4278
- return owner;
4279
- }
4280
- function getNearestNativeShadowComponent(vm) {
4281
- const owner = getNearestShadowComponent(vm);
4282
- if (!isNull(owner) && owner.shadowMode === 1 /* ShadowMode.Synthetic */) {
4283
- // Synthetic-within-native is impossible. So if the nearest shadow component is
4284
- // synthetic, we know we won't find a native component if we go any further.
4285
- return null;
4286
- }
4287
- return owner;
4288
- }
4289
- function createStylesheet(vm, stylesheets) {
4290
- const { renderMode, shadowMode, renderer: { ssr, insertStylesheet }, } = vm;
4291
- if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
4292
- for (let i = 0; i < stylesheets.length; i++) {
4293
- insertStylesheet(stylesheets[i]);
4294
- }
4295
- }
4296
- else if (ssr || vm.hydrated) {
4297
- // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
4298
- // This works in the client, because the stylesheets are created, and cached in the VM
4299
- // the first time the VM renders.
4300
- // native shadow or light DOM, SSR
4301
- return ArrayMap.call(stylesheets, createInlineStyleVNode);
4302
- }
4303
- else {
4304
- // native shadow or light DOM, DOM renderer
4305
- const root = getNearestNativeShadowComponent(vm);
4306
- // null root means a global style
4307
- const target = isNull(root) ? undefined : root.shadowRoot;
4308
- for (let i = 0; i < stylesheets.length; i++) {
4309
- insertStylesheet(stylesheets[i], target);
4310
- }
4311
- }
4312
- return null;
4313
- }
4314
-
4315
4323
  /*
4316
4324
  * Copyright (c) 2018, salesforce.com, inc.
4317
4325
  * All rights reserved.
@@ -6089,8 +6097,24 @@ function validateAttrs(vnode, elm, renderer) {
6089
6097
  return nodesAreCompatible;
6090
6098
  }
6091
6099
  function validateClassAttr(vnode, elm, renderer) {
6092
- const { data: { className, classMap }, } = vnode;
6100
+ const { data, owner } = vnode;
6101
+ let { className, classMap } = data;
6093
6102
  const { getProperty, getClassList } = renderer;
6103
+ const scopedToken = getScopeTokenClass(owner);
6104
+ // Classnames for scoped CSS are added directly to the DOM during rendering,
6105
+ // or to the VDOM on the server in the case of SSR. As such, these classnames
6106
+ // are never present in VDOM nodes in the browser.
6107
+ //
6108
+ // Consequently, hydration mismatches will occur if scoped CSS token classnames
6109
+ // are rendered during SSR. This needs to be accounted for when validating.
6110
+ if (scopedToken) {
6111
+ if (!isUndefined$1(className)) {
6112
+ className = `${scopedToken} ${className}`;
6113
+ }
6114
+ else if (!isUndefined$1(classMap)) {
6115
+ classMap = Object.assign(Object.assign({}, classMap), { [scopedToken]: true });
6116
+ }
6117
+ }
6094
6118
  let nodesAreCompatible = true;
6095
6119
  let vnodeClassName;
6096
6120
  if (!isUndefined$1(className) && String(className) !== getProperty(elm, 'className')) {
@@ -6332,4 +6356,4 @@ function getComponentConstructor(elm) {
6332
6356
  }
6333
6357
 
6334
6358
  export { LightningElement, profilerControl as __unstable__ProfilerControl, api$1 as api, connectRootElement, createContextProvider, createVM, disconnectRootElement, freezeTemplate, getAssociatedVMIfPresent, getComponentConstructor, getComponentDef, getComponentHtmlPrototype, getUpgradableConstructor, hydrateRoot, isComponentConstructor, parseFragment, parseSVGFragment, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, setHooks, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
6335
- /* version: 2.20.2 */
6359
+ /* version: 2.21.0 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lwc/engine-core",
3
- "version": "2.20.2",
3
+ "version": "2.21.0",
4
4
  "description": "Core LWC engine APIs.",
5
5
  "homepage": "https://lwc.dev/",
6
6
  "repository": {
@@ -25,8 +25,8 @@
25
25
  "types/"
26
26
  ],
27
27
  "dependencies": {
28
- "@lwc/features": "2.20.2",
29
- "@lwc/shared": "2.20.2"
28
+ "@lwc/features": "2.21.0",
29
+ "@lwc/shared": "2.21.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "observable-membrane": "2.0.0"
@@ -14,4 +14,10 @@ export declare type StylesheetFactory = (stylesheetToken: string | undefined, us
14
14
  export declare type TemplateStylesheetFactories = Array<StylesheetFactory | TemplateStylesheetFactories>;
15
15
  export declare function updateStylesheetToken(vm: VM, template: Template): void;
16
16
  export declare function getStylesheetsContent(vm: VM, template: Template): string[];
17
+ /**
18
+ * If the component that is currently being rendered uses scoped styles,
19
+ * this returns the unique token for that scoped stylesheet. Otherwise
20
+ * it returns null.
21
+ */
22
+ export declare function getScopeTokenClass(owner: VM): string | null;
17
23
  export declare function createStylesheet(vm: VM, stylesheets: string[]): VNode[] | null;