@lwc/engine-core 6.5.2 → 6.6.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/dist/framework/renderer.d.ts +1 -1
- package/dist/framework/stylesheet.d.ts +1 -0
- package/dist/index.cjs.js +341 -252
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +342 -253
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
|
@@ -40,7 +40,7 @@ export interface RendererAPI {
|
|
|
40
40
|
getLastElementChild: (element: E) => E | null;
|
|
41
41
|
getTagName: (element: E) => string;
|
|
42
42
|
isConnected: (node: N) => boolean;
|
|
43
|
-
insertStylesheet: (content: string, target
|
|
43
|
+
insertStylesheet: (content: string, target: ShadowRoot | undefined, signal: AbortSignal | undefined) => void;
|
|
44
44
|
assertInstanceOfHTMLElement: (elm: any, msg: string) => void;
|
|
45
45
|
createCustomElement: (tagName: string, upgradeCallback: LifecycleCallback, useNativeLifecycle: boolean, isFormAssociated: boolean) => E;
|
|
46
46
|
defineCustomElement: (tagName: string, isFormAssociated: boolean) => void;
|
|
@@ -31,3 +31,4 @@ export declare function getScopeTokenClass(owner: VM, legacy: boolean): string |
|
|
|
31
31
|
*/
|
|
32
32
|
export declare function getStylesheetTokenHost(vnode: VCustomElement): string | null;
|
|
33
33
|
export declare function createStylesheet(vm: VM, stylesheets: string[]): VNode[] | null;
|
|
34
|
+
export declare function unrenderStylesheet(stylesheet: StylesheetFactory): void;
|
package/dist/index.cjs.js
CHANGED
|
@@ -2912,6 +2912,296 @@ const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor, baseP
|
|
|
2912
2912
|
shared.freeze(BaseBridgeElement);
|
|
2913
2913
|
shared.seal(BaseBridgeElement.prototype);
|
|
2914
2914
|
|
|
2915
|
+
/*
|
|
2916
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
2917
|
+
* All rights reserved.
|
|
2918
|
+
* SPDX-License-Identifier: MIT
|
|
2919
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2920
|
+
*/
|
|
2921
|
+
// These are only used for HMR in dev mode
|
|
2922
|
+
// The "pure" annotations are so that Rollup knows for sure it can remove these from prod mode
|
|
2923
|
+
let stylesheetsToCssContent = /*@__PURE__@*/ new WeakMap();
|
|
2924
|
+
let cssContentToAbortControllers = /*@__PURE__@*/ new Map();
|
|
2925
|
+
// Only used in LWC's Karma tests
|
|
2926
|
+
if (process.env.NODE_ENV === 'test-karma-lwc') {
|
|
2927
|
+
// Used to reset the global state between test runs
|
|
2928
|
+
window.__lwcResetStylesheetCache = () => {
|
|
2929
|
+
stylesheetsToCssContent = new WeakMap();
|
|
2930
|
+
cssContentToAbortControllers = new Map();
|
|
2931
|
+
};
|
|
2932
|
+
}
|
|
2933
|
+
function linkStylesheetToCssContentInDevMode(stylesheet, cssContent) {
|
|
2934
|
+
// Should never leak to prod; only used for HMR
|
|
2935
|
+
assertNotProd();
|
|
2936
|
+
let cssContents = stylesheetsToCssContent.get(stylesheet);
|
|
2937
|
+
if (shared.isUndefined(cssContents)) {
|
|
2938
|
+
cssContents = new Set();
|
|
2939
|
+
stylesheetsToCssContent.set(stylesheet, cssContents);
|
|
2940
|
+
}
|
|
2941
|
+
cssContents.add(cssContent);
|
|
2942
|
+
}
|
|
2943
|
+
function getOrCreateAbortControllerInDevMode(cssContent) {
|
|
2944
|
+
// Should never leak to prod; only used for HMR
|
|
2945
|
+
assertNotProd();
|
|
2946
|
+
let abortController = cssContentToAbortControllers.get(cssContent);
|
|
2947
|
+
if (shared.isUndefined(abortController)) {
|
|
2948
|
+
abortController = new AbortController();
|
|
2949
|
+
cssContentToAbortControllers.set(cssContent, abortController);
|
|
2950
|
+
}
|
|
2951
|
+
return abortController;
|
|
2952
|
+
}
|
|
2953
|
+
function getOrCreateAbortSignal(cssContent) {
|
|
2954
|
+
// abort controller/signal is only used for HMR in development
|
|
2955
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2956
|
+
return getOrCreateAbortControllerInDevMode(cssContent).signal;
|
|
2957
|
+
}
|
|
2958
|
+
return undefined;
|
|
2959
|
+
}
|
|
2960
|
+
function makeHostToken(token) {
|
|
2961
|
+
// Note: if this ever changes, update the `cssScopeTokens` returned by `@lwc/compiler`
|
|
2962
|
+
return `${token}-host`;
|
|
2963
|
+
}
|
|
2964
|
+
function createInlineStyleVNode(content) {
|
|
2965
|
+
return api.h('style', {
|
|
2966
|
+
key: 'style', // special key
|
|
2967
|
+
attrs: {
|
|
2968
|
+
type: 'text/css',
|
|
2969
|
+
},
|
|
2970
|
+
}, [api.t(content)]);
|
|
2971
|
+
}
|
|
2972
|
+
// TODO [#3733]: remove support for legacy scope tokens
|
|
2973
|
+
function updateStylesheetToken(vm, template, legacy) {
|
|
2974
|
+
const { elm, context, renderMode, shadowMode, renderer: { getClassList, removeAttribute, setAttribute }, } = vm;
|
|
2975
|
+
const { stylesheets: newStylesheets } = template;
|
|
2976
|
+
const newStylesheetToken = legacy ? template.legacyStylesheetToken : template.stylesheetToken;
|
|
2977
|
+
const { stylesheets: newVmStylesheets } = vm;
|
|
2978
|
+
const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
|
|
2979
|
+
const { hasScopedStyles } = context;
|
|
2980
|
+
let newToken;
|
|
2981
|
+
let newHasTokenInClass;
|
|
2982
|
+
let newHasTokenInAttribute;
|
|
2983
|
+
// Reset the styling token applied to the host element.
|
|
2984
|
+
let oldToken;
|
|
2985
|
+
let oldHasTokenInClass;
|
|
2986
|
+
let oldHasTokenInAttribute;
|
|
2987
|
+
if (legacy) {
|
|
2988
|
+
oldToken = context.legacyStylesheetToken;
|
|
2989
|
+
oldHasTokenInClass = context.hasLegacyTokenInClass;
|
|
2990
|
+
oldHasTokenInAttribute = context.hasLegacyTokenInAttribute;
|
|
2991
|
+
}
|
|
2992
|
+
else {
|
|
2993
|
+
oldToken = context.stylesheetToken;
|
|
2994
|
+
oldHasTokenInClass = context.hasTokenInClass;
|
|
2995
|
+
oldHasTokenInAttribute = context.hasTokenInAttribute;
|
|
2996
|
+
}
|
|
2997
|
+
if (!shared.isUndefined(oldToken)) {
|
|
2998
|
+
if (oldHasTokenInClass) {
|
|
2999
|
+
getClassList(elm).remove(makeHostToken(oldToken));
|
|
3000
|
+
}
|
|
3001
|
+
if (oldHasTokenInAttribute) {
|
|
3002
|
+
removeAttribute(elm, makeHostToken(oldToken));
|
|
3003
|
+
}
|
|
3004
|
+
}
|
|
3005
|
+
// Apply the new template styling token to the host element, if the new template has any
|
|
3006
|
+
// associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
|
|
3007
|
+
const hasNewStylesheets = hasStyles(newStylesheets);
|
|
3008
|
+
const hasNewVmStylesheets = hasStyles(newVmStylesheets);
|
|
3009
|
+
if (hasNewStylesheets || hasNewVmStylesheets) {
|
|
3010
|
+
newToken = newStylesheetToken;
|
|
3011
|
+
}
|
|
3012
|
+
// Set the new styling token on the host element
|
|
3013
|
+
if (!shared.isUndefined(newToken)) {
|
|
3014
|
+
if (hasScopedStyles) {
|
|
3015
|
+
getClassList(elm).add(makeHostToken(newToken));
|
|
3016
|
+
newHasTokenInClass = true;
|
|
3017
|
+
}
|
|
3018
|
+
if (isSyntheticShadow) {
|
|
3019
|
+
setAttribute(elm, makeHostToken(newToken), '');
|
|
3020
|
+
newHasTokenInAttribute = true;
|
|
3021
|
+
}
|
|
3022
|
+
}
|
|
3023
|
+
// Update the styling tokens present on the context object.
|
|
3024
|
+
if (legacy) {
|
|
3025
|
+
context.legacyStylesheetToken = newToken;
|
|
3026
|
+
context.hasLegacyTokenInClass = newHasTokenInClass;
|
|
3027
|
+
context.hasLegacyTokenInAttribute = newHasTokenInAttribute;
|
|
3028
|
+
}
|
|
3029
|
+
else {
|
|
3030
|
+
context.stylesheetToken = newToken;
|
|
3031
|
+
context.hasTokenInClass = newHasTokenInClass;
|
|
3032
|
+
context.hasTokenInAttribute = newHasTokenInAttribute;
|
|
3033
|
+
}
|
|
3034
|
+
}
|
|
3035
|
+
function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
|
|
3036
|
+
const content = [];
|
|
3037
|
+
let root;
|
|
3038
|
+
for (let i = 0; i < stylesheets.length; i++) {
|
|
3039
|
+
let stylesheet = stylesheets[i];
|
|
3040
|
+
if (shared.isArray(stylesheet)) {
|
|
3041
|
+
shared.ArrayPush.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
|
|
3042
|
+
}
|
|
3043
|
+
else {
|
|
3044
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
3045
|
+
// Check for compiler version mismatch in dev mode only
|
|
3046
|
+
checkVersionMismatch(stylesheet, 'stylesheet');
|
|
3047
|
+
// in dev-mode, we support hot swapping of stylesheet, which means that
|
|
3048
|
+
// the component instance might be attempting to use an old version of
|
|
3049
|
+
// the stylesheet, while internally, we have a replacement for it.
|
|
3050
|
+
stylesheet = getStyleOrSwappedStyle(stylesheet);
|
|
3051
|
+
}
|
|
3052
|
+
const isScopedCss = stylesheet[shared.KEY__SCOPED_CSS];
|
|
3053
|
+
if (lwcRuntimeFlags.DISABLE_LIGHT_DOM_UNSCOPED_CSS &&
|
|
3054
|
+
!isScopedCss &&
|
|
3055
|
+
vm.renderMode === 0 /* RenderMode.Light */) {
|
|
3056
|
+
logError('Unscoped CSS is not supported in Light DOM in this environment. Please use scoped CSS ' +
|
|
3057
|
+
'(*.scoped.css) instead of unscoped CSS (*.css). See also: https://sfdc.co/scoped-styles-light-dom');
|
|
3058
|
+
continue;
|
|
3059
|
+
}
|
|
3060
|
+
// Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
|
|
3061
|
+
const scopeToken = isScopedCss ||
|
|
3062
|
+
(vm.shadowMode === 1 /* ShadowMode.Synthetic */ && vm.renderMode === 1 /* RenderMode.Shadow */)
|
|
3063
|
+
? stylesheetToken
|
|
3064
|
+
: undefined;
|
|
3065
|
+
// Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
|
|
3066
|
+
// native shadow DOM. Synthetic shadow DOM never uses `:host`.
|
|
3067
|
+
const useActualHostSelector = vm.renderMode === 0 /* RenderMode.Light */
|
|
3068
|
+
? !isScopedCss
|
|
3069
|
+
: vm.shadowMode === 0 /* ShadowMode.Native */;
|
|
3070
|
+
// Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
|
|
3071
|
+
// we use an attribute selector on the host to simulate :dir().
|
|
3072
|
+
let useNativeDirPseudoclass;
|
|
3073
|
+
if (vm.renderMode === 1 /* RenderMode.Shadow */) {
|
|
3074
|
+
useNativeDirPseudoclass = vm.shadowMode === 0 /* ShadowMode.Native */;
|
|
3075
|
+
}
|
|
3076
|
+
else {
|
|
3077
|
+
// Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
|
|
3078
|
+
// At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
|
|
3079
|
+
if (shared.isUndefined(root)) {
|
|
3080
|
+
// Only calculate the root once as necessary
|
|
3081
|
+
root = getNearestShadowComponent(vm);
|
|
3082
|
+
}
|
|
3083
|
+
useNativeDirPseudoclass = shared.isNull(root) || root.shadowMode === 0 /* ShadowMode.Native */;
|
|
3084
|
+
}
|
|
3085
|
+
const cssContent = stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass);
|
|
3086
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
3087
|
+
linkStylesheetToCssContentInDevMode(stylesheet, cssContent);
|
|
3088
|
+
}
|
|
3089
|
+
shared.ArrayPush.call(content, cssContent);
|
|
3090
|
+
}
|
|
3091
|
+
}
|
|
3092
|
+
return content;
|
|
3093
|
+
}
|
|
3094
|
+
function getStylesheetsContent(vm, template) {
|
|
3095
|
+
const { stylesheets, stylesheetToken } = template;
|
|
3096
|
+
const { stylesheets: vmStylesheets } = vm;
|
|
3097
|
+
let content = [];
|
|
3098
|
+
if (hasStyles(stylesheets)) {
|
|
3099
|
+
content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
|
|
3100
|
+
}
|
|
3101
|
+
// VM (component) stylesheets apply after template stylesheets
|
|
3102
|
+
if (hasStyles(vmStylesheets)) {
|
|
3103
|
+
shared.ArrayPush.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
|
|
3104
|
+
}
|
|
3105
|
+
return content;
|
|
3106
|
+
}
|
|
3107
|
+
// It might be worth caching this to avoid doing the lookup repeatedly, but
|
|
3108
|
+
// perf testing has not shown it to be a huge improvement yet:
|
|
3109
|
+
// https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
|
|
3110
|
+
function getNearestShadowComponent(vm) {
|
|
3111
|
+
let owner = vm;
|
|
3112
|
+
while (!shared.isNull(owner)) {
|
|
3113
|
+
if (owner.renderMode === 1 /* RenderMode.Shadow */) {
|
|
3114
|
+
return owner;
|
|
3115
|
+
}
|
|
3116
|
+
owner = owner.owner;
|
|
3117
|
+
}
|
|
3118
|
+
return owner;
|
|
3119
|
+
}
|
|
3120
|
+
/**
|
|
3121
|
+
* If the component that is currently being rendered uses scoped styles,
|
|
3122
|
+
* this returns the unique token for that scoped stylesheet. Otherwise
|
|
3123
|
+
* it returns null.
|
|
3124
|
+
* @param owner
|
|
3125
|
+
* @param legacy
|
|
3126
|
+
*/
|
|
3127
|
+
// TODO [#3733]: remove support for legacy scope tokens
|
|
3128
|
+
function getScopeTokenClass(owner, legacy) {
|
|
3129
|
+
const { cmpTemplate, context } = owner;
|
|
3130
|
+
return ((context.hasScopedStyles &&
|
|
3131
|
+
(legacy ? cmpTemplate?.legacyStylesheetToken : cmpTemplate?.stylesheetToken)) ||
|
|
3132
|
+
null);
|
|
3133
|
+
}
|
|
3134
|
+
/**
|
|
3135
|
+
* This function returns the host style token for a custom element if it
|
|
3136
|
+
* exists. Otherwise it returns null.
|
|
3137
|
+
*
|
|
3138
|
+
* A host style token is applied to the component if scoped styles are used.
|
|
3139
|
+
* @param vnode
|
|
3140
|
+
*/
|
|
3141
|
+
function getStylesheetTokenHost(vnode) {
|
|
3142
|
+
const { template } = getComponentInternalDef(vnode.ctor);
|
|
3143
|
+
const { vm } = vnode;
|
|
3144
|
+
const { stylesheetToken } = template;
|
|
3145
|
+
return !shared.isUndefined(stylesheetToken) && computeHasScopedStyles(template, vm)
|
|
3146
|
+
? makeHostToken(stylesheetToken)
|
|
3147
|
+
: null;
|
|
3148
|
+
}
|
|
3149
|
+
function getNearestNativeShadowComponent(vm) {
|
|
3150
|
+
const owner = getNearestShadowComponent(vm);
|
|
3151
|
+
if (!shared.isNull(owner) && owner.shadowMode === 1 /* ShadowMode.Synthetic */) {
|
|
3152
|
+
// Synthetic-within-native is impossible. So if the nearest shadow component is
|
|
3153
|
+
// synthetic, we know we won't find a native component if we go any further.
|
|
3154
|
+
return null;
|
|
3155
|
+
}
|
|
3156
|
+
return owner;
|
|
3157
|
+
}
|
|
3158
|
+
function createStylesheet(vm, stylesheets) {
|
|
3159
|
+
const { renderMode, shadowMode, renderer: { insertStylesheet }, } = vm;
|
|
3160
|
+
if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
|
|
3161
|
+
for (let i = 0; i < stylesheets.length; i++) {
|
|
3162
|
+
const stylesheet = stylesheets[i];
|
|
3163
|
+
insertStylesheet(stylesheet, undefined, getOrCreateAbortSignal(stylesheet));
|
|
3164
|
+
}
|
|
3165
|
+
}
|
|
3166
|
+
else if (!process.env.IS_BROWSER || vm.hydrated) {
|
|
3167
|
+
// Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
|
|
3168
|
+
// This works in the client, because the stylesheets are created, and cached in the VM
|
|
3169
|
+
// the first time the VM renders.
|
|
3170
|
+
// native shadow or light DOM, SSR
|
|
3171
|
+
return shared.ArrayMap.call(stylesheets, createInlineStyleVNode);
|
|
3172
|
+
}
|
|
3173
|
+
else {
|
|
3174
|
+
// native shadow or light DOM, DOM renderer
|
|
3175
|
+
const root = getNearestNativeShadowComponent(vm);
|
|
3176
|
+
// null root means a global style
|
|
3177
|
+
const target = shared.isNull(root) ? undefined : root.shadowRoot;
|
|
3178
|
+
for (let i = 0; i < stylesheets.length; i++) {
|
|
3179
|
+
const stylesheet = stylesheets[i];
|
|
3180
|
+
insertStylesheet(stylesheet, target, getOrCreateAbortSignal(stylesheet));
|
|
3181
|
+
}
|
|
3182
|
+
}
|
|
3183
|
+
return null;
|
|
3184
|
+
}
|
|
3185
|
+
function unrenderStylesheet(stylesheet) {
|
|
3186
|
+
// should never leak to prod; only used for HMR
|
|
3187
|
+
assertNotProd();
|
|
3188
|
+
const cssContents = stylesheetsToCssContent.get(stylesheet);
|
|
3189
|
+
/* istanbul ignore if */
|
|
3190
|
+
if (shared.isUndefined(cssContents)) {
|
|
3191
|
+
throw new Error('Cannot unrender stylesheet which was never rendered');
|
|
3192
|
+
}
|
|
3193
|
+
for (const cssContent of cssContents) {
|
|
3194
|
+
const abortController = cssContentToAbortControllers.get(cssContent);
|
|
3195
|
+
/* istanbul ignore if */
|
|
3196
|
+
if (shared.isUndefined(abortController)) {
|
|
3197
|
+
throw new Error('Cannot find AbortController for CSS content');
|
|
3198
|
+
}
|
|
3199
|
+
abortController.abort();
|
|
3200
|
+
// remove association with AbortController in case stylesheet is rendered again
|
|
3201
|
+
cssContentToAbortControllers.delete(cssContent);
|
|
3202
|
+
}
|
|
3203
|
+
}
|
|
3204
|
+
|
|
2915
3205
|
/*
|
|
2916
3206
|
* Copyright (c) 2023, salesforce.com, inc.
|
|
2917
3207
|
* All rights reserved.
|
|
@@ -3005,16 +3295,31 @@ const WeakMultiMap = supportsWeakRefs ? ModernWeakMultiMap : LegacyWeakMultiMap;
|
|
|
3005
3295
|
* SPDX-License-Identifier: MIT
|
|
3006
3296
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
3007
3297
|
*/
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3298
|
+
let swappedTemplateMap = /*@__PURE__@*/ new WeakMap();
|
|
3299
|
+
let swappedComponentMap =
|
|
3300
|
+
/*@__PURE__@*/ new WeakMap();
|
|
3301
|
+
let swappedStyleMap = /*@__PURE__@*/ new WeakMap();
|
|
3011
3302
|
// The important thing here is the weak values – VMs are transient (one per component instance) and should be GC'ed,
|
|
3012
3303
|
// so we don't want to create strong references to them.
|
|
3013
3304
|
// The weak keys are kind of useless, because Templates, LightningElementConstructors, and StylesheetFactories are
|
|
3014
3305
|
// never GC'ed. But maybe they will be someday, so we may as well use weak keys too.
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3306
|
+
// The "pure" annotations are so that Rollup knows for sure it can remove these from prod mode
|
|
3307
|
+
let activeTemplates = /*@__PURE__@*/ new WeakMultiMap();
|
|
3308
|
+
let activeComponents =
|
|
3309
|
+
/*@__PURE__@*/ new WeakMultiMap();
|
|
3310
|
+
let activeStyles = /*@__PURE__@*/ new WeakMultiMap();
|
|
3311
|
+
// Only used in LWC's Karma tests
|
|
3312
|
+
if (process.env.NODE_ENV === 'test-karma-lwc') {
|
|
3313
|
+
// Used to reset the global state between test runs
|
|
3314
|
+
window.__lwcResetHotSwaps = () => {
|
|
3315
|
+
swappedTemplateMap = new WeakMap();
|
|
3316
|
+
swappedComponentMap = new WeakMap();
|
|
3317
|
+
swappedStyleMap = new WeakMap();
|
|
3318
|
+
activeTemplates = new WeakMultiMap();
|
|
3319
|
+
activeComponents = new WeakMultiMap();
|
|
3320
|
+
activeStyles = new WeakMultiMap();
|
|
3321
|
+
};
|
|
3322
|
+
}
|
|
3018
3323
|
function rehydrateHotTemplate(tpl) {
|
|
3019
3324
|
const list = activeTemplates.get(tpl);
|
|
3020
3325
|
for (const vm of list) {
|
|
@@ -3030,8 +3335,9 @@ function rehydrateHotTemplate(tpl) {
|
|
|
3030
3335
|
return true;
|
|
3031
3336
|
}
|
|
3032
3337
|
function rehydrateHotStyle(style) {
|
|
3033
|
-
const
|
|
3034
|
-
|
|
3338
|
+
const activeVMs = activeStyles.get(style);
|
|
3339
|
+
unrenderStylesheet(style);
|
|
3340
|
+
for (const vm of activeVMs) {
|
|
3035
3341
|
// if a style definition is swapped, we must reset
|
|
3036
3342
|
// vm's template content in the next micro-task:
|
|
3037
3343
|
forceRehydration(vm);
|
|
@@ -3068,6 +3374,7 @@ function rehydrateHotComponent(Ctor) {
|
|
|
3068
3374
|
}
|
|
3069
3375
|
function getTemplateOrSwappedTemplate(tpl) {
|
|
3070
3376
|
assertNotProd(); // this method should never leak to prod
|
|
3377
|
+
// TODO [#4154]: shows stale content when swapping content back and forth multiple times
|
|
3071
3378
|
const visited = new Set();
|
|
3072
3379
|
while (swappedTemplateMap.has(tpl) && !visited.has(tpl)) {
|
|
3073
3380
|
visited.add(tpl);
|
|
@@ -3077,6 +3384,7 @@ function getTemplateOrSwappedTemplate(tpl) {
|
|
|
3077
3384
|
}
|
|
3078
3385
|
function getComponentOrSwappedComponent(Ctor) {
|
|
3079
3386
|
assertNotProd(); // this method should never leak to prod
|
|
3387
|
+
// TODO [#4154]: shows stale content when swapping content back and forth multiple times
|
|
3080
3388
|
const visited = new Set();
|
|
3081
3389
|
while (swappedComponentMap.has(Ctor) && !visited.has(Ctor)) {
|
|
3082
3390
|
visited.add(Ctor);
|
|
@@ -3086,6 +3394,7 @@ function getComponentOrSwappedComponent(Ctor) {
|
|
|
3086
3394
|
}
|
|
3087
3395
|
function getStyleOrSwappedStyle(style) {
|
|
3088
3396
|
assertNotProd(); // this method should never leak to prod
|
|
3397
|
+
// TODO [#4154]: shows stale content when swapping content back and forth multiple times
|
|
3089
3398
|
const visited = new Set();
|
|
3090
3399
|
while (swappedStyleMap.has(style) && !visited.has(style)) {
|
|
3091
3400
|
visited.add(style);
|
|
@@ -3093,6 +3402,22 @@ function getStyleOrSwappedStyle(style) {
|
|
|
3093
3402
|
}
|
|
3094
3403
|
return style;
|
|
3095
3404
|
}
|
|
3405
|
+
function addActiveStylesheets(stylesheets, vm) {
|
|
3406
|
+
if (shared.isUndefined(stylesheets) || shared.isNull(stylesheets)) {
|
|
3407
|
+
// Ignore non-existent stylesheets
|
|
3408
|
+
return;
|
|
3409
|
+
}
|
|
3410
|
+
for (const stylesheet of flattenStylesheets(stylesheets)) {
|
|
3411
|
+
// this is necessary because we don't hold the list of styles
|
|
3412
|
+
// in the vm, we only hold the selected (already swapped template)
|
|
3413
|
+
// but the styles attached to the template might not be the actual
|
|
3414
|
+
// active ones, but the swapped versions of those.
|
|
3415
|
+
const swappedStylesheet = getStyleOrSwappedStyle(stylesheet);
|
|
3416
|
+
// this will allow us to keep track of the stylesheet that are
|
|
3417
|
+
// being used by a hot component
|
|
3418
|
+
activeStyles.add(swappedStylesheet, vm);
|
|
3419
|
+
}
|
|
3420
|
+
}
|
|
3096
3421
|
function setActiveVM(vm) {
|
|
3097
3422
|
assertNotProd(); // this method should never leak to prod
|
|
3098
3423
|
// tracking active component
|
|
@@ -3100,25 +3425,15 @@ function setActiveVM(vm) {
|
|
|
3100
3425
|
// this will allow us to keep track of the hot components
|
|
3101
3426
|
activeComponents.add(Ctor, vm);
|
|
3102
3427
|
// tracking active template
|
|
3103
|
-
const
|
|
3104
|
-
if (
|
|
3428
|
+
const template = vm.cmpTemplate;
|
|
3429
|
+
if (!shared.isNull(template)) {
|
|
3105
3430
|
// this will allow us to keep track of the templates that are
|
|
3106
3431
|
// being used by a hot component
|
|
3107
|
-
activeTemplates.add(
|
|
3108
|
-
//
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
// this is necessary because we don't hold the list of styles
|
|
3113
|
-
// in the vm, we only hold the selected (already swapped template)
|
|
3114
|
-
// but the styles attached to the template might not be the actual
|
|
3115
|
-
// active ones, but the swapped versions of those.
|
|
3116
|
-
const swappedStylesheet = getStyleOrSwappedStyle(stylesheet);
|
|
3117
|
-
// this will allow us to keep track of the stylesheet that are
|
|
3118
|
-
// being used by a hot component
|
|
3119
|
-
activeStyles.add(swappedStylesheet, vm);
|
|
3120
|
-
}
|
|
3121
|
-
}
|
|
3432
|
+
activeTemplates.add(template, vm);
|
|
3433
|
+
// Tracking active styles from the template or the VM. `template.stylesheets` are implicitly associated
|
|
3434
|
+
// (e.g. `foo.css` associated with `foo.html`), whereas `vm.stylesheets` are from `static stylesheets`.
|
|
3435
|
+
addActiveStylesheets(template.stylesheets, vm);
|
|
3436
|
+
addActiveStylesheets(vm.stylesheets, vm);
|
|
3122
3437
|
}
|
|
3123
3438
|
}
|
|
3124
3439
|
function swapTemplate(oldTpl, newTpl) {
|
|
@@ -3400,232 +3715,6 @@ function getComponentDef(Ctor) {
|
|
|
3400
3715
|
};
|
|
3401
3716
|
}
|
|
3402
3717
|
|
|
3403
|
-
/*
|
|
3404
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
3405
|
-
* All rights reserved.
|
|
3406
|
-
* SPDX-License-Identifier: MIT
|
|
3407
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
3408
|
-
*/
|
|
3409
|
-
function makeHostToken(token) {
|
|
3410
|
-
// Note: if this ever changes, update the `cssScopeTokens` returned by `@lwc/compiler`
|
|
3411
|
-
return `${token}-host`;
|
|
3412
|
-
}
|
|
3413
|
-
function createInlineStyleVNode(content) {
|
|
3414
|
-
return api.h('style', {
|
|
3415
|
-
key: 'style', // special key
|
|
3416
|
-
attrs: {
|
|
3417
|
-
type: 'text/css',
|
|
3418
|
-
},
|
|
3419
|
-
}, [api.t(content)]);
|
|
3420
|
-
}
|
|
3421
|
-
// TODO [#3733]: remove support for legacy scope tokens
|
|
3422
|
-
function updateStylesheetToken(vm, template, legacy) {
|
|
3423
|
-
const { elm, context, renderMode, shadowMode, renderer: { getClassList, removeAttribute, setAttribute }, } = vm;
|
|
3424
|
-
const { stylesheets: newStylesheets } = template;
|
|
3425
|
-
const newStylesheetToken = legacy ? template.legacyStylesheetToken : template.stylesheetToken;
|
|
3426
|
-
const { stylesheets: newVmStylesheets } = vm;
|
|
3427
|
-
const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
|
|
3428
|
-
const { hasScopedStyles } = context;
|
|
3429
|
-
let newToken;
|
|
3430
|
-
let newHasTokenInClass;
|
|
3431
|
-
let newHasTokenInAttribute;
|
|
3432
|
-
// Reset the styling token applied to the host element.
|
|
3433
|
-
let oldToken;
|
|
3434
|
-
let oldHasTokenInClass;
|
|
3435
|
-
let oldHasTokenInAttribute;
|
|
3436
|
-
if (legacy) {
|
|
3437
|
-
oldToken = context.legacyStylesheetToken;
|
|
3438
|
-
oldHasTokenInClass = context.hasLegacyTokenInClass;
|
|
3439
|
-
oldHasTokenInAttribute = context.hasLegacyTokenInAttribute;
|
|
3440
|
-
}
|
|
3441
|
-
else {
|
|
3442
|
-
oldToken = context.stylesheetToken;
|
|
3443
|
-
oldHasTokenInClass = context.hasTokenInClass;
|
|
3444
|
-
oldHasTokenInAttribute = context.hasTokenInAttribute;
|
|
3445
|
-
}
|
|
3446
|
-
if (!shared.isUndefined(oldToken)) {
|
|
3447
|
-
if (oldHasTokenInClass) {
|
|
3448
|
-
getClassList(elm).remove(makeHostToken(oldToken));
|
|
3449
|
-
}
|
|
3450
|
-
if (oldHasTokenInAttribute) {
|
|
3451
|
-
removeAttribute(elm, makeHostToken(oldToken));
|
|
3452
|
-
}
|
|
3453
|
-
}
|
|
3454
|
-
// Apply the new template styling token to the host element, if the new template has any
|
|
3455
|
-
// associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
|
|
3456
|
-
const hasNewStylesheets = hasStyles(newStylesheets);
|
|
3457
|
-
const hasNewVmStylesheets = hasStyles(newVmStylesheets);
|
|
3458
|
-
if (hasNewStylesheets || hasNewVmStylesheets) {
|
|
3459
|
-
newToken = newStylesheetToken;
|
|
3460
|
-
}
|
|
3461
|
-
// Set the new styling token on the host element
|
|
3462
|
-
if (!shared.isUndefined(newToken)) {
|
|
3463
|
-
if (hasScopedStyles) {
|
|
3464
|
-
getClassList(elm).add(makeHostToken(newToken));
|
|
3465
|
-
newHasTokenInClass = true;
|
|
3466
|
-
}
|
|
3467
|
-
if (isSyntheticShadow) {
|
|
3468
|
-
setAttribute(elm, makeHostToken(newToken), '');
|
|
3469
|
-
newHasTokenInAttribute = true;
|
|
3470
|
-
}
|
|
3471
|
-
}
|
|
3472
|
-
// Update the styling tokens present on the context object.
|
|
3473
|
-
if (legacy) {
|
|
3474
|
-
context.legacyStylesheetToken = newToken;
|
|
3475
|
-
context.hasLegacyTokenInClass = newHasTokenInClass;
|
|
3476
|
-
context.hasLegacyTokenInAttribute = newHasTokenInAttribute;
|
|
3477
|
-
}
|
|
3478
|
-
else {
|
|
3479
|
-
context.stylesheetToken = newToken;
|
|
3480
|
-
context.hasTokenInClass = newHasTokenInClass;
|
|
3481
|
-
context.hasTokenInAttribute = newHasTokenInAttribute;
|
|
3482
|
-
}
|
|
3483
|
-
}
|
|
3484
|
-
function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
|
|
3485
|
-
const content = [];
|
|
3486
|
-
let root;
|
|
3487
|
-
for (let i = 0; i < stylesheets.length; i++) {
|
|
3488
|
-
let stylesheet = stylesheets[i];
|
|
3489
|
-
if (shared.isArray(stylesheet)) {
|
|
3490
|
-
shared.ArrayPush.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
|
|
3491
|
-
}
|
|
3492
|
-
else {
|
|
3493
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
3494
|
-
// Check for compiler version mismatch in dev mode only
|
|
3495
|
-
checkVersionMismatch(stylesheet, 'stylesheet');
|
|
3496
|
-
// in dev-mode, we support hot swapping of stylesheet, which means that
|
|
3497
|
-
// the component instance might be attempting to use an old version of
|
|
3498
|
-
// the stylesheet, while internally, we have a replacement for it.
|
|
3499
|
-
stylesheet = getStyleOrSwappedStyle(stylesheet);
|
|
3500
|
-
}
|
|
3501
|
-
const isScopedCss = stylesheet[shared.KEY__SCOPED_CSS];
|
|
3502
|
-
if (lwcRuntimeFlags.DISABLE_LIGHT_DOM_UNSCOPED_CSS &&
|
|
3503
|
-
!isScopedCss &&
|
|
3504
|
-
vm.renderMode === 0 /* RenderMode.Light */) {
|
|
3505
|
-
logError('Unscoped CSS is not supported in Light DOM in this environment. Please use scoped CSS ' +
|
|
3506
|
-
'(*.scoped.css) instead of unscoped CSS (*.css). See also: https://sfdc.co/scoped-styles-light-dom');
|
|
3507
|
-
continue;
|
|
3508
|
-
}
|
|
3509
|
-
// Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
|
|
3510
|
-
const scopeToken = isScopedCss ||
|
|
3511
|
-
(vm.shadowMode === 1 /* ShadowMode.Synthetic */ && vm.renderMode === 1 /* RenderMode.Shadow */)
|
|
3512
|
-
? stylesheetToken
|
|
3513
|
-
: undefined;
|
|
3514
|
-
// Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
|
|
3515
|
-
// native shadow DOM. Synthetic shadow DOM never uses `:host`.
|
|
3516
|
-
const useActualHostSelector = vm.renderMode === 0 /* RenderMode.Light */
|
|
3517
|
-
? !isScopedCss
|
|
3518
|
-
: vm.shadowMode === 0 /* ShadowMode.Native */;
|
|
3519
|
-
// Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
|
|
3520
|
-
// we use an attribute selector on the host to simulate :dir().
|
|
3521
|
-
let useNativeDirPseudoclass;
|
|
3522
|
-
if (vm.renderMode === 1 /* RenderMode.Shadow */) {
|
|
3523
|
-
useNativeDirPseudoclass = vm.shadowMode === 0 /* ShadowMode.Native */;
|
|
3524
|
-
}
|
|
3525
|
-
else {
|
|
3526
|
-
// Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
|
|
3527
|
-
// At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
|
|
3528
|
-
if (shared.isUndefined(root)) {
|
|
3529
|
-
// Only calculate the root once as necessary
|
|
3530
|
-
root = getNearestShadowComponent(vm);
|
|
3531
|
-
}
|
|
3532
|
-
useNativeDirPseudoclass = shared.isNull(root) || root.shadowMode === 0 /* ShadowMode.Native */;
|
|
3533
|
-
}
|
|
3534
|
-
shared.ArrayPush.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
|
|
3535
|
-
}
|
|
3536
|
-
}
|
|
3537
|
-
return content;
|
|
3538
|
-
}
|
|
3539
|
-
function getStylesheetsContent(vm, template) {
|
|
3540
|
-
const { stylesheets, stylesheetToken } = template;
|
|
3541
|
-
const { stylesheets: vmStylesheets } = vm;
|
|
3542
|
-
let content = [];
|
|
3543
|
-
if (hasStyles(stylesheets)) {
|
|
3544
|
-
content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
|
|
3545
|
-
}
|
|
3546
|
-
// VM (component) stylesheets apply after template stylesheets
|
|
3547
|
-
if (hasStyles(vmStylesheets)) {
|
|
3548
|
-
shared.ArrayPush.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
|
|
3549
|
-
}
|
|
3550
|
-
return content;
|
|
3551
|
-
}
|
|
3552
|
-
// It might be worth caching this to avoid doing the lookup repeatedly, but
|
|
3553
|
-
// perf testing has not shown it to be a huge improvement yet:
|
|
3554
|
-
// https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
|
|
3555
|
-
function getNearestShadowComponent(vm) {
|
|
3556
|
-
let owner = vm;
|
|
3557
|
-
while (!shared.isNull(owner)) {
|
|
3558
|
-
if (owner.renderMode === 1 /* RenderMode.Shadow */) {
|
|
3559
|
-
return owner;
|
|
3560
|
-
}
|
|
3561
|
-
owner = owner.owner;
|
|
3562
|
-
}
|
|
3563
|
-
return owner;
|
|
3564
|
-
}
|
|
3565
|
-
/**
|
|
3566
|
-
* If the component that is currently being rendered uses scoped styles,
|
|
3567
|
-
* this returns the unique token for that scoped stylesheet. Otherwise
|
|
3568
|
-
* it returns null.
|
|
3569
|
-
* @param owner
|
|
3570
|
-
* @param legacy
|
|
3571
|
-
*/
|
|
3572
|
-
// TODO [#3733]: remove support for legacy scope tokens
|
|
3573
|
-
function getScopeTokenClass(owner, legacy) {
|
|
3574
|
-
const { cmpTemplate, context } = owner;
|
|
3575
|
-
return ((context.hasScopedStyles &&
|
|
3576
|
-
(legacy ? cmpTemplate?.legacyStylesheetToken : cmpTemplate?.stylesheetToken)) ||
|
|
3577
|
-
null);
|
|
3578
|
-
}
|
|
3579
|
-
/**
|
|
3580
|
-
* This function returns the host style token for a custom element if it
|
|
3581
|
-
* exists. Otherwise it returns null.
|
|
3582
|
-
*
|
|
3583
|
-
* A host style token is applied to the component if scoped styles are used.
|
|
3584
|
-
* @param vnode
|
|
3585
|
-
*/
|
|
3586
|
-
function getStylesheetTokenHost(vnode) {
|
|
3587
|
-
const { template } = getComponentInternalDef(vnode.ctor);
|
|
3588
|
-
const { vm } = vnode;
|
|
3589
|
-
const { stylesheetToken } = template;
|
|
3590
|
-
return !shared.isUndefined(stylesheetToken) && computeHasScopedStyles(template, vm)
|
|
3591
|
-
? makeHostToken(stylesheetToken)
|
|
3592
|
-
: null;
|
|
3593
|
-
}
|
|
3594
|
-
function getNearestNativeShadowComponent(vm) {
|
|
3595
|
-
const owner = getNearestShadowComponent(vm);
|
|
3596
|
-
if (!shared.isNull(owner) && owner.shadowMode === 1 /* ShadowMode.Synthetic */) {
|
|
3597
|
-
// Synthetic-within-native is impossible. So if the nearest shadow component is
|
|
3598
|
-
// synthetic, we know we won't find a native component if we go any further.
|
|
3599
|
-
return null;
|
|
3600
|
-
}
|
|
3601
|
-
return owner;
|
|
3602
|
-
}
|
|
3603
|
-
function createStylesheet(vm, stylesheets) {
|
|
3604
|
-
const { renderMode, shadowMode, renderer: { insertStylesheet }, } = vm;
|
|
3605
|
-
if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
|
|
3606
|
-
for (let i = 0; i < stylesheets.length; i++) {
|
|
3607
|
-
insertStylesheet(stylesheets[i]);
|
|
3608
|
-
}
|
|
3609
|
-
}
|
|
3610
|
-
else if (!process.env.IS_BROWSER || vm.hydrated) {
|
|
3611
|
-
// Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
|
|
3612
|
-
// This works in the client, because the stylesheets are created, and cached in the VM
|
|
3613
|
-
// the first time the VM renders.
|
|
3614
|
-
// native shadow or light DOM, SSR
|
|
3615
|
-
return shared.ArrayMap.call(stylesheets, createInlineStyleVNode);
|
|
3616
|
-
}
|
|
3617
|
-
else {
|
|
3618
|
-
// native shadow or light DOM, DOM renderer
|
|
3619
|
-
const root = getNearestNativeShadowComponent(vm);
|
|
3620
|
-
// null root means a global style
|
|
3621
|
-
const target = shared.isNull(root) ? undefined : root.shadowRoot;
|
|
3622
|
-
for (let i = 0; i < stylesheets.length; i++) {
|
|
3623
|
-
insertStylesheet(stylesheets[i], target);
|
|
3624
|
-
}
|
|
3625
|
-
}
|
|
3626
|
-
return null;
|
|
3627
|
-
}
|
|
3628
|
-
|
|
3629
3718
|
/*
|
|
3630
3719
|
* Copyright (c) 2024, Salesforce, Inc.
|
|
3631
3720
|
* All rights reserved.
|
|
@@ -7851,5 +7940,5 @@ exports.swapTemplate = swapTemplate;
|
|
|
7851
7940
|
exports.track = track;
|
|
7852
7941
|
exports.unwrap = unwrap;
|
|
7853
7942
|
exports.wire = wire;
|
|
7854
|
-
/** version: 6.
|
|
7943
|
+
/** version: 6.6.0 */
|
|
7855
7944
|
//# sourceMappingURL=index.cjs.js.map
|