@lwc/engine-core 7.2.1 → 7.2.3-alpha.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/fragment-cache.d.ts +6 -0
- package/dist/index.cjs.js +75 -44
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +76 -45
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const enum FragmentCacheKey {
|
|
2
|
+
HAS_SCOPED_STYLE = 1,
|
|
3
|
+
SHADOW_MODE_SYNTHETIC = 2
|
|
4
|
+
}
|
|
5
|
+
export declare function getFromFragmentCache(cacheKey: number, strings: string[]): Element | undefined;
|
|
6
|
+
export declare function setInFragmentCache(cacheKey: number, strings: string[], element: Element): void;
|
package/dist/index.cjs.js
CHANGED
|
@@ -155,7 +155,7 @@ function log(method, message, vm, once) {
|
|
|
155
155
|
}
|
|
156
156
|
alreadyLoggedMessages.add(msg);
|
|
157
157
|
}
|
|
158
|
-
// In
|
|
158
|
+
// In Vitest tests, reduce the warning and error verbosity by not printing the callstack
|
|
159
159
|
if (process.env.NODE_ENV === 'test') {
|
|
160
160
|
/* eslint-disable-next-line no-console */
|
|
161
161
|
console[method](msg);
|
|
@@ -1456,7 +1456,7 @@ async function fetchStylesheet(elm) {
|
|
|
1456
1456
|
try {
|
|
1457
1457
|
return await (await fetch(href)).text();
|
|
1458
1458
|
}
|
|
1459
|
-
catch (
|
|
1459
|
+
catch (_err) {
|
|
1460
1460
|
logWarnOnce(`Ignoring cross-origin stylesheet in migrate mode: ${href}`);
|
|
1461
1461
|
// ignore errors with cross-origin stylesheets - nothing we can do for those
|
|
1462
1462
|
return '';
|
|
@@ -5259,22 +5259,30 @@ function s(slotName, data, children, slotset) {
|
|
|
5259
5259
|
if (renderMode === 0 /* RenderMode.Light */ &&
|
|
5260
5260
|
shared.isAPIFeatureEnabled(6 /* APIFeature.USE_LIGHT_DOM_SLOT_FORWARDING */, apiVersion) &&
|
|
5261
5261
|
(isVBaseElement(vnode) || isVStatic(vnode)) &&
|
|
5262
|
-
// We only need to copy the vnodes when the slot assignment changes, copying every time causes issues with
|
|
5263
|
-
// disconnected/connected callback firing.
|
|
5264
5262
|
vnode.slotAssignment !== data.slotAssignment) {
|
|
5265
|
-
// When the light DOM slot assignment (slot attribute) changes we can't use the same reference
|
|
5266
|
-
// to the vnode because the current way the diffing algo works, it will replace the original
|
|
5267
|
-
// to the host element with a new one. This means the new element will be mounted and
|
|
5268
|
-
// Creating a copy of the vnode
|
|
5269
|
-
|
|
5270
|
-
|
|
5271
|
-
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5263
|
+
// When the light DOM slot assignment (slot attribute) changes, we can't use the same reference
|
|
5264
|
+
// to the vnode because the current way the diffing algo works, it will replace the original
|
|
5265
|
+
// reference to the host element with a new one. This means the new element will be mounted and
|
|
5266
|
+
// immediately unmounted. Creating a copy of the vnode preserves a reference to the previous
|
|
5267
|
+
// host element.
|
|
5268
|
+
clonedVNode = { ...vnode, slotAssignment: data.slotAssignment };
|
|
5269
|
+
// For disconnectedCallback to work correctly in synthetic lifecycle mode, we need to link the
|
|
5270
|
+
// current VM's velements to the clone, so that when the VM unmounts, the clone also unmounts.
|
|
5271
|
+
// Note this only applies to VCustomElements, since those are the elements that we manually need
|
|
5272
|
+
// to call disconnectedCallback for, when running in synthetic lifecycle mode.
|
|
5273
|
+
//
|
|
5274
|
+
// You might think it would make more sense to add the clonedVNode to the same velements array
|
|
5275
|
+
// as the original vnode's VM (i.e. `vnode.owner.velements`) rather than the current VM (i.e.
|
|
5276
|
+
// `vmBeingRendered.velements`), but this actually might not trigger disconnectedCallback
|
|
5277
|
+
// in synthetic lifecycle mode. The reason for this is that a reactivity change may cause
|
|
5278
|
+
// the slottable component to unmount, but _not_ the slotter component (see issue #4446).
|
|
5279
|
+
//
|
|
5280
|
+
// If this occurs, then the slottable component (i.e .this component we are rendering right
|
|
5281
|
+
// now) is the one that needs to own the clone. Whereas if a reactivity change higher in the
|
|
5282
|
+
// tree causes the slotter to unmount, then the slottable will also unmount. So using the
|
|
5283
|
+
// current VM works either way.
|
|
5284
|
+
if (isVCustomElement(vnode)) {
|
|
5285
|
+
addVNodeToChildLWC(clonedVNode);
|
|
5278
5286
|
}
|
|
5279
5287
|
}
|
|
5280
5288
|
// If the slot content is standard type, the content is static, no additional
|
|
@@ -5796,6 +5804,44 @@ function logGlobalOperationEnd(opId, vm) {
|
|
|
5796
5804
|
}
|
|
5797
5805
|
}
|
|
5798
5806
|
|
|
5807
|
+
/*
|
|
5808
|
+
* Copyright (c) 2024, Salesforce, Inc.
|
|
5809
|
+
* All rights reserved.
|
|
5810
|
+
* SPDX-License-Identifier: MIT
|
|
5811
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
5812
|
+
*/
|
|
5813
|
+
// HAS_SCOPED_STYLE | SHADOW_MODE_SYNTHETIC = 3
|
|
5814
|
+
const MAX_CACHE_KEY = 3;
|
|
5815
|
+
// Mapping of cacheKeys to `string[]` (assumed to come from a tagged template literal) to an Element.
|
|
5816
|
+
// Note that every unique tagged template literal will have a unique `string[]`. So by using `string[]`
|
|
5817
|
+
// as the WeakMap key, we effectively associate each Element with a unique tagged template literal.
|
|
5818
|
+
// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates
|
|
5819
|
+
// Also note that this array only needs to be large enough to account for the maximum possible cache key
|
|
5820
|
+
const fragmentCache = shared.ArrayFrom({ length: MAX_CACHE_KEY + 1 }, () => new WeakMap());
|
|
5821
|
+
// Only used in LWC's Karma tests
|
|
5822
|
+
if (process.env.NODE_ENV === 'test-karma-lwc') {
|
|
5823
|
+
window.__lwcResetFragmentCache = () => {
|
|
5824
|
+
for (let i = 0; i < fragmentCache.length; i++) {
|
|
5825
|
+
fragmentCache[i] = new WeakMap();
|
|
5826
|
+
}
|
|
5827
|
+
};
|
|
5828
|
+
}
|
|
5829
|
+
function checkIsBrowser() {
|
|
5830
|
+
// The fragment cache only serves prevent calling innerHTML multiple times which doesn't happen on the server.
|
|
5831
|
+
/* istanbul ignore next */
|
|
5832
|
+
if (!process.env.IS_BROWSER) {
|
|
5833
|
+
throw new Error('The fragment cache is intended to only be used in @lwc/engine-dom, not @lwc/engine-server');
|
|
5834
|
+
}
|
|
5835
|
+
}
|
|
5836
|
+
function getFromFragmentCache(cacheKey, strings) {
|
|
5837
|
+
checkIsBrowser();
|
|
5838
|
+
return fragmentCache[cacheKey].get(strings);
|
|
5839
|
+
}
|
|
5840
|
+
function setInFragmentCache(cacheKey, strings, element) {
|
|
5841
|
+
checkIsBrowser();
|
|
5842
|
+
fragmentCache[cacheKey].set(strings, element);
|
|
5843
|
+
}
|
|
5844
|
+
|
|
5799
5845
|
/*
|
|
5800
5846
|
* Copyright (c) 2024, Salesforce, Inc.
|
|
5801
5847
|
* All rights reserved.
|
|
@@ -5939,43 +5985,24 @@ function serializeClassAttribute(part, classToken) {
|
|
|
5939
5985
|
const computedClassName = `${classToken} ${shared.keys(classMap).join(' ')}`.trim();
|
|
5940
5986
|
return computedClassName.length ? ` class="${shared.htmlEscape(computedClassName, true)}"` : '';
|
|
5941
5987
|
}
|
|
5942
|
-
// This should be a no-op outside of LWC's Karma tests, where it's not needed
|
|
5943
|
-
let registerFragmentCache = shared.noop;
|
|
5944
|
-
// Only used in LWC's Karma tests
|
|
5945
|
-
if (process.env.NODE_ENV === 'test-karma-lwc') {
|
|
5946
|
-
// Keep track of fragmentCaches, so we can clear them in LWC's Karma tests
|
|
5947
|
-
const fragmentCaches = [];
|
|
5948
|
-
registerFragmentCache = (fragmentCache) => {
|
|
5949
|
-
fragmentCaches.push(fragmentCache);
|
|
5950
|
-
};
|
|
5951
|
-
window.__lwcResetFragmentCaches = () => {
|
|
5952
|
-
for (const fragmentCache of fragmentCaches) {
|
|
5953
|
-
for (const key of shared.keys(fragmentCache)) {
|
|
5954
|
-
delete fragmentCache[key];
|
|
5955
|
-
}
|
|
5956
|
-
}
|
|
5957
|
-
};
|
|
5958
|
-
}
|
|
5959
5988
|
function buildParseFragmentFn(createFragmentFn) {
|
|
5960
|
-
return (strings, ...keys)
|
|
5961
|
-
|
|
5962
|
-
registerFragmentCache(cache);
|
|
5963
|
-
return function (parts) {
|
|
5989
|
+
return function parseFragment(strings, ...keys) {
|
|
5990
|
+
return function applyFragmentParts(parts) {
|
|
5964
5991
|
const { context: { hasScopedStyles, stylesheetToken, legacyStylesheetToken }, shadowMode, renderer, } = getVMBeingRendered();
|
|
5965
5992
|
const hasStyleToken = !shared.isUndefined(stylesheetToken);
|
|
5966
5993
|
const isSyntheticShadow = shadowMode === 1 /* ShadowMode.Synthetic */;
|
|
5967
5994
|
const hasLegacyToken = lwcRuntimeFlags.ENABLE_LEGACY_SCOPE_TOKENS && !shared.isUndefined(legacyStylesheetToken);
|
|
5968
5995
|
let cacheKey = 0;
|
|
5969
5996
|
if (hasStyleToken && hasScopedStyles) {
|
|
5970
|
-
cacheKey |= 1 /*
|
|
5997
|
+
cacheKey |= 1 /* FragmentCacheKey.HAS_SCOPED_STYLE */;
|
|
5971
5998
|
}
|
|
5972
5999
|
if (hasStyleToken && isSyntheticShadow) {
|
|
5973
|
-
cacheKey |= 2 /*
|
|
6000
|
+
cacheKey |= 2 /* FragmentCacheKey.SHADOW_MODE_SYNTHETIC */;
|
|
5974
6001
|
}
|
|
5975
6002
|
// Cache is only here to prevent calling innerHTML multiple times which doesn't happen on the server.
|
|
5976
6003
|
if (process.env.IS_BROWSER) {
|
|
5977
6004
|
// Disable this on the server to prevent cache poisoning when expressions are used.
|
|
5978
|
-
const cached =
|
|
6005
|
+
const cached = getFromFragmentCache(cacheKey, strings);
|
|
5979
6006
|
if (!shared.isUndefined(cached)) {
|
|
5980
6007
|
return cached;
|
|
5981
6008
|
}
|
|
@@ -6015,8 +6042,12 @@ function buildParseFragmentFn(createFragmentFn) {
|
|
|
6015
6042
|
}
|
|
6016
6043
|
}
|
|
6017
6044
|
htmlFragment += strings[strings.length - 1];
|
|
6018
|
-
|
|
6019
|
-
|
|
6045
|
+
const element = createFragmentFn(htmlFragment, renderer);
|
|
6046
|
+
// Cache is only here to prevent calling innerHTML multiple times which doesn't happen on the server.
|
|
6047
|
+
if (process.env.IS_BROWSER) {
|
|
6048
|
+
setInFragmentCache(cacheKey, strings, element);
|
|
6049
|
+
}
|
|
6050
|
+
return element;
|
|
6020
6051
|
};
|
|
6021
6052
|
};
|
|
6022
6053
|
}
|
|
@@ -8092,5 +8123,5 @@ exports.swapTemplate = swapTemplate;
|
|
|
8092
8123
|
exports.track = track;
|
|
8093
8124
|
exports.unwrap = unwrap;
|
|
8094
8125
|
exports.wire = wire;
|
|
8095
|
-
/** version: 7.2.
|
|
8126
|
+
/** version: 7.2.2 */
|
|
8096
8127
|
//# sourceMappingURL=index.cjs.js.map
|