@lwc/engine-core 2.37.2 → 2.38.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.
@@ -1801,6 +1801,14 @@ LightningElement.prototype = {
1801
1801
  }
1802
1802
  return renderer.getLastElementChild(vm.elm);
1803
1803
  },
1804
+ get ownerDocument() {
1805
+ const vm = getAssociatedVM(this);
1806
+ const renderer = vm.renderer;
1807
+ if (process.env.NODE_ENV !== 'production') {
1808
+ warnIfInvokedDuringConstruction(vm, 'ownerDocument');
1809
+ }
1810
+ return renderer.ownerDocument(vm.elm);
1811
+ },
1804
1812
  render() {
1805
1813
  const vm = getAssociatedVM(this);
1806
1814
  return vm.def.template;
@@ -1876,31 +1884,84 @@ function createObservedFieldPropertyDescriptor(key) {
1876
1884
  }
1877
1885
 
1878
1886
  /*
1879
- * Copyright (c) 2018, salesforce.com, inc.
1887
+ * Copyright (c) 2023, salesforce.com, inc.
1880
1888
  * All rights reserved.
1881
1889
  * SPDX-License-Identifier: MIT
1882
1890
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1883
1891
  */
1884
- const DeprecatedWiredElementHost = '$$DeprecatedWiredElementHostKey$$';
1885
- const DeprecatedWiredParamsMeta = '$$DeprecatedWiredParamsMetaKey$$';
1886
- const WIRE_DEBUG_ENTRY = '@wire';
1887
- const WireMetaMap = new Map();
1888
- class WireContextRegistrationEvent extends CustomEvent {
1889
- constructor(adapterToken, { setNewContext, setDisconnectedCallback }) {
1890
- super(adapterToken, {
1891
- bubbles: true,
1892
- composed: true,
1892
+ const AdapterToTokenMap = new Map();
1893
+ function createContextProviderWithRegister(adapter, registerContextProvider) {
1894
+ let adapterContextToken = AdapterToTokenMap.get(adapter);
1895
+ if (!shared.isUndefined(adapterContextToken)) {
1896
+ throw new Error(`Adapter already has a context provider.`);
1897
+ }
1898
+ adapterContextToken = guid();
1899
+ AdapterToTokenMap.set(adapter, adapterContextToken);
1900
+ const providers = new WeakSet();
1901
+ return (elmOrComponent, options) => {
1902
+ if (providers.has(elmOrComponent)) {
1903
+ throw new Error(`Adapter was already installed on ${elmOrComponent}.`);
1904
+ }
1905
+ providers.add(elmOrComponent);
1906
+ const { consumerConnectedCallback, consumerDisconnectedCallback } = options;
1907
+ registerContextProvider(elmOrComponent, adapterContextToken, (subscriptionPayload) => {
1908
+ const { setNewContext, setDisconnectedCallback } = subscriptionPayload;
1909
+ const consumer = {
1910
+ provide(newContext) {
1911
+ setNewContext(newContext);
1912
+ },
1913
+ };
1914
+ const disconnectCallback = () => {
1915
+ if (!shared.isUndefined(consumerDisconnectedCallback)) {
1916
+ consumerDisconnectedCallback(consumer);
1917
+ }
1918
+ };
1919
+ setDisconnectedCallback(disconnectCallback);
1920
+ consumerConnectedCallback(consumer);
1893
1921
  });
1894
- shared.defineProperties(this, {
1895
- setNewContext: {
1896
- value: setNewContext,
1922
+ };
1923
+ }
1924
+ function createContextWatcher(vm, wireDef, callbackWhenContextIsReady) {
1925
+ const { adapter } = wireDef;
1926
+ const adapterContextToken = AdapterToTokenMap.get(adapter);
1927
+ if (shared.isUndefined(adapterContextToken)) {
1928
+ return; // no provider found, nothing to be done
1929
+ }
1930
+ const { elm, context: { wiredConnecting, wiredDisconnecting }, renderer: { registerContextConsumer }, } = vm;
1931
+ // waiting for the component to be connected to formally request the context via the token
1932
+ shared.ArrayPush.call(wiredConnecting, () => {
1933
+ // This will attempt to connect the current element with one of its anscestors
1934
+ // that can provide context for the given wire adapter. This relationship is
1935
+ // keyed on the secret & internal value of `adapterContextToken`, which is unique
1936
+ // to a given wire adapter.
1937
+ //
1938
+ // Depending on the runtime environment, this connection is made using either DOM
1939
+ // events (in the browser) or a custom traversal (on the server).
1940
+ registerContextConsumer(elm, adapterContextToken, {
1941
+ setNewContext(newContext) {
1942
+ // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
1943
+ // TODO: dev-mode validation of config based on the adapter.contextSchema
1944
+ callbackWhenContextIsReady(newContext);
1897
1945
  },
1898
- setDisconnectedCallback: {
1899
- value: setDisconnectedCallback,
1946
+ setDisconnectedCallback(disconnectCallback) {
1947
+ // adds this callback into the disconnect bucket so it gets disconnected from parent
1948
+ // the the element hosting the wire is disconnected
1949
+ shared.ArrayPush.call(wiredDisconnecting, disconnectCallback);
1900
1950
  },
1901
1951
  });
1902
- }
1952
+ });
1903
1953
  }
1954
+
1955
+ /*
1956
+ * Copyright (c) 2023, salesforce.com, inc.
1957
+ * All rights reserved.
1958
+ * SPDX-License-Identifier: MIT
1959
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1960
+ */
1961
+ const DeprecatedWiredElementHost = '$$DeprecatedWiredElementHostKey$$';
1962
+ const DeprecatedWiredParamsMeta = '$$DeprecatedWiredParamsMetaKey$$';
1963
+ const WIRE_DEBUG_ENTRY = '@wire';
1964
+ const WireMetaMap = new Map();
1904
1965
  function createFieldDataCallback(vm, name) {
1905
1966
  return (value) => {
1906
1967
  updateComponentValue(vm, name, value);
@@ -1944,35 +2005,6 @@ function createConfigWatcher(component, configCallback, callbackWhenConfigIsRead
1944
2005
  ro,
1945
2006
  };
1946
2007
  }
1947
- function createContextWatcher(vm, wireDef, callbackWhenContextIsReady) {
1948
- const { adapter } = wireDef;
1949
- const adapterContextToken = getAdapterToken(adapter);
1950
- if (shared.isUndefined(adapterContextToken)) {
1951
- return; // no provider found, nothing to be done
1952
- }
1953
- const { elm, context: { wiredConnecting, wiredDisconnecting }, renderer: { dispatchEvent }, } = vm;
1954
- // waiting for the component to be connected to formally request the context via the token
1955
- shared.ArrayPush.call(wiredConnecting, () => {
1956
- // This event is responsible for connecting the host element with another
1957
- // element in the composed path that is providing contextual data. The provider
1958
- // must be listening for a special dom event with the name corresponding to the value of
1959
- // `adapterContextToken`, which will remain secret and internal to this file only to
1960
- // guarantee that the linkage can be forged.
1961
- const contextRegistrationEvent = new WireContextRegistrationEvent(adapterContextToken, {
1962
- setNewContext(newContext) {
1963
- // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
1964
- // TODO: dev-mode validation of config based on the adapter.contextSchema
1965
- callbackWhenContextIsReady(newContext);
1966
- },
1967
- setDisconnectedCallback(disconnectCallback) {
1968
- // adds this callback into the disconnect bucket so it gets disconnected from parent
1969
- // the the element hosting the wire is disconnected
1970
- shared.ArrayPush.call(wiredDisconnecting, disconnectCallback);
1971
- },
1972
- });
1973
- dispatchEvent(elm, contextRegistrationEvent);
1974
- });
1975
- }
1976
2008
  function createConnector(vm, name, wireDef) {
1977
2009
  const { method, adapter, configCallback, dynamic } = wireDef;
1978
2010
  let debugInfo;
@@ -2047,13 +2079,6 @@ function createConnector(vm, name, wireDef) {
2047
2079
  resetConfigWatcher: () => ro.reset(),
2048
2080
  };
2049
2081
  }
2050
- const AdapterToTokenMap = new Map();
2051
- function getAdapterToken(adapter) {
2052
- return AdapterToTokenMap.get(adapter);
2053
- }
2054
- function setAdapterToken(adapter, token) {
2055
- AdapterToTokenMap.set(adapter, token);
2056
- }
2057
2082
  function storeWiredMethodMeta(descriptor, adapter, configCallback, dynamic) {
2058
2083
  // support for callable adapters
2059
2084
  if (adapter.adapter) {
@@ -5870,6 +5895,10 @@ function forceRehydration(vm) {
5870
5895
  // Use the unpatched native getElementById/querySelectorAll rather than the synthetic one
5871
5896
  const getElementById = shared.globalThis[shared.KEY__NATIVE_GET_ELEMENT_BY_ID];
5872
5897
  const querySelectorAll = shared.globalThis[shared.KEY__NATIVE_QUERY_SELECTOR_ALL];
5898
+ // This is a "handoff" from synthetic-shadow to engine-core – we want to clean up after ourselves
5899
+ // so nobody else can misuse these global APIs.
5900
+ delete shared.globalThis[shared.KEY__NATIVE_GET_ELEMENT_BY_ID];
5901
+ delete shared.globalThis[shared.KEY__NATIVE_QUERY_SELECTOR_ALL];
5873
5902
  function isSyntheticShadowRootInstance(rootNode) {
5874
5903
  return rootNode !== document && shared.isTrue(rootNode.synthetic);
5875
5904
  }
@@ -6117,67 +6146,6 @@ if (process.env.IS_BROWSER) {
6117
6146
  }
6118
6147
  }
6119
6148
 
6120
- /*
6121
- * Copyright (c) 2018, salesforce.com, inc.
6122
- * All rights reserved.
6123
- * SPDX-License-Identifier: MIT
6124
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6125
- */
6126
- // this is lwc internal implementation
6127
- function createContextProvider(adapter) {
6128
- let adapterContextToken = getAdapterToken(adapter);
6129
- if (!shared.isUndefined(adapterContextToken)) {
6130
- throw new Error(`Adapter already has a context provider.`);
6131
- }
6132
- adapterContextToken = guid();
6133
- setAdapterToken(adapter, adapterContextToken);
6134
- const providers = new WeakSet();
6135
- return (elm, options) => {
6136
- if (providers.has(elm)) {
6137
- throw new Error(`Adapter was already installed on ${elm}.`);
6138
- }
6139
- providers.add(elm);
6140
- const { consumerConnectedCallback, consumerDisconnectedCallback } = options;
6141
- elm.addEventListener(adapterContextToken, ((evt) => {
6142
- const { setNewContext, setDisconnectedCallback } = evt;
6143
- const consumer = {
6144
- provide(newContext) {
6145
- setNewContext(newContext);
6146
- },
6147
- };
6148
- const disconnectCallback = () => {
6149
- if (!shared.isUndefined(consumerDisconnectedCallback)) {
6150
- consumerDisconnectedCallback(consumer);
6151
- }
6152
- };
6153
- setDisconnectedCallback(disconnectCallback);
6154
- consumerConnectedCallback(consumer);
6155
- evt.stopImmediatePropagation();
6156
- }));
6157
- };
6158
- }
6159
-
6160
- /*
6161
- * Copyright (c) 2018, salesforce.com, inc.
6162
- * All rights reserved.
6163
- * SPDX-License-Identifier: MIT
6164
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6165
- */
6166
- /**
6167
- * EXPERIMENTAL: This function allows you to create a reactive readonly
6168
- * membrane around any object value. This API is subject to change or
6169
- * being removed.
6170
- */
6171
- function readonly(obj) {
6172
- if (process.env.NODE_ENV !== 'production') {
6173
- // TODO [#1292]: Remove the readonly decorator
6174
- if (arguments.length !== 1) {
6175
- shared.assert.fail('@readonly cannot be used as a decorator just yet, use it as a function with one argument to produce a readonly version of the provided value.');
6176
- }
6177
- }
6178
- return getReadOnlyProxy(obj);
6179
- }
6180
-
6181
6149
  /*
6182
6150
  * Copyright (c) 2022, salesforce.com, inc.
6183
6151
  * All rights reserved.
@@ -6231,15 +6199,44 @@ function hydrateNode(node, vnode, renderer) {
6231
6199
  return renderer.nextSibling(hydratedNode);
6232
6200
  }
6233
6201
  const NODE_VALUE_PROP = 'nodeValue';
6202
+ const PARENT_NODE_PROP = 'parentNode';
6203
+ const TAG_NAME_PROP = 'tagName';
6204
+ function textNodeContentsAreEqual(node, vnode, renderer) {
6205
+ const { getProperty } = renderer;
6206
+ const nodeValue = getProperty(node, NODE_VALUE_PROP);
6207
+ if (nodeValue === vnode.text) {
6208
+ return true;
6209
+ }
6210
+ // Special case for empty text nodes – these are serialized differently on the server
6211
+ // See https://github.com/salesforce/lwc/pull/2656
6212
+ if (nodeValue === '\u200D' && vnode.text === '') {
6213
+ return true;
6214
+ }
6215
+ // Special case for text nodes inside `<style>` tags – these are escaped when rendered server-size,
6216
+ // but not when generated by the engine client-side.
6217
+ const parentNode = getProperty(node, PARENT_NODE_PROP);
6218
+ // Should never be null, but just to be safe, we check.
6219
+ /* istanbul ignore else */
6220
+ if (!shared.isNull(parentNode)) {
6221
+ const tagName = getProperty(parentNode, TAG_NAME_PROP);
6222
+ // If the tagName is STYLE, then the following condition should always be true.
6223
+ // The LWC compiler blocks using `<style>`s inside of templates, so it should be impossible
6224
+ // for component authors to render different `<style>` text content on the client and server.
6225
+ // But just to be safe, we check.
6226
+ /* istanbul ignore next */
6227
+ if (tagName === 'STYLE' && shared.htmlEscape(vnode.text) === nodeValue) {
6228
+ return true;
6229
+ }
6230
+ }
6231
+ return false;
6232
+ }
6234
6233
  function hydrateText(node, vnode, renderer) {
6235
6234
  var _a;
6236
6235
  if (!hasCorrectNodeType(vnode, node, 3 /* EnvNodeTypes.TEXT */, renderer)) {
6237
6236
  return handleMismatch(node, vnode, renderer);
6238
6237
  }
6239
6238
  if (process.env.NODE_ENV !== 'production') {
6240
- const { getProperty } = renderer;
6241
- const nodeValue = getProperty(node, NODE_VALUE_PROP);
6242
- if (nodeValue !== vnode.text && !(nodeValue === '\u200D' && vnode.text === '')) {
6239
+ if (!textNodeContentsAreEqual(node, vnode, renderer)) {
6243
6240
  logWarn('Hydration mismatch: text values do not match, will recover from the difference', vnode.owner);
6244
6241
  }
6245
6242
  }
@@ -6419,6 +6416,19 @@ function isMatchingElement(vnode, elm, renderer) {
6419
6416
  const hasIncompatibleStyle = validateStyleAttr(vnode, elm, renderer);
6420
6417
  return hasIncompatibleAttrs && hasIncompatibleClass && hasIncompatibleStyle;
6421
6418
  }
6419
+ function attributeValuesAreEqual(vnodeValue, value) {
6420
+ const vnodeValueAsString = String(vnodeValue);
6421
+ if (vnodeValueAsString === value) {
6422
+ return true;
6423
+ }
6424
+ // If the expected value is null, this means that the attribute does not exist. In that case,
6425
+ // we accept any nullish value (undefined or null).
6426
+ if (shared.isNull(value) && (shared.isUndefined(vnodeValue) || shared.isNull(vnodeValue))) {
6427
+ return true;
6428
+ }
6429
+ // In all other cases, the two values are not considered equal
6430
+ return false;
6431
+ }
6422
6432
  function validateAttrs(vnode, elm, renderer) {
6423
6433
  const { data: { attrs = {} }, } = vnode;
6424
6434
  let nodesAreCompatible = true;
@@ -6428,10 +6438,10 @@ function validateAttrs(vnode, elm, renderer) {
6428
6438
  const { owner } = vnode;
6429
6439
  const { getAttribute } = renderer;
6430
6440
  const elmAttrValue = getAttribute(elm, attrName);
6431
- if (String(attrValue) !== elmAttrValue) {
6441
+ if (!attributeValuesAreEqual(attrValue, elmAttrValue)) {
6432
6442
  if (process.env.NODE_ENV !== 'production') {
6433
6443
  const { getProperty } = renderer;
6434
- logError(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: attribute "${attrName}" has different values, expected "${attrValue}" but found "${elmAttrValue}"`, owner);
6444
+ logError(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: attribute "${attrName}" has different values, expected "${attrValue}" but found ${shared.isNull(elmAttrValue) ? 'null' : `"${elmAttrValue}"`}`, owner);
6435
6445
  }
6436
6446
  nodesAreCompatible = false;
6437
6447
  }
@@ -6826,6 +6836,27 @@ function getComponentConstructor(elm) {
6826
6836
  return ctor;
6827
6837
  }
6828
6838
 
6839
+ /*
6840
+ * Copyright (c) 2018, salesforce.com, inc.
6841
+ * All rights reserved.
6842
+ * SPDX-License-Identifier: MIT
6843
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6844
+ */
6845
+ /**
6846
+ * EXPERIMENTAL: This function allows you to create a reactive readonly
6847
+ * membrane around any object value. This API is subject to change or
6848
+ * being removed.
6849
+ */
6850
+ function readonly(obj) {
6851
+ if (process.env.NODE_ENV !== 'production') {
6852
+ // TODO [#1292]: Remove the readonly decorator
6853
+ if (arguments.length !== 1) {
6854
+ shared.assert.fail('@readonly cannot be used as a decorator just yet, use it as a function with one argument to produce a readonly version of the provided value.');
6855
+ }
6856
+ }
6857
+ return getReadOnlyProxy(obj);
6858
+ }
6859
+
6829
6860
  Object.defineProperty(exports, 'setFeatureFlag', {
6830
6861
  enumerable: true,
6831
6862
  get: function () { return features.setFeatureFlag; }
@@ -6839,7 +6870,7 @@ exports.__unstable__ProfilerControl = profilerControl;
6839
6870
  exports.__unstable__ReportingControl = reportingControl;
6840
6871
  exports.api = api$1;
6841
6872
  exports.connectRootElement = connectRootElement;
6842
- exports.createContextProvider = createContextProvider;
6873
+ exports.createContextProviderWithRegister = createContextProviderWithRegister;
6843
6874
  exports.createVM = createVM;
6844
6875
  exports.disconnectRootElement = disconnectRootElement;
6845
6876
  exports.freezeTemplate = freezeTemplate;
@@ -6864,4 +6895,5 @@ exports.swapTemplate = swapTemplate;
6864
6895
  exports.track = track;
6865
6896
  exports.unwrap = unwrap;
6866
6897
  exports.wire = wire;
6867
- /* version: 2.37.2 */
6898
+ /* version: 2.38.0 */
6899
+ //# sourceMappingURL=engine-core.cjs.js.map