Skip to content

Commit 414fc55

Browse files
committed
fix(polyfill): ensure promise polyfill applied for ie11
Closes #1188
1 parent 14f5e29 commit 414fc55

3 files changed

Lines changed: 45 additions & 49 deletions

File tree

src/client/core-esm.ts

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -35,59 +35,55 @@ export function defineCustomElement(win: Window, cmpData: d.ComponentHostData |
3535
createComponentOnReadyPrototype(win, namespace, (win as any).HTMLElement.prototype);
3636
}
3737

38-
return new Promise(resolve => {
38+
return applyPolyfills(win).then(() => {
39+
40+
if (!pltMap[namespace]) {
41+
const Context: d.CoreContext = {};
42+
const resourcesUrl = opts.resourcesUrl || './';
43+
44+
appGlobal(namespace, Context, win, doc, resourcesUrl, hydratedCssClass);
45+
46+
// create a platform for this namespace
47+
pltMap[namespace] = createPlatformMain(
48+
namespace,
49+
Context,
50+
win,
51+
doc,
52+
resourcesUrl,
53+
hydratedCssClass,
54+
cmpDataArray
55+
);
56+
}
3957

40-
applyPolyfills(win, () => {
58+
// polyfills have been applied if need be
59+
(cmpData as d.ComponentHostData[]).forEach(c => {
60+
let HostElementConstructor: any;
4161

42-
if (!pltMap[namespace]) {
43-
const Context: d.CoreContext = {};
44-
const resourcesUrl = opts.resourcesUrl || './';
62+
if (isNative(win.customElements.define)) {
63+
// native custom elements supported
64+
const createHostConstructor = new Function('w', 'return class extends w.HTMLElement{}');
65+
HostElementConstructor = createHostConstructor(win);
4566

46-
appGlobal(namespace, Context, win, doc, resourcesUrl, hydratedCssClass);
67+
} else {
68+
// using polyfilled custom elements
69+
HostElementConstructor = function(self: any) {
70+
return (win as any).HTMLElement.call(this, self);
71+
};
4772

48-
// create a platform for this namespace
49-
pltMap[namespace] = createPlatformMain(
50-
namespace,
51-
Context,
52-
win,
53-
doc,
54-
resourcesUrl,
55-
hydratedCssClass,
56-
cmpDataArray
73+
HostElementConstructor.prototype = Object.create(
74+
(win as any).HTMLElement.prototype,
75+
{ constructor: { value: HostElementConstructor, configurable: true } }
5776
);
5877
}
5978

60-
// polyfills have been applied if need be
61-
(cmpData as d.ComponentHostData[]).forEach(c => {
62-
let HostElementConstructor: any;
63-
64-
if (isNative(win.customElements.define)) {
65-
// native custom elements supported
66-
const createHostConstructor = new Function('w', 'return class extends w.HTMLElement{}');
67-
HostElementConstructor = createHostConstructor(win);
68-
69-
} else {
70-
// using polyfilled custom elements
71-
HostElementConstructor = function(self: any) {
72-
return (win as any).HTMLElement.call(this, self);
73-
};
74-
75-
HostElementConstructor.prototype = Object.create(
76-
(win as any).HTMLElement.prototype,
77-
{ constructor: { value: HostElementConstructor, configurable: true } }
78-
);
79-
}
80-
81-
// convert the static constructor data to cmp metadata
82-
// define the component as a custom element
83-
pltMap[namespace].defineComponent(
84-
buildComponentLoader(c),
85-
HostElementConstructor
86-
);
87-
});
88-
89-
resolve();
79+
// convert the static constructor data to cmp metadata
80+
// define the component as a custom element
81+
pltMap[namespace].defineComponent(
82+
buildComponentLoader(c),
83+
HostElementConstructor
84+
);
9085
});
86+
9187
});
9288
}
9389

src/client/polyfills/index.js

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

test/karma/test-app/esm-webpack/karma.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ describe('esm-webpack', () => {
1212

1313
it('webpack', async () => {
1414
await testEsmImport(app);
15+
const hydratedElm = app.querySelector('esm-import.hydrated')
16+
expect(hydratedElm).not.toBe(null);
1517
});
1618

1719
});

0 commit comments

Comments
 (0)