Skip to content

Commit fafb487

Browse files
author
Steve Orvell
authored
Merge pull request #181 from Polymer/native-property-limitation
Address native properties issue on older browsers
2 parents b4c5f51 + 91b4078 commit fafb487

File tree

5 files changed

+51
-48
lines changed

5 files changed

+51
-48
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,8 @@ Chrome, Safari, Opera, Firefox, Edge. In addition, Internet Explorer 11 is also
275275

276276
## Known Issues
277277

278+
* On very old versions of Safari (<=9) or Chrome (<=41), properties created for native
279+
platform properties like (`id` or `name`) may not have default values set in the element constructor.
280+
On these browsers native properties appear on instances and therefore their default value
281+
will overwrite any element default (e.g. if the element sets this.id = 'id' in the constructor,
282+
the 'id' will become '' since this is the native platform default).

package-lock.json

Lines changed: 27 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@
2323
"devDependencies": {
2424
"@types/chai": "^4.0.1",
2525
"@types/mocha": "^5.2.4",
26-
"@webcomponents/webcomponentsjs": "^2.1.0",
26+
"@webcomponents/webcomponentsjs": "^2.1.1",
2727
"chai": "^4.0.2",
2828
"mocha": "^5.0.5",
2929
"rollup": "^0.64.1",
3030
"rollup-plugin-filesize": "^4.0.1",
31-
"rollup-plugin-node-resolve": "^3.3.0",
31+
"rollup-plugin-node-resolve": "^3.4.0",
3232
"rollup-plugin-terser": "^1.0.1",
3333
"tslint": "^5.7.0",
3434
"typedoc": "^0.8.0",
35-
"typescript": "^3.0.1",
35+
"typescript": "^3.0.3",
3636
"uglify-es": "^3.3.9",
3737
"wct-browser-legacy": "^1.0.1",
3838
"web-component-tester": "^6.8.0"
3939
},
4040
"typings": "lit-element.d.ts",
4141
"dependencies": {
42-
"lit-html": "^0.11.0"
42+
"lit-html": "^0.11.2"
4343
},
4444
"publishConfig": {
4545
"access": "public"

src/lib/updating-element.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,12 @@ export abstract class UpdatingElement extends HTMLElement {
325325
* Fixes any properties set on the instance before upgrade time.
326326
* Otherwise these would shadow the accessor and break these properties.
327327
* The properties are stored in a Map which is played back after the constructor
328-
* runs.
328+
* runs. Note, on very old versions of Safari (<=9) or Chrome (<=41), properties
329+
* created for native platform properties like (`id` or `name`) may not have default
330+
* values set in the element constructor. On these browsers native properties
331+
* appear on instances and therefore their default value will overwrite any element
332+
* default (e.g. if the element sets this.id = 'id' in the constructor, the 'id'
333+
* will become '' since this is the native platform default).
329334
*/
330335
private _saveInstanceProperties() {
331336
for (const [p] of (this.constructor as typeof UpdatingElement)._classProperties) {

src/test/lit-element_test.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,8 @@ suite('LitElement', () => {
12001200
assert.equal(el.getAttribute('zot'), '3');
12011201
});
12021202

1203+
// Note, on older browsers (e.g. old Safari/Chrome), native properties
1204+
// cannot have default values. These will be overwritten by instance values.
12031205
test('can make properties for native accessors', async () => {
12041206
class E extends LitElement {
12051207

@@ -1212,19 +1214,11 @@ suite('LitElement', () => {
12121214
};
12131215
}
12141216

1215-
name: string;
1216-
foo: string;
1217+
name: string|undefined;
1218+
foo = '';
12171219

12181220
changedProperties: PropertyValues|undefined = undefined;
12191221

1220-
constructor() {
1221-
super();
1222-
this.id = 'id';
1223-
this.name = 'name';
1224-
this.title = 'title';
1225-
this.foo = 'foo';
1226-
}
1227-
12281222
update(changedProperties: PropertyValues) {
12291223
(this as any).zot = (this as any).foo + (this as any).bar;
12301224
super.update(changedProperties);
@@ -1240,12 +1234,11 @@ suite('LitElement', () => {
12401234
const el = new E() as any;
12411235
container.appendChild(el);
12421236
await el.updateComplete;
1243-
const testMap = new Map();
1244-
testMap.set('id', undefined);
1245-
testMap.set('name', undefined);
1246-
testMap.set('title', undefined);
1247-
testMap.set('foo', undefined);
1248-
assert.deepEqual(el.changedProperties, testMap);
1237+
el.foo = 'foo';
1238+
el.id = 'id';
1239+
el.name = 'name';
1240+
el.title = 'title';
1241+
await el.updateComplete;
12491242
assert.equal(el.shadowRoot!.textContent, 'id-name-title-foo');
12501243
assert.equal((window as any).id, el);
12511244
el.id = 'id2';

0 commit comments

Comments
 (0)