Skip to content

Commit

Permalink
Fix template-finding issue with DisableUpgrade mixin.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kevinpschaaf committed Aug 22, 2019
1 parent f95fd32 commit e534c3c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/legacy/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,10 @@ export const Class = function(info, mixin) {
let klass = mixin ? mixin(LegacyElementMixin(HTMLElement)) :
LegacyElementMixin(HTMLElement);
klass = GenerateClassFromInfo(info, klass, info.behaviors);
// decorate klass with registration info
klass.is = klass.prototype.is = info.is;
if (legacyOptimizations) {
klass = DisableUpgradeMixin(klass);
}
// decorate klass with registration info
klass.is = klass.prototype.is = info.is;
return klass;
};
13 changes: 9 additions & 4 deletions lib/mixins/element-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,13 @@ export const ElementMixin = dedupingMixin(base => {
/**
* Returns the template that will be stamped into this element's shadow root.
*
* If a `static get is()` getter is defined, the default implementation
* will return the first `<template>` in a `dom-module` whose `id`
* matches this element's `is`.
* If a `static get is()` getter is defined, the default implementation will
* return the first `<template>` in a `dom-module` whose `id` matches this
* element's `is` (note that a `_template` property on the class prototype
* takes precedence over the `dom-module` template, to maintain legacy
* element semantics; a subclass will subsequently fall back to its super
* class template if neither a `prototype._template` or a `dom-module` for
* the class's `is` was found).
*
* Users may override this getter to return an arbitrary template
* (in which case the `is` getter is unnecessary). The template returned
Expand Down Expand Up @@ -466,7 +470,8 @@ export const ElementMixin = dedupingMixin(base => {
this.prototype.hasOwnProperty(JSCompiler_renameProperty('_template', this.prototype)) ?
this.prototype._template :
// Look in dom-module associated with this element's is
(getTemplateFromDomModule(/** @type {PolymerElementConstructor}*/ (this).is) ||
((this.hasOwnProperty(JSCompiler_renameProperty('is', this)) &&
(getTemplateFromDomModule(/** @type {PolymerElementConstructor}*/ (this).is))) ||
// Next look for superclass template (call the super impl this
// way so that `this` points to the superclass)
Object.getPrototypeOf(/** @type {PolymerElementConstructor}*/ (this).prototype).constructor.template);
Expand Down

0 comments on commit e534c3c

Please sign in to comment.