Skip to content

Commit 32eb059

Browse files
authored
fix(engine): reactive membrane tags and component instances tags (salesforce#1913)
1 parent d504d44 commit 32eb059

File tree

6 files changed

+31
-5
lines changed

6 files changed

+31
-5
lines changed

packages/@lwc/engine-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"devDependencies": {
2828
"@lwc/features": "1.7.11",
2929
"@lwc/shared": "1.7.11",
30-
"observable-membrane": "0.26.1"
30+
"observable-membrane": "1.0.1"
3131
},
3232
"publishConfig": {
3333
"access": "public"

packages/@lwc/engine-core/src/framework/base-lightning-element.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ import { Template, isUpdatingTemplate, getVMBeingRendered } from './template';
3838
import { logError } from '../shared/logger';
3939
import { getComponentTag } from '../shared/format';
4040
import { HTMLElementConstructor } from './base-bridge-element';
41+
import { lockerLivePropertyKey } from './membrane';
42+
import { EmptyObject } from './utils';
4143

4244
/**
4345
* This operation is called with a descriptor of an standard html property
@@ -212,6 +214,9 @@ function BaseLightningElementConstructor(this: LightningElement): LightningEleme
212214
vm.getHook = getHook;
213215
}
214216

217+
// Making the component instance a live value when using Locker to support expandos.
218+
defineProperty(component, lockerLivePropertyKey, EmptyObject);
219+
215220
// Linking elm, shadow root and component with the VM.
216221
associateVM(component, vm);
217222
associateVM(cmpRoot, vm);

packages/@lwc/engine-core/src/framework/membrane.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import ObservableMembrane from 'observable-membrane';
88
import { valueObserved, valueMutated } from './mutation-tracker';
99

10+
export const lockerLivePropertyKey = Symbol.for('@@lockerLiveValue');
11+
1012
function valueDistortion(value: any) {
1113
return value;
1214
}
@@ -15,6 +17,7 @@ export const reactiveMembrane = new ObservableMembrane({
1517
valueObserved,
1618
valueMutated,
1719
valueDistortion,
20+
tagPropertyKey: lockerLivePropertyKey,
1821
});
1922

2023
/**

packages/integration-karma/test/integrations/locker/index.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createElement } from 'lwc';
22

33
import LockerIntegration from 'x/lockerIntegration';
4+
import LockerLiveComponent from 'x/lockerLiveComponent';
45
import LockerHooks, { hooks } from 'x/lockerHooks';
56

67
it('should support Locker integration which uses a wrapped LightningElement base class', () => {
@@ -112,3 +113,11 @@ describe('Locker hooks', () => {
112113
});
113114
});
114115
});
116+
117+
describe('Locker live objects', () => {
118+
it('should report the component instance as live to support expandos', () => {
119+
const elm = createElement('x-live', { is: LockerLiveComponent });
120+
document.body.appendChild(elm);
121+
expect(elm.hasMarker()).toBe(true);
122+
});
123+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { LightningElement, api } from 'lwc';
2+
3+
const marker = Symbol.for('@@lockerLiveValue');
4+
5+
export default class Foo extends LightningElement {
6+
@api hasMarker() {
7+
return Object.hasOwnProperty.call(this, marker);
8+
}
9+
}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10462,10 +10462,10 @@ object.values@^1.1.0:
1046210462
function-bind "^1.1.1"
1046310463
has "^1.0.3"
1046410464

10465-
observable-membrane@0.26.1:
10466-
version "0.26.1"
10467-
resolved "http://npm.lwcjs.org/observable-membrane/-/observable-membrane-0.26.1/5619a7b2f4b0414d62b3e6cc2ea65734a08cce7a.tgz#5619a7b2f4b0414d62b3e6cc2ea65734a08cce7a"
10468-
integrity sha512-fBxLHtd0pUFI/rKh6Dfn9fxjEgY4NkRIqlPEKa9fR28rC9CQDfQ5P+t292CtAArtXOQ1mF8Nq9m1cF52IdN8DA==
10465+
observable-membrane@1.0.1:
10466+
version "1.0.1"
10467+
resolved "https://registry.yarnpkg.com/observable-membrane/-/observable-membrane-1.0.1.tgz#1041074136d5d62b0fc488880bed1c3680674ec5"
10468+
integrity sha512-AlPC0ZuEuBYt9LSbsBGOz0rpIjkdbIH5JQMLHZrmCRkUedfVoNSFQXLYso+hXxWrRqwEhxEkQuYNg6Pch3hmqQ==
1046910469

1047010470
octokit-pagination-methods@^1.1.0:
1047110471
version "1.1.0"

0 commit comments

Comments
 (0)