Skip to content

Commit e534c3c

Browse files
committed
Fix template-finding issue with DisableUpgrade mixin.
The existing rules are that `prototype._template` is first priority and dom-module via `is` is second priority _for a given class_. A subclass has a new shot at overriding the previous template either by defining a new `prototype._template` or a new `is` resulting in a dom-module lookup. However, trivially subclassing a Polymer legacy element breaks these rules, since if there is no _own_ `prototype._template` on the current class, it will lookup a dom-module using `is` from up the entire prototype chain. This defeats the rule that a `prototype._template` on the superclass should have taken priority over its dom-module. This change ensures that we only lookup dom-module if the class has an _own_ is property.
1 parent f95fd32 commit e534c3c

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lib/legacy/class.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,10 @@ export const Class = function(info, mixin) {
534534
let klass = mixin ? mixin(LegacyElementMixin(HTMLElement)) :
535535
LegacyElementMixin(HTMLElement);
536536
klass = GenerateClassFromInfo(info, klass, info.behaviors);
537+
// decorate klass with registration info
538+
klass.is = klass.prototype.is = info.is;
537539
if (legacyOptimizations) {
538540
klass = DisableUpgradeMixin(klass);
539541
}
540-
// decorate klass with registration info
541-
klass.is = klass.prototype.is = info.is;
542542
return klass;
543543
};

lib/mixins/element-mixin.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,13 @@ export const ElementMixin = dedupingMixin(base => {
411411
/**
412412
* Returns the template that will be stamped into this element's shadow root.
413413
*
414-
* If a `static get is()` getter is defined, the default implementation
415-
* will return the first `<template>` in a `dom-module` whose `id`
416-
* matches this element's `is`.
414+
* If a `static get is()` getter is defined, the default implementation will
415+
* return the first `<template>` in a `dom-module` whose `id` matches this
416+
* element's `is` (note that a `_template` property on the class prototype
417+
* takes precedence over the `dom-module` template, to maintain legacy
418+
* element semantics; a subclass will subsequently fall back to its super
419+
* class template if neither a `prototype._template` or a `dom-module` for
420+
* the class's `is` was found).
417421
*
418422
* Users may override this getter to return an arbitrary template
419423
* (in which case the `is` getter is unnecessary). The template returned
@@ -466,7 +470,8 @@ export const ElementMixin = dedupingMixin(base => {
466470
this.prototype.hasOwnProperty(JSCompiler_renameProperty('_template', this.prototype)) ?
467471
this.prototype._template :
468472
// Look in dom-module associated with this element's is
469-
(getTemplateFromDomModule(/** @type {PolymerElementConstructor}*/ (this).is) ||
473+
((this.hasOwnProperty(JSCompiler_renameProperty('is', this)) &&
474+
(getTemplateFromDomModule(/** @type {PolymerElementConstructor}*/ (this).is))) ||
470475
// Next look for superclass template (call the super impl this
471476
// way so that `this` points to the superclass)
472477
Object.getPrototypeOf(/** @type {PolymerElementConstructor}*/ (this).prototype).constructor.template);

0 commit comments

Comments
 (0)