Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix Custom Element instance creation in IE11 #25245

Merged
merged 1 commit into from
Oct 24, 2019

Conversation

jridgewell
Copy link
Contributor

When we transpile super in Custom Element subclasses, we change it to superClass.call(this) (where superClass is HTMLElementPolyfill). That .call value is inherited from Function.prototype.

But, IE11's native HTMLElement hierarchy doesn't extend from Function! And because HTMLElementPolyfill extends from HTMLElement, it doesn't have a .call! So we need to manually install it.

When we transpile `super` in Custom Element subclasses, we change it to
`superClass.call(this)` (where `superClass` is `HTMLElementPolyfill`).
That `.call` value is inherited from `Function.prototype`.  But, IE11's
native HTMLElement hierarchy doesn't extend from Function!  And because
`HTMLElementPolyfill` extends from `HTMLElement`, it doesn't have a
`.call`! So we need to manually install it.
@jridgewell jridgewell merged commit a9f6179 into ampproject:master Oct 24, 2019
@jridgewell jridgewell deleted the ie11-custom-elements branch October 24, 2019 22:12
@rsimha
Copy link
Contributor

rsimha commented Oct 24, 2019

Is there an IE11 integration test for this? You'll need to call enableIe() to opt in.

describe
.configure()
.enableIe()
.retryOnSaucelabs()
.run('Rendering of one ad', () => {

zhouyx pushed a commit that referenced this pull request Oct 25, 2019
When we transpile `super` in Custom Element subclasses, we change it to
`superClass.call(this)` (where `superClass` is `HTMLElementPolyfill`).
That `.call` value is inherited from `Function.prototype`.  But, IE11's
native HTMLElement hierarchy doesn't extend from Function!  And because
`HTMLElementPolyfill` extends from `HTMLElement`, it doesn't have a
`.call`! So we need to manually install it.
micajuine-ho pushed a commit to micajuine-ho/amphtml that referenced this pull request Dec 27, 2019
When we transpile `super` in Custom Element subclasses, we change it to
`superClass.call(this)` (where `superClass` is `HTMLElementPolyfill`).
That `.call` value is inherited from `Function.prototype`.  But, IE11's
native HTMLElement hierarchy doesn't extend from Function!  And because
`HTMLElementPolyfill` extends from `HTMLElement`, it doesn't have a
`.call`! So we need to manually install it.
jridgewell added a commit to jridgewell/amphtml that referenced this pull request Apr 15, 2020
This is a continuation of ampproject#25245. All of our Custom Elements extend from a common `CustomAmpElement` class, which itself extends from `HTMLElementPolyfill`. In ampproject#27470, I removed the `constructor` from `CustomAmpElement` class. But, because it's a subclass and must have a `constructor` that calls `super()`, Closure replaced it with a `constructor() { superClass.apply(this, arguments); }` when transpiling.

But, due to the same faulty inheritance chain described in ampproject#25245, `HTMLElementPolyfill` doesn't inherit an `apply` method! So doing `superClass.apply()` throws an error. 😭

This PR installs all important Function methods onto our polyfill, to be resilient to any future changes in the instance creation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants