@lwc/engine-core 2.5.8 → 2.6.1

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.
@@ -1428,10 +1428,10 @@ const {
1428
1428
  isArray
1429
1429
  } = Array;
1430
1430
  const {
1431
+ prototype: ObjectDotPrototype,
1431
1432
  getPrototypeOf,
1432
1433
  create: ObjectCreate,
1433
1434
  defineProperty: ObjectDefineProperty,
1434
- defineProperties: ObjectDefineProperties,
1435
1435
  isExtensible,
1436
1436
  getOwnPropertyDescriptor,
1437
1437
  getOwnPropertyNames,
@@ -1441,8 +1441,7 @@ const {
1441
1441
  } = Object;
1442
1442
  const {
1443
1443
  push: ArrayPush,
1444
- concat: ArrayConcat,
1445
- map: ArrayMap
1444
+ concat: ArrayConcat
1446
1445
  } = Array.prototype;
1447
1446
  const OtS = {}.toString;
1448
1447
 
@@ -1507,7 +1506,9 @@ class BaseProxyHandler {
1507
1506
  // but it will always be compatible with the previous descriptor
1508
1507
  // to preserve the object invariants, which makes these lines safe.
1509
1508
 
1510
- const originalDescriptor = getOwnPropertyDescriptor(originalTarget, key);
1509
+ const originalDescriptor = getOwnPropertyDescriptor(originalTarget, key); // TODO: it should be impossible for the originalDescriptor to ever be undefined, this `if` can be removed
1510
+
1511
+ /* istanbul ignore else */
1511
1512
 
1512
1513
  if (!isUndefined(originalDescriptor)) {
1513
1514
  const wrappedDesc = this.wrapDescriptor(originalDescriptor);
@@ -1535,11 +1536,17 @@ class BaseProxyHandler {
1535
1536
 
1536
1537
  preventExtensions(shadowTarget);
1537
1538
  } // Shared Traps
1539
+ // TODO: apply() is never called
1540
+
1541
+ /* istanbul ignore next */
1538
1542
 
1539
1543
 
1540
1544
  apply(shadowTarget, thisArg, argArray) {
1541
1545
  /* No op */
1542
- }
1546
+ } // TODO: construct() is never called
1547
+
1548
+ /* istanbul ignore next */
1549
+
1543
1550
 
1544
1551
  construct(shadowTarget, argArray, newTarget) {
1545
1552
  /* No op */
@@ -1652,8 +1659,8 @@ class BaseProxyHandler {
1652
1659
 
1653
1660
  }
1654
1661
 
1655
- const getterMap = new WeakMap();
1656
- const setterMap = new WeakMap();
1662
+ const getterMap$1 = new WeakMap();
1663
+ const setterMap$1 = new WeakMap();
1657
1664
  const reverseGetterMap = new WeakMap();
1658
1665
  const reverseSetterMap = new WeakMap();
1659
1666
 
@@ -1663,7 +1670,7 @@ class ReactiveProxyHandler extends BaseProxyHandler {
1663
1670
  }
1664
1671
 
1665
1672
  wrapGetter(originalGet) {
1666
- const wrappedGetter = getterMap.get(originalGet);
1673
+ const wrappedGetter = getterMap$1.get(originalGet);
1667
1674
 
1668
1675
  if (!isUndefined(wrappedGetter)) {
1669
1676
  return wrappedGetter;
@@ -1676,13 +1683,13 @@ class ReactiveProxyHandler extends BaseProxyHandler {
1676
1683
  return handler.wrapValue(originalGet.call(unwrap$1(this)));
1677
1684
  };
1678
1685
 
1679
- getterMap.set(originalGet, get);
1686
+ getterMap$1.set(originalGet, get);
1680
1687
  reverseGetterMap.set(get, originalGet);
1681
1688
  return get;
1682
1689
  }
1683
1690
 
1684
1691
  wrapSetter(originalSet) {
1685
- const wrappedSetter = setterMap.get(originalSet);
1692
+ const wrappedSetter = setterMap$1.get(originalSet);
1686
1693
 
1687
1694
  if (!isUndefined(wrappedSetter)) {
1688
1695
  return wrappedSetter;
@@ -1693,7 +1700,7 @@ class ReactiveProxyHandler extends BaseProxyHandler {
1693
1700
  originalSet.call(unwrap$1(this), unwrap$1(v));
1694
1701
  };
1695
1702
 
1696
- setterMap.set(originalSet, set);
1703
+ setterMap$1.set(originalSet, set);
1697
1704
  reverseSetterMap.set(set, originalSet);
1698
1705
  return set;
1699
1706
  }
@@ -1734,7 +1741,7 @@ class ReactiveProxyHandler extends BaseProxyHandler {
1734
1741
  return unwrap$1(redGet.call(handler.wrapValue(this)));
1735
1742
  };
1736
1743
 
1737
- getterMap.set(get, redGet);
1744
+ getterMap$1.set(get, redGet);
1738
1745
  reverseGetterMap.set(redGet, get);
1739
1746
  return get;
1740
1747
  }
@@ -1753,7 +1760,7 @@ class ReactiveProxyHandler extends BaseProxyHandler {
1753
1760
  redSet.call(handler.wrapValue(this), handler.wrapValue(v));
1754
1761
  };
1755
1762
 
1756
- setterMap.set(set, redSet);
1763
+ setterMap$1.set(set, redSet);
1757
1764
  reverseSetterMap.set(redSet, set);
1758
1765
  return set;
1759
1766
  }
@@ -1794,6 +1801,7 @@ class ReactiveProxyHandler extends BaseProxyHandler {
1794
1801
  }
1795
1802
 
1796
1803
  setPrototypeOf(shadowTarget, prototype) {
1804
+ /* istanbul ignore else */
1797
1805
  if (process.env.NODE_ENV !== 'production') {
1798
1806
  throw new Error(`Invalid setPrototypeOf invocation for reactive proxy ${toString(this.originalTarget)}. Prototype of reactive objects cannot be changed.`);
1799
1807
  }
@@ -1807,6 +1815,11 @@ class ReactiveProxyHandler extends BaseProxyHandler {
1807
1815
  preventExtensions(originalTarget); // if the originalTarget is a proxy itself, it might reject
1808
1816
  // the preventExtension call, in which case we should not attempt to lock down
1809
1817
  // the shadow target.
1818
+ // TODO: It should not actually be possible to reach this `if` statement.
1819
+ // If a proxy rejects extensions, then calling preventExtensions will throw an error:
1820
+ // https://codepen.io/nolanlawson-the-selector/pen/QWMOjbY
1821
+
1822
+ /* istanbul ignore if */
1810
1823
 
1811
1824
  if (isExtensible(originalTarget)) {
1812
1825
  return false;
@@ -1848,8 +1861,8 @@ class ReactiveProxyHandler extends BaseProxyHandler {
1848
1861
 
1849
1862
  }
1850
1863
 
1851
- const getterMap$1 = new WeakMap();
1852
- const setterMap$1 = new WeakMap();
1864
+ const getterMap = new WeakMap();
1865
+ const setterMap = new WeakMap();
1853
1866
 
1854
1867
  class ReadOnlyHandler extends BaseProxyHandler {
1855
1868
  wrapValue(value) {
@@ -1857,7 +1870,7 @@ class ReadOnlyHandler extends BaseProxyHandler {
1857
1870
  }
1858
1871
 
1859
1872
  wrapGetter(originalGet) {
1860
- const wrappedGetter = getterMap$1.get(originalGet);
1873
+ const wrappedGetter = getterMap.get(originalGet);
1861
1874
 
1862
1875
  if (!isUndefined(wrappedGetter)) {
1863
1876
  return wrappedGetter;
@@ -1870,12 +1883,12 @@ class ReadOnlyHandler extends BaseProxyHandler {
1870
1883
  return handler.wrapValue(originalGet.call(unwrap$1(this)));
1871
1884
  };
1872
1885
 
1873
- getterMap$1.set(originalGet, get);
1886
+ getterMap.set(originalGet, get);
1874
1887
  return get;
1875
1888
  }
1876
1889
 
1877
1890
  wrapSetter(originalSet) {
1878
- const wrappedSetter = setterMap$1.get(originalSet);
1891
+ const wrappedSetter = setterMap.get(originalSet);
1879
1892
 
1880
1893
  if (!isUndefined(wrappedSetter)) {
1881
1894
  return wrappedSetter;
@@ -1884,6 +1897,7 @@ class ReadOnlyHandler extends BaseProxyHandler {
1884
1897
  const handler = this;
1885
1898
 
1886
1899
  const set = function (v) {
1900
+ /* istanbul ignore else */
1887
1901
  if (process.env.NODE_ENV !== 'production') {
1888
1902
  const {
1889
1903
  originalTarget
@@ -1892,33 +1906,41 @@ class ReadOnlyHandler extends BaseProxyHandler {
1892
1906
  }
1893
1907
  };
1894
1908
 
1895
- setterMap$1.set(originalSet, set);
1909
+ setterMap.set(originalSet, set);
1896
1910
  return set;
1897
1911
  }
1898
1912
 
1899
1913
  set(shadowTarget, key, value) {
1914
+ /* istanbul ignore else */
1900
1915
  if (process.env.NODE_ENV !== 'production') {
1901
1916
  const {
1902
1917
  originalTarget
1903
1918
  } = this;
1904
- throw new Error(`Invalid mutation: Cannot set "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
1919
+ const msg = isArray(originalTarget) ? `Invalid mutation: Cannot mutate array at index ${key.toString()}. Array is read-only.` : `Invalid mutation: Cannot set "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`;
1920
+ throw new Error(msg);
1905
1921
  }
1922
+ /* istanbul ignore next */
1923
+
1906
1924
 
1907
1925
  return false;
1908
1926
  }
1909
1927
 
1910
1928
  deleteProperty(shadowTarget, key) {
1929
+ /* istanbul ignore else */
1911
1930
  if (process.env.NODE_ENV !== 'production') {
1912
1931
  const {
1913
1932
  originalTarget
1914
1933
  } = this;
1915
1934
  throw new Error(`Invalid mutation: Cannot delete "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
1916
1935
  }
1936
+ /* istanbul ignore next */
1937
+
1917
1938
 
1918
1939
  return false;
1919
1940
  }
1920
1941
 
1921
1942
  setPrototypeOf(shadowTarget, prototype) {
1943
+ /* istanbul ignore else */
1922
1944
  if (process.env.NODE_ENV !== 'production') {
1923
1945
  const {
1924
1946
  originalTarget
@@ -1928,23 +1950,29 @@ class ReadOnlyHandler extends BaseProxyHandler {
1928
1950
  }
1929
1951
 
1930
1952
  preventExtensions(shadowTarget) {
1953
+ /* istanbul ignore else */
1931
1954
  if (process.env.NODE_ENV !== 'production') {
1932
1955
  const {
1933
1956
  originalTarget
1934
1957
  } = this;
1935
1958
  throw new Error(`Invalid mutation: Cannot preventExtensions on ${originalTarget}". "${originalTarget} is read-only.`);
1936
1959
  }
1960
+ /* istanbul ignore next */
1961
+
1937
1962
 
1938
1963
  return false;
1939
1964
  }
1940
1965
 
1941
1966
  defineProperty(shadowTarget, key, descriptor) {
1967
+ /* istanbul ignore else */
1942
1968
  if (process.env.NODE_ENV !== 'production') {
1943
1969
  const {
1944
1970
  originalTarget
1945
1971
  } = this;
1946
1972
  throw new Error(`Invalid mutation: Cannot defineProperty "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
1947
1973
  }
1974
+ /* istanbul ignore next */
1975
+
1948
1976
 
1949
1977
  return false;
1950
1978
  }
@@ -2002,6 +2030,8 @@ const formatter = {
2002
2030
  }; // Inspired from paulmillr/es6-shim
2003
2031
  // https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L176-L185
2004
2032
 
2033
+ /* istanbul ignore next */
2034
+
2005
2035
  function getGlobal() {
2006
2036
  // the only reliable means to get the global object is `Function('return this')()`
2007
2037
  // However, this causes CSP violations in Chrome apps.
@@ -2026,6 +2056,7 @@ function getGlobal() {
2026
2056
  }
2027
2057
 
2028
2058
  function init() {
2059
+ /* istanbul ignore if */
2029
2060
  if (process.env.NODE_ENV === 'production') {
2030
2061
  // this method should never leak to prod
2031
2062
  throw new ReferenceError();
@@ -2040,13 +2071,13 @@ function init() {
2040
2071
  ArrayPush.call(devtoolsFormatters, formatter);
2041
2072
  global.devtoolsFormatters = devtoolsFormatters;
2042
2073
  }
2074
+ /* istanbul ignore else */
2075
+
2043
2076
 
2044
2077
  if (process.env.NODE_ENV !== 'production') {
2045
2078
  init();
2046
2079
  }
2047
2080
 
2048
- const ObjectDotPrototype = Object.prototype;
2049
-
2050
2081
  function defaultValueIsObservable(value) {
2051
2082
  // intentionally checking for null
2052
2083
  if (value === null) {
@@ -2074,106 +2105,85 @@ const defaultValueMutated = (obj, key) => {
2074
2105
  /* do nothing */
2075
2106
  };
2076
2107
 
2077
- const defaultValueDistortion = value => value;
2078
-
2079
2108
  function createShadowTarget(value) {
2080
2109
  return isArray(value) ? [] : {};
2081
2110
  }
2082
2111
 
2083
- class ReactiveMembrane {
2084
- constructor(options) {
2085
- this.valueDistortion = defaultValueDistortion;
2086
- this.valueMutated = defaultValueMutated;
2087
- this.valueObserved = defaultValueObserved;
2088
- this.valueIsObservable = defaultValueIsObservable;
2089
- this.objectGraph = new WeakMap();
2090
-
2091
- if (!isUndefined(options)) {
2092
- const {
2093
- valueDistortion,
2094
- valueMutated,
2095
- valueObserved,
2096
- valueIsObservable,
2097
- tagPropertyKey
2098
- } = options;
2099
- this.valueDistortion = isFunction(valueDistortion) ? valueDistortion : defaultValueDistortion;
2100
- this.valueMutated = isFunction(valueMutated) ? valueMutated : defaultValueMutated;
2101
- this.valueObserved = isFunction(valueObserved) ? valueObserved : defaultValueObserved;
2102
- this.valueIsObservable = isFunction(valueIsObservable) ? valueIsObservable : defaultValueIsObservable;
2103
- this.tagPropertyKey = tagPropertyKey;
2104
- }
2112
+ class ObservableMembrane {
2113
+ constructor(options = {}) {
2114
+ this.readOnlyObjectGraph = new WeakMap();
2115
+ this.reactiveObjectGraph = new WeakMap();
2116
+ const {
2117
+ valueMutated,
2118
+ valueObserved,
2119
+ valueIsObservable,
2120
+ tagPropertyKey
2121
+ } = options;
2122
+ this.valueMutated = isFunction(valueMutated) ? valueMutated : defaultValueMutated;
2123
+ this.valueObserved = isFunction(valueObserved) ? valueObserved : defaultValueObserved;
2124
+ this.valueIsObservable = isFunction(valueIsObservable) ? valueIsObservable : defaultValueIsObservable;
2125
+ this.tagPropertyKey = tagPropertyKey;
2105
2126
  }
2106
2127
 
2107
2128
  getProxy(value) {
2108
2129
  const unwrappedValue = unwrap$1(value);
2109
- const distorted = this.valueDistortion(unwrappedValue);
2110
2130
 
2111
- if (this.valueIsObservable(distorted)) {
2112
- const o = this.getReactiveState(unwrappedValue, distorted); // when trying to extract the writable version of a readonly
2113
- // we return the readonly.
2131
+ if (this.valueIsObservable(unwrappedValue)) {
2132
+ // When trying to extract the writable version of a readonly we return the readonly.
2133
+ if (this.readOnlyObjectGraph.get(unwrappedValue) === value) {
2134
+ return value;
2135
+ }
2114
2136
 
2115
- return o.readOnly === value ? value : o.reactive;
2137
+ return this.getReactiveHandler(unwrappedValue);
2116
2138
  }
2117
2139
 
2118
- return distorted;
2140
+ return unwrappedValue;
2119
2141
  }
2120
2142
 
2121
2143
  getReadOnlyProxy(value) {
2122
2144
  value = unwrap$1(value);
2123
- const distorted = this.valueDistortion(value);
2124
2145
 
2125
- if (this.valueIsObservable(distorted)) {
2126
- return this.getReactiveState(value, distorted).readOnly;
2146
+ if (this.valueIsObservable(value)) {
2147
+ return this.getReadOnlyHandler(value);
2127
2148
  }
2128
2149
 
2129
- return distorted;
2150
+ return value;
2130
2151
  }
2131
2152
 
2132
2153
  unwrapProxy(p) {
2133
2154
  return unwrap$1(p);
2134
2155
  }
2135
2156
 
2136
- getReactiveState(value, distortedValue) {
2137
- const {
2138
- objectGraph
2139
- } = this;
2140
- let reactiveState = objectGraph.get(distortedValue);
2157
+ getReactiveHandler(value) {
2158
+ let proxy = this.reactiveObjectGraph.get(value);
2141
2159
 
2142
- if (reactiveState) {
2143
- return reactiveState;
2160
+ if (isUndefined(proxy)) {
2161
+ // caching the proxy after the first time it is accessed
2162
+ const handler = new ReactiveProxyHandler(this, value);
2163
+ proxy = new Proxy(createShadowTarget(value), handler);
2164
+ registerProxy(proxy, value);
2165
+ this.reactiveObjectGraph.set(value, proxy);
2144
2166
  }
2145
2167
 
2146
- const membrane = this;
2147
- reactiveState = {
2148
- get reactive() {
2149
- const reactiveHandler = new ReactiveProxyHandler(membrane, distortedValue); // caching the reactive proxy after the first time it is accessed
2150
-
2151
- const proxy = new Proxy(createShadowTarget(distortedValue), reactiveHandler);
2152
- registerProxy(proxy, value);
2153
- ObjectDefineProperty(this, 'reactive', {
2154
- value: proxy
2155
- });
2156
- return proxy;
2157
- },
2168
+ return proxy;
2169
+ }
2158
2170
 
2159
- get readOnly() {
2160
- const readOnlyHandler = new ReadOnlyHandler(membrane, distortedValue); // caching the readOnly proxy after the first time it is accessed
2171
+ getReadOnlyHandler(value) {
2172
+ let proxy = this.readOnlyObjectGraph.get(value);
2161
2173
 
2162
- const proxy = new Proxy(createShadowTarget(distortedValue), readOnlyHandler);
2163
- registerProxy(proxy, value);
2164
- ObjectDefineProperty(this, 'readOnly', {
2165
- value: proxy
2166
- });
2167
- return proxy;
2168
- }
2174
+ if (isUndefined(proxy)) {
2175
+ // caching the proxy after the first time it is accessed
2176
+ const handler = new ReadOnlyHandler(this, value);
2177
+ proxy = new Proxy(createShadowTarget(value), handler);
2178
+ registerProxy(proxy, value);
2179
+ this.readOnlyObjectGraph.set(value, proxy);
2180
+ }
2169
2181
 
2170
- };
2171
- objectGraph.set(distortedValue, reactiveState);
2172
- return reactiveState;
2182
+ return proxy;
2173
2183
  }
2174
2184
 
2175
2185
  }
2176
- /** version: 1.0.0 */
2186
+ /** version: 2.0.0 */
2177
2187
 
2178
2188
  /*
2179
2189
  * Copyright (c) 2018, salesforce.com, inc.
@@ -2182,15 +2192,9 @@ class ReactiveMembrane {
2182
2192
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2183
2193
  */
2184
2194
  const lockerLivePropertyKey = Symbol.for('@@lockerLiveValue');
2185
-
2186
- function valueDistortion(value) {
2187
- return value;
2188
- }
2189
-
2190
- const reactiveMembrane = new ReactiveMembrane({
2195
+ const reactiveMembrane = new ObservableMembrane({
2191
2196
  valueObserved,
2192
2197
  valueMutated,
2193
- valueDistortion,
2194
2198
  tagPropertyKey: lockerLivePropertyKey
2195
2199
  });
2196
2200
  /**
@@ -2199,16 +2203,9 @@ const reactiveMembrane = new ReactiveMembrane({
2199
2203
  * change or being removed.
2200
2204
  */
2201
2205
 
2202
- const unwrap = function (value) {
2203
- const unwrapped = reactiveMembrane.unwrapProxy(value);
2204
-
2205
- if (unwrapped !== value) {
2206
- // if value is a proxy, unwrap to access original value and apply distortion
2207
- return valueDistortion(unwrapped);
2208
- }
2209
-
2210
- return value;
2211
- };
2206
+ function unwrap(value) {
2207
+ return reactiveMembrane.unwrapProxy(value);
2208
+ }
2212
2209
 
2213
2210
  /*
2214
2211
  * Copyright (c) 2018, salesforce.com, inc.
@@ -4283,7 +4280,7 @@ function vnodesAndElementHaveCompatibleAttrs(vnode, elm) {
4283
4280
  for (const [attrName, attrValue] of Object.entries(attrs)) {
4284
4281
  const elmAttrValue = renderer.getAttribute(elm, attrName);
4285
4282
 
4286
- if (attrValue !== elmAttrValue) {
4283
+ if (String(attrValue) !== elmAttrValue) {
4287
4284
  logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "${attrName}" has different values, expected "${attrValue}" but found "${elmAttrValue}"`, vnode.owner);
4288
4285
  nodesAreCompatible = false;
4289
4286
  }
@@ -4305,7 +4302,7 @@ function vnodesAndElementHaveCompatibleClass(vnode, elm) {
4305
4302
  let nodesAreCompatible = true;
4306
4303
  let vnodeClassName;
4307
4304
 
4308
- if (!shared.isUndefined(className) && className !== elm.className) {
4305
+ if (!shared.isUndefined(className) && String(className) !== elm.className) {
4309
4306
  // className is used when class is bound to an expr.
4310
4307
  nodesAreCompatible = false;
4311
4308
  vnodeClassName = className;
@@ -5100,7 +5097,7 @@ function co(text) {
5100
5097
 
5101
5098
 
5102
5099
  function d(value) {
5103
- return value == null ? '' : value;
5100
+ return value == null ? '' : String(value);
5104
5101
  } // [b]ind function
5105
5102
 
5106
5103
 
@@ -5391,6 +5388,7 @@ function updateStylesheetToken(vm, template) {
5391
5388
 
5392
5389
  function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
5393
5390
  const content = [];
5391
+ let root;
5394
5392
 
5395
5393
  for (let i = 0; i < stylesheets.length; i++) {
5396
5394
  let stylesheet = stylesheets[i];
@@ -5403,23 +5401,46 @@ function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
5403
5401
  // the component instance might be attempting to use an old version of
5404
5402
  // the stylesheet, while internally, we have a replacement for it.
5405
5403
  stylesheet = getStyleOrSwappedStyle(stylesheet);
5406
- } // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
5407
- // native shadow DOM. Synthetic shadow DOM never uses `:host`.
5404
+ }
5405
+
5406
+ const isScopedCss = stylesheet[shared.KEY__SCOPED_CSS]; // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
5408
5407
 
5408
+ const scopeToken = isScopedCss || vm.shadowMode === 1
5409
+ /* Synthetic */
5410
+ && vm.renderMode === 1
5411
+ /* Shadow */
5412
+ ? stylesheetToken : undefined; // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
5413
+ // native shadow DOM. Synthetic shadow DOM never uses `:host`.
5409
5414
 
5410
- const isScopedCss = stylesheet[shared.KEY__SCOPED_CSS];
5411
5415
  const useActualHostSelector = vm.renderMode === 0
5412
5416
  /* Light */
5413
5417
  ? !isScopedCss : vm.shadowMode === 0
5414
5418
  /* Native */
5415
- ; // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
5419
+ ; // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
5420
+ // we use an attribute selector on the host to simulate :dir().
5416
5421
 
5417
- const scopeToken = isScopedCss || vm.shadowMode === 1
5418
- /* Synthetic */
5419
- && vm.renderMode === 1
5422
+ let useNativeDirPseudoclass;
5423
+
5424
+ if (vm.renderMode === 1
5420
5425
  /* Shadow */
5421
- ? stylesheetToken : undefined;
5422
- shared.ArrayPush.call(content, stylesheet(useActualHostSelector, scopeToken));
5426
+ ) {
5427
+ useNativeDirPseudoclass = vm.shadowMode === 0
5428
+ /* Native */
5429
+ ;
5430
+ } else {
5431
+ // Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
5432
+ // At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
5433
+ if (shared.isUndefined(root)) {
5434
+ // Only calculate the root once as necessary
5435
+ root = getNearestShadowComponent(vm);
5436
+ }
5437
+
5438
+ useNativeDirPseudoclass = shared.isNull(root) || root.shadowMode === 0
5439
+ /* Native */
5440
+ ;
5441
+ }
5442
+
5443
+ shared.ArrayPush.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
5423
5444
  }
5424
5445
  }
5425
5446
 
@@ -5442,14 +5463,12 @@ function getStylesheetsContent(vm, template) {
5442
5463
  // perf testing has not shown it to be a huge improvement yet:
5443
5464
  // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
5444
5465
 
5445
- function getNearestNativeShadowComponent(vm) {
5466
+ function getNearestShadowComponent(vm) {
5446
5467
  let owner = vm;
5447
5468
 
5448
5469
  while (!shared.isNull(owner)) {
5449
5470
  if (owner.renderMode === 1
5450
5471
  /* Shadow */
5451
- && owner.shadowMode === 0
5452
- /* Native */
5453
5472
  ) {
5454
5473
  return owner;
5455
5474
  }
@@ -5460,6 +5479,20 @@ function getNearestNativeShadowComponent(vm) {
5460
5479
  return owner;
5461
5480
  }
5462
5481
 
5482
+ function getNearestNativeShadowComponent(vm) {
5483
+ const owner = getNearestShadowComponent(vm);
5484
+
5485
+ if (!shared.isNull(owner) && owner.shadowMode === 1
5486
+ /* Synthetic */
5487
+ ) {
5488
+ // Synthetic-within-native is impossible. So if the nearest shadow component is
5489
+ // synthetic, we know we won't find a native component if we go any further.
5490
+ return null;
5491
+ }
5492
+
5493
+ return owner;
5494
+ }
5495
+
5463
5496
  function createStylesheet(vm, stylesheets) {
5464
5497
  const {
5465
5498
  renderer,
@@ -5475,7 +5508,7 @@ function createStylesheet(vm, stylesheets) {
5475
5508
  for (let i = 0; i < stylesheets.length; i++) {
5476
5509
  renderer.insertGlobalStylesheet(stylesheets[i]);
5477
5510
  }
5478
- } else if (renderer.ssr || renderer.isHydrating) {
5511
+ } else if (renderer.ssr || renderer.isHydrating()) {
5479
5512
  // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
5480
5513
  // This works in the client, because the stylesheets are created, and cached in the VM
5481
5514
  // the first time the VM renders.
@@ -7185,4 +7218,4 @@ exports.swapTemplate = swapTemplate;
7185
7218
  exports.track = track;
7186
7219
  exports.unwrap = unwrap;
7187
7220
  exports.wire = wire;
7188
- /* version: 2.5.8 */
7221
+ /* version: 2.6.1 */
@@ -1425,10 +1425,10 @@ const {
1425
1425
  isArray
1426
1426
  } = Array;
1427
1427
  const {
1428
+ prototype: ObjectDotPrototype,
1428
1429
  getPrototypeOf,
1429
1430
  create: ObjectCreate,
1430
1431
  defineProperty: ObjectDefineProperty,
1431
- defineProperties: ObjectDefineProperties,
1432
1432
  isExtensible,
1433
1433
  getOwnPropertyDescriptor,
1434
1434
  getOwnPropertyNames,
@@ -1438,8 +1438,7 @@ const {
1438
1438
  } = Object;
1439
1439
  const {
1440
1440
  push: ArrayPush,
1441
- concat: ArrayConcat,
1442
- map: ArrayMap
1441
+ concat: ArrayConcat
1443
1442
  } = Array.prototype;
1444
1443
  const OtS = {}.toString;
1445
1444
 
@@ -1504,7 +1503,9 @@ class BaseProxyHandler {
1504
1503
  // but it will always be compatible with the previous descriptor
1505
1504
  // to preserve the object invariants, which makes these lines safe.
1506
1505
 
1507
- const originalDescriptor = getOwnPropertyDescriptor(originalTarget, key);
1506
+ const originalDescriptor = getOwnPropertyDescriptor(originalTarget, key); // TODO: it should be impossible for the originalDescriptor to ever be undefined, this `if` can be removed
1507
+
1508
+ /* istanbul ignore else */
1508
1509
 
1509
1510
  if (!isUndefined(originalDescriptor)) {
1510
1511
  const wrappedDesc = this.wrapDescriptor(originalDescriptor);
@@ -1532,11 +1533,17 @@ class BaseProxyHandler {
1532
1533
 
1533
1534
  preventExtensions(shadowTarget);
1534
1535
  } // Shared Traps
1536
+ // TODO: apply() is never called
1537
+
1538
+ /* istanbul ignore next */
1535
1539
 
1536
1540
 
1537
1541
  apply(shadowTarget, thisArg, argArray) {
1538
1542
  /* No op */
1539
- }
1543
+ } // TODO: construct() is never called
1544
+
1545
+ /* istanbul ignore next */
1546
+
1540
1547
 
1541
1548
  construct(shadowTarget, argArray, newTarget) {
1542
1549
  /* No op */
@@ -1649,8 +1656,8 @@ class BaseProxyHandler {
1649
1656
 
1650
1657
  }
1651
1658
 
1652
- const getterMap = new WeakMap();
1653
- const setterMap = new WeakMap();
1659
+ const getterMap$1 = new WeakMap();
1660
+ const setterMap$1 = new WeakMap();
1654
1661
  const reverseGetterMap = new WeakMap();
1655
1662
  const reverseSetterMap = new WeakMap();
1656
1663
 
@@ -1660,7 +1667,7 @@ class ReactiveProxyHandler extends BaseProxyHandler {
1660
1667
  }
1661
1668
 
1662
1669
  wrapGetter(originalGet) {
1663
- const wrappedGetter = getterMap.get(originalGet);
1670
+ const wrappedGetter = getterMap$1.get(originalGet);
1664
1671
 
1665
1672
  if (!isUndefined(wrappedGetter)) {
1666
1673
  return wrappedGetter;
@@ -1673,13 +1680,13 @@ class ReactiveProxyHandler extends BaseProxyHandler {
1673
1680
  return handler.wrapValue(originalGet.call(unwrap$1(this)));
1674
1681
  };
1675
1682
 
1676
- getterMap.set(originalGet, get);
1683
+ getterMap$1.set(originalGet, get);
1677
1684
  reverseGetterMap.set(get, originalGet);
1678
1685
  return get;
1679
1686
  }
1680
1687
 
1681
1688
  wrapSetter(originalSet) {
1682
- const wrappedSetter = setterMap.get(originalSet);
1689
+ const wrappedSetter = setterMap$1.get(originalSet);
1683
1690
 
1684
1691
  if (!isUndefined(wrappedSetter)) {
1685
1692
  return wrappedSetter;
@@ -1690,7 +1697,7 @@ class ReactiveProxyHandler extends BaseProxyHandler {
1690
1697
  originalSet.call(unwrap$1(this), unwrap$1(v));
1691
1698
  };
1692
1699
 
1693
- setterMap.set(originalSet, set);
1700
+ setterMap$1.set(originalSet, set);
1694
1701
  reverseSetterMap.set(set, originalSet);
1695
1702
  return set;
1696
1703
  }
@@ -1731,7 +1738,7 @@ class ReactiveProxyHandler extends BaseProxyHandler {
1731
1738
  return unwrap$1(redGet.call(handler.wrapValue(this)));
1732
1739
  };
1733
1740
 
1734
- getterMap.set(get, redGet);
1741
+ getterMap$1.set(get, redGet);
1735
1742
  reverseGetterMap.set(redGet, get);
1736
1743
  return get;
1737
1744
  }
@@ -1750,7 +1757,7 @@ class ReactiveProxyHandler extends BaseProxyHandler {
1750
1757
  redSet.call(handler.wrapValue(this), handler.wrapValue(v));
1751
1758
  };
1752
1759
 
1753
- setterMap.set(set, redSet);
1760
+ setterMap$1.set(set, redSet);
1754
1761
  reverseSetterMap.set(redSet, set);
1755
1762
  return set;
1756
1763
  }
@@ -1791,6 +1798,7 @@ class ReactiveProxyHandler extends BaseProxyHandler {
1791
1798
  }
1792
1799
 
1793
1800
  setPrototypeOf(shadowTarget, prototype) {
1801
+ /* istanbul ignore else */
1794
1802
  if (process.env.NODE_ENV !== 'production') {
1795
1803
  throw new Error(`Invalid setPrototypeOf invocation for reactive proxy ${toString(this.originalTarget)}. Prototype of reactive objects cannot be changed.`);
1796
1804
  }
@@ -1804,6 +1812,11 @@ class ReactiveProxyHandler extends BaseProxyHandler {
1804
1812
  preventExtensions(originalTarget); // if the originalTarget is a proxy itself, it might reject
1805
1813
  // the preventExtension call, in which case we should not attempt to lock down
1806
1814
  // the shadow target.
1815
+ // TODO: It should not actually be possible to reach this `if` statement.
1816
+ // If a proxy rejects extensions, then calling preventExtensions will throw an error:
1817
+ // https://codepen.io/nolanlawson-the-selector/pen/QWMOjbY
1818
+
1819
+ /* istanbul ignore if */
1807
1820
 
1808
1821
  if (isExtensible(originalTarget)) {
1809
1822
  return false;
@@ -1845,8 +1858,8 @@ class ReactiveProxyHandler extends BaseProxyHandler {
1845
1858
 
1846
1859
  }
1847
1860
 
1848
- const getterMap$1 = new WeakMap();
1849
- const setterMap$1 = new WeakMap();
1861
+ const getterMap = new WeakMap();
1862
+ const setterMap = new WeakMap();
1850
1863
 
1851
1864
  class ReadOnlyHandler extends BaseProxyHandler {
1852
1865
  wrapValue(value) {
@@ -1854,7 +1867,7 @@ class ReadOnlyHandler extends BaseProxyHandler {
1854
1867
  }
1855
1868
 
1856
1869
  wrapGetter(originalGet) {
1857
- const wrappedGetter = getterMap$1.get(originalGet);
1870
+ const wrappedGetter = getterMap.get(originalGet);
1858
1871
 
1859
1872
  if (!isUndefined(wrappedGetter)) {
1860
1873
  return wrappedGetter;
@@ -1867,12 +1880,12 @@ class ReadOnlyHandler extends BaseProxyHandler {
1867
1880
  return handler.wrapValue(originalGet.call(unwrap$1(this)));
1868
1881
  };
1869
1882
 
1870
- getterMap$1.set(originalGet, get);
1883
+ getterMap.set(originalGet, get);
1871
1884
  return get;
1872
1885
  }
1873
1886
 
1874
1887
  wrapSetter(originalSet) {
1875
- const wrappedSetter = setterMap$1.get(originalSet);
1888
+ const wrappedSetter = setterMap.get(originalSet);
1876
1889
 
1877
1890
  if (!isUndefined(wrappedSetter)) {
1878
1891
  return wrappedSetter;
@@ -1881,6 +1894,7 @@ class ReadOnlyHandler extends BaseProxyHandler {
1881
1894
  const handler = this;
1882
1895
 
1883
1896
  const set = function (v) {
1897
+ /* istanbul ignore else */
1884
1898
  if (process.env.NODE_ENV !== 'production') {
1885
1899
  const {
1886
1900
  originalTarget
@@ -1889,33 +1903,41 @@ class ReadOnlyHandler extends BaseProxyHandler {
1889
1903
  }
1890
1904
  };
1891
1905
 
1892
- setterMap$1.set(originalSet, set);
1906
+ setterMap.set(originalSet, set);
1893
1907
  return set;
1894
1908
  }
1895
1909
 
1896
1910
  set(shadowTarget, key, value) {
1911
+ /* istanbul ignore else */
1897
1912
  if (process.env.NODE_ENV !== 'production') {
1898
1913
  const {
1899
1914
  originalTarget
1900
1915
  } = this;
1901
- throw new Error(`Invalid mutation: Cannot set "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
1916
+ const msg = isArray(originalTarget) ? `Invalid mutation: Cannot mutate array at index ${key.toString()}. Array is read-only.` : `Invalid mutation: Cannot set "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`;
1917
+ throw new Error(msg);
1902
1918
  }
1919
+ /* istanbul ignore next */
1920
+
1903
1921
 
1904
1922
  return false;
1905
1923
  }
1906
1924
 
1907
1925
  deleteProperty(shadowTarget, key) {
1926
+ /* istanbul ignore else */
1908
1927
  if (process.env.NODE_ENV !== 'production') {
1909
1928
  const {
1910
1929
  originalTarget
1911
1930
  } = this;
1912
1931
  throw new Error(`Invalid mutation: Cannot delete "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
1913
1932
  }
1933
+ /* istanbul ignore next */
1934
+
1914
1935
 
1915
1936
  return false;
1916
1937
  }
1917
1938
 
1918
1939
  setPrototypeOf(shadowTarget, prototype) {
1940
+ /* istanbul ignore else */
1919
1941
  if (process.env.NODE_ENV !== 'production') {
1920
1942
  const {
1921
1943
  originalTarget
@@ -1925,23 +1947,29 @@ class ReadOnlyHandler extends BaseProxyHandler {
1925
1947
  }
1926
1948
 
1927
1949
  preventExtensions(shadowTarget) {
1950
+ /* istanbul ignore else */
1928
1951
  if (process.env.NODE_ENV !== 'production') {
1929
1952
  const {
1930
1953
  originalTarget
1931
1954
  } = this;
1932
1955
  throw new Error(`Invalid mutation: Cannot preventExtensions on ${originalTarget}". "${originalTarget} is read-only.`);
1933
1956
  }
1957
+ /* istanbul ignore next */
1958
+
1934
1959
 
1935
1960
  return false;
1936
1961
  }
1937
1962
 
1938
1963
  defineProperty(shadowTarget, key, descriptor) {
1964
+ /* istanbul ignore else */
1939
1965
  if (process.env.NODE_ENV !== 'production') {
1940
1966
  const {
1941
1967
  originalTarget
1942
1968
  } = this;
1943
1969
  throw new Error(`Invalid mutation: Cannot defineProperty "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
1944
1970
  }
1971
+ /* istanbul ignore next */
1972
+
1945
1973
 
1946
1974
  return false;
1947
1975
  }
@@ -1999,6 +2027,8 @@ const formatter = {
1999
2027
  }; // Inspired from paulmillr/es6-shim
2000
2028
  // https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L176-L185
2001
2029
 
2030
+ /* istanbul ignore next */
2031
+
2002
2032
  function getGlobal() {
2003
2033
  // the only reliable means to get the global object is `Function('return this')()`
2004
2034
  // However, this causes CSP violations in Chrome apps.
@@ -2023,6 +2053,7 @@ function getGlobal() {
2023
2053
  }
2024
2054
 
2025
2055
  function init() {
2056
+ /* istanbul ignore if */
2026
2057
  if (process.env.NODE_ENV === 'production') {
2027
2058
  // this method should never leak to prod
2028
2059
  throw new ReferenceError();
@@ -2037,13 +2068,13 @@ function init() {
2037
2068
  ArrayPush.call(devtoolsFormatters, formatter);
2038
2069
  global.devtoolsFormatters = devtoolsFormatters;
2039
2070
  }
2071
+ /* istanbul ignore else */
2072
+
2040
2073
 
2041
2074
  if (process.env.NODE_ENV !== 'production') {
2042
2075
  init();
2043
2076
  }
2044
2077
 
2045
- const ObjectDotPrototype = Object.prototype;
2046
-
2047
2078
  function defaultValueIsObservable(value) {
2048
2079
  // intentionally checking for null
2049
2080
  if (value === null) {
@@ -2071,106 +2102,85 @@ const defaultValueMutated = (obj, key) => {
2071
2102
  /* do nothing */
2072
2103
  };
2073
2104
 
2074
- const defaultValueDistortion = value => value;
2075
-
2076
2105
  function createShadowTarget(value) {
2077
2106
  return isArray(value) ? [] : {};
2078
2107
  }
2079
2108
 
2080
- class ReactiveMembrane {
2081
- constructor(options) {
2082
- this.valueDistortion = defaultValueDistortion;
2083
- this.valueMutated = defaultValueMutated;
2084
- this.valueObserved = defaultValueObserved;
2085
- this.valueIsObservable = defaultValueIsObservable;
2086
- this.objectGraph = new WeakMap();
2087
-
2088
- if (!isUndefined(options)) {
2089
- const {
2090
- valueDistortion,
2091
- valueMutated,
2092
- valueObserved,
2093
- valueIsObservable,
2094
- tagPropertyKey
2095
- } = options;
2096
- this.valueDistortion = isFunction(valueDistortion) ? valueDistortion : defaultValueDistortion;
2097
- this.valueMutated = isFunction(valueMutated) ? valueMutated : defaultValueMutated;
2098
- this.valueObserved = isFunction(valueObserved) ? valueObserved : defaultValueObserved;
2099
- this.valueIsObservable = isFunction(valueIsObservable) ? valueIsObservable : defaultValueIsObservable;
2100
- this.tagPropertyKey = tagPropertyKey;
2101
- }
2109
+ class ObservableMembrane {
2110
+ constructor(options = {}) {
2111
+ this.readOnlyObjectGraph = new WeakMap();
2112
+ this.reactiveObjectGraph = new WeakMap();
2113
+ const {
2114
+ valueMutated,
2115
+ valueObserved,
2116
+ valueIsObservable,
2117
+ tagPropertyKey
2118
+ } = options;
2119
+ this.valueMutated = isFunction(valueMutated) ? valueMutated : defaultValueMutated;
2120
+ this.valueObserved = isFunction(valueObserved) ? valueObserved : defaultValueObserved;
2121
+ this.valueIsObservable = isFunction(valueIsObservable) ? valueIsObservable : defaultValueIsObservable;
2122
+ this.tagPropertyKey = tagPropertyKey;
2102
2123
  }
2103
2124
 
2104
2125
  getProxy(value) {
2105
2126
  const unwrappedValue = unwrap$1(value);
2106
- const distorted = this.valueDistortion(unwrappedValue);
2107
2127
 
2108
- if (this.valueIsObservable(distorted)) {
2109
- const o = this.getReactiveState(unwrappedValue, distorted); // when trying to extract the writable version of a readonly
2110
- // we return the readonly.
2128
+ if (this.valueIsObservable(unwrappedValue)) {
2129
+ // When trying to extract the writable version of a readonly we return the readonly.
2130
+ if (this.readOnlyObjectGraph.get(unwrappedValue) === value) {
2131
+ return value;
2132
+ }
2111
2133
 
2112
- return o.readOnly === value ? value : o.reactive;
2134
+ return this.getReactiveHandler(unwrappedValue);
2113
2135
  }
2114
2136
 
2115
- return distorted;
2137
+ return unwrappedValue;
2116
2138
  }
2117
2139
 
2118
2140
  getReadOnlyProxy(value) {
2119
2141
  value = unwrap$1(value);
2120
- const distorted = this.valueDistortion(value);
2121
2142
 
2122
- if (this.valueIsObservable(distorted)) {
2123
- return this.getReactiveState(value, distorted).readOnly;
2143
+ if (this.valueIsObservable(value)) {
2144
+ return this.getReadOnlyHandler(value);
2124
2145
  }
2125
2146
 
2126
- return distorted;
2147
+ return value;
2127
2148
  }
2128
2149
 
2129
2150
  unwrapProxy(p) {
2130
2151
  return unwrap$1(p);
2131
2152
  }
2132
2153
 
2133
- getReactiveState(value, distortedValue) {
2134
- const {
2135
- objectGraph
2136
- } = this;
2137
- let reactiveState = objectGraph.get(distortedValue);
2154
+ getReactiveHandler(value) {
2155
+ let proxy = this.reactiveObjectGraph.get(value);
2138
2156
 
2139
- if (reactiveState) {
2140
- return reactiveState;
2157
+ if (isUndefined(proxy)) {
2158
+ // caching the proxy after the first time it is accessed
2159
+ const handler = new ReactiveProxyHandler(this, value);
2160
+ proxy = new Proxy(createShadowTarget(value), handler);
2161
+ registerProxy(proxy, value);
2162
+ this.reactiveObjectGraph.set(value, proxy);
2141
2163
  }
2142
2164
 
2143
- const membrane = this;
2144
- reactiveState = {
2145
- get reactive() {
2146
- const reactiveHandler = new ReactiveProxyHandler(membrane, distortedValue); // caching the reactive proxy after the first time it is accessed
2147
-
2148
- const proxy = new Proxy(createShadowTarget(distortedValue), reactiveHandler);
2149
- registerProxy(proxy, value);
2150
- ObjectDefineProperty(this, 'reactive', {
2151
- value: proxy
2152
- });
2153
- return proxy;
2154
- },
2165
+ return proxy;
2166
+ }
2155
2167
 
2156
- get readOnly() {
2157
- const readOnlyHandler = new ReadOnlyHandler(membrane, distortedValue); // caching the readOnly proxy after the first time it is accessed
2168
+ getReadOnlyHandler(value) {
2169
+ let proxy = this.readOnlyObjectGraph.get(value);
2158
2170
 
2159
- const proxy = new Proxy(createShadowTarget(distortedValue), readOnlyHandler);
2160
- registerProxy(proxy, value);
2161
- ObjectDefineProperty(this, 'readOnly', {
2162
- value: proxy
2163
- });
2164
- return proxy;
2165
- }
2171
+ if (isUndefined(proxy)) {
2172
+ // caching the proxy after the first time it is accessed
2173
+ const handler = new ReadOnlyHandler(this, value);
2174
+ proxy = new Proxy(createShadowTarget(value), handler);
2175
+ registerProxy(proxy, value);
2176
+ this.readOnlyObjectGraph.set(value, proxy);
2177
+ }
2166
2178
 
2167
- };
2168
- objectGraph.set(distortedValue, reactiveState);
2169
- return reactiveState;
2179
+ return proxy;
2170
2180
  }
2171
2181
 
2172
2182
  }
2173
- /** version: 1.0.0 */
2183
+ /** version: 2.0.0 */
2174
2184
 
2175
2185
  /*
2176
2186
  * Copyright (c) 2018, salesforce.com, inc.
@@ -2179,15 +2189,9 @@ class ReactiveMembrane {
2179
2189
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2180
2190
  */
2181
2191
  const lockerLivePropertyKey = Symbol.for('@@lockerLiveValue');
2182
-
2183
- function valueDistortion(value) {
2184
- return value;
2185
- }
2186
-
2187
- const reactiveMembrane = new ReactiveMembrane({
2192
+ const reactiveMembrane = new ObservableMembrane({
2188
2193
  valueObserved,
2189
2194
  valueMutated,
2190
- valueDistortion,
2191
2195
  tagPropertyKey: lockerLivePropertyKey
2192
2196
  });
2193
2197
  /**
@@ -2196,16 +2200,9 @@ const reactiveMembrane = new ReactiveMembrane({
2196
2200
  * change or being removed.
2197
2201
  */
2198
2202
 
2199
- const unwrap = function (value) {
2200
- const unwrapped = reactiveMembrane.unwrapProxy(value);
2201
-
2202
- if (unwrapped !== value) {
2203
- // if value is a proxy, unwrap to access original value and apply distortion
2204
- return valueDistortion(unwrapped);
2205
- }
2206
-
2207
- return value;
2208
- };
2203
+ function unwrap(value) {
2204
+ return reactiveMembrane.unwrapProxy(value);
2205
+ }
2209
2206
 
2210
2207
  /*
2211
2208
  * Copyright (c) 2018, salesforce.com, inc.
@@ -4280,7 +4277,7 @@ function vnodesAndElementHaveCompatibleAttrs(vnode, elm) {
4280
4277
  for (const [attrName, attrValue] of Object.entries(attrs)) {
4281
4278
  const elmAttrValue = renderer.getAttribute(elm, attrName);
4282
4279
 
4283
- if (attrValue !== elmAttrValue) {
4280
+ if (String(attrValue) !== elmAttrValue) {
4284
4281
  logError(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: attribute "${attrName}" has different values, expected "${attrValue}" but found "${elmAttrValue}"`, vnode.owner);
4285
4282
  nodesAreCompatible = false;
4286
4283
  }
@@ -4302,7 +4299,7 @@ function vnodesAndElementHaveCompatibleClass(vnode, elm) {
4302
4299
  let nodesAreCompatible = true;
4303
4300
  let vnodeClassName;
4304
4301
 
4305
- if (!isUndefined$1(className) && className !== elm.className) {
4302
+ if (!isUndefined$1(className) && String(className) !== elm.className) {
4306
4303
  // className is used when class is bound to an expr.
4307
4304
  nodesAreCompatible = false;
4308
4305
  vnodeClassName = className;
@@ -5097,7 +5094,7 @@ function co(text) {
5097
5094
 
5098
5095
 
5099
5096
  function d(value) {
5100
- return value == null ? '' : value;
5097
+ return value == null ? '' : String(value);
5101
5098
  } // [b]ind function
5102
5099
 
5103
5100
 
@@ -5388,6 +5385,7 @@ function updateStylesheetToken(vm, template) {
5388
5385
 
5389
5386
  function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
5390
5387
  const content = [];
5388
+ let root;
5391
5389
 
5392
5390
  for (let i = 0; i < stylesheets.length; i++) {
5393
5391
  let stylesheet = stylesheets[i];
@@ -5400,23 +5398,46 @@ function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
5400
5398
  // the component instance might be attempting to use an old version of
5401
5399
  // the stylesheet, while internally, we have a replacement for it.
5402
5400
  stylesheet = getStyleOrSwappedStyle(stylesheet);
5403
- } // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
5404
- // native shadow DOM. Synthetic shadow DOM never uses `:host`.
5401
+ }
5402
+
5403
+ const isScopedCss = stylesheet[KEY__SCOPED_CSS]; // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
5405
5404
 
5405
+ const scopeToken = isScopedCss || vm.shadowMode === 1
5406
+ /* Synthetic */
5407
+ && vm.renderMode === 1
5408
+ /* Shadow */
5409
+ ? stylesheetToken : undefined; // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
5410
+ // native shadow DOM. Synthetic shadow DOM never uses `:host`.
5406
5411
 
5407
- const isScopedCss = stylesheet[KEY__SCOPED_CSS];
5408
5412
  const useActualHostSelector = vm.renderMode === 0
5409
5413
  /* Light */
5410
5414
  ? !isScopedCss : vm.shadowMode === 0
5411
5415
  /* Native */
5412
- ; // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
5416
+ ; // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
5417
+ // we use an attribute selector on the host to simulate :dir().
5413
5418
 
5414
- const scopeToken = isScopedCss || vm.shadowMode === 1
5415
- /* Synthetic */
5416
- && vm.renderMode === 1
5419
+ let useNativeDirPseudoclass;
5420
+
5421
+ if (vm.renderMode === 1
5417
5422
  /* Shadow */
5418
- ? stylesheetToken : undefined;
5419
- ArrayPush$1.call(content, stylesheet(useActualHostSelector, scopeToken));
5423
+ ) {
5424
+ useNativeDirPseudoclass = vm.shadowMode === 0
5425
+ /* Native */
5426
+ ;
5427
+ } else {
5428
+ // Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
5429
+ // At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
5430
+ if (isUndefined$1(root)) {
5431
+ // Only calculate the root once as necessary
5432
+ root = getNearestShadowComponent(vm);
5433
+ }
5434
+
5435
+ useNativeDirPseudoclass = isNull(root) || root.shadowMode === 0
5436
+ /* Native */
5437
+ ;
5438
+ }
5439
+
5440
+ ArrayPush$1.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
5420
5441
  }
5421
5442
  }
5422
5443
 
@@ -5439,14 +5460,12 @@ function getStylesheetsContent(vm, template) {
5439
5460
  // perf testing has not shown it to be a huge improvement yet:
5440
5461
  // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
5441
5462
 
5442
- function getNearestNativeShadowComponent(vm) {
5463
+ function getNearestShadowComponent(vm) {
5443
5464
  let owner = vm;
5444
5465
 
5445
5466
  while (!isNull(owner)) {
5446
5467
  if (owner.renderMode === 1
5447
5468
  /* Shadow */
5448
- && owner.shadowMode === 0
5449
- /* Native */
5450
5469
  ) {
5451
5470
  return owner;
5452
5471
  }
@@ -5457,6 +5476,20 @@ function getNearestNativeShadowComponent(vm) {
5457
5476
  return owner;
5458
5477
  }
5459
5478
 
5479
+ function getNearestNativeShadowComponent(vm) {
5480
+ const owner = getNearestShadowComponent(vm);
5481
+
5482
+ if (!isNull(owner) && owner.shadowMode === 1
5483
+ /* Synthetic */
5484
+ ) {
5485
+ // Synthetic-within-native is impossible. So if the nearest shadow component is
5486
+ // synthetic, we know we won't find a native component if we go any further.
5487
+ return null;
5488
+ }
5489
+
5490
+ return owner;
5491
+ }
5492
+
5460
5493
  function createStylesheet(vm, stylesheets) {
5461
5494
  const {
5462
5495
  renderer,
@@ -5472,7 +5505,7 @@ function createStylesheet(vm, stylesheets) {
5472
5505
  for (let i = 0; i < stylesheets.length; i++) {
5473
5506
  renderer.insertGlobalStylesheet(stylesheets[i]);
5474
5507
  }
5475
- } else if (renderer.ssr || renderer.isHydrating) {
5508
+ } else if (renderer.ssr || renderer.isHydrating()) {
5476
5509
  // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
5477
5510
  // This works in the client, because the stylesheets are created, and cached in the VM
5478
5511
  // the first time the VM renders.
@@ -7149,4 +7182,4 @@ function setHooks(hooks) {
7149
7182
  }
7150
7183
 
7151
7184
  export { LightningElement, profilerControl as __unstable__ProfilerControl, api$1 as api, connectRootElement, createContextProvider, createVM, disconnectRootElement, getAssociatedVMIfPresent, getComponentDef, getComponentInternalDef, getUpgradableConstructor, hydrateRootElement, isComponentConstructor, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, setHooks, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
7152
- /* version: 2.5.8 */
7185
+ /* version: 2.6.1 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lwc/engine-core",
3
- "version": "2.5.8",
3
+ "version": "2.6.1",
4
4
  "description": "Core LWC engine APIs.",
5
5
  "homepage": "https://lwc.dev/",
6
6
  "repository": {
@@ -24,14 +24,14 @@
24
24
  "types/"
25
25
  ],
26
26
  "dependencies": {
27
- "@lwc/features": "2.5.8",
28
- "@lwc/shared": "2.5.8"
27
+ "@lwc/features": "2.6.1",
28
+ "@lwc/shared": "2.6.1"
29
29
  },
30
30
  "devDependencies": {
31
- "observable-membrane": "1.0.1"
31
+ "observable-membrane": "2.0.0"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
35
35
  },
36
- "gitHead": "223513a6a4e070b3243db0a345024a184f82dc08"
36
+ "gitHead": "65ae5d96106495314904cade2522cceef2067229"
37
37
  }
@@ -12,7 +12,7 @@ declare function i(iterable: Iterable<any>, factory: (value: any, index: number,
12
12
  declare function f(items: any[]): any[];
13
13
  declare function t(text: string): VText;
14
14
  declare function co(text: string): VComment;
15
- declare function d(value: any): string | any;
15
+ declare function d(value: any): string;
16
16
  declare function b(fn: EventListener): EventListener;
17
17
  declare function k(compilerKey: number, obj: any): string | void;
18
18
  declare function gid(id: string | undefined | null): string | null | undefined;
@@ -1,4 +1,4 @@
1
- import ObservableMembrane from 'observable-membrane';
1
+ import { ObservableMembrane } from 'observable-membrane';
2
2
  export declare const lockerLivePropertyKey: unique symbol;
3
3
  export declare const reactiveMembrane: ObservableMembrane;
4
4
  /**
@@ -6,4 +6,4 @@ export declare const reactiveMembrane: ObservableMembrane;
6
6
  * works for observable membrane objects. This API is subject to
7
7
  * change or being removed.
8
8
  */
9
- export declare const unwrap: (value: any) => any;
9
+ export declare function unwrap(value: any): any;
@@ -2,7 +2,7 @@ export declare type HostNode = any;
2
2
  export declare type HostElement = any;
3
3
  export interface Renderer<N = HostNode, E = HostElement> {
4
4
  ssr: boolean;
5
- readonly isHydrating: boolean;
5
+ isHydrating(): boolean;
6
6
  isNativeShadowDefined: boolean;
7
7
  isSyntheticShadowDefined: boolean;
8
8
  insert(node: N, parent: E, anchor: N | null): void;
@@ -5,7 +5,7 @@ import { Template } from './template';
5
5
  * Function producing style based on a host and a shadow selector. This function is invoked by
6
6
  * the engine with different values depending on the mode that the component is running on.
7
7
  */
8
- export declare type StylesheetFactory = (useActualHostSelector: boolean, stylesheetToken: string | undefined) => string;
8
+ export declare type StylesheetFactory = (stylesheetToken: string | undefined, useActualHostSelector: boolean, useNativeDirPseudoclass: boolean) => string;
9
9
  /**
10
10
  * The list of stylesheets associated with a template. Each entry is either a StylesheetFactory or a
11
11
  * TemplateStylesheetFactory a given stylesheet depends on other external stylesheets (via the