Conflict in IE11 if I include an Stencil library in other stencil application
Stencil version:
@stencil/[email protected]
I'm submitting a:
[ x ] bug report [ ] feature request [ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/
Current behavior: When you include a Stencil library to reuse it in another Stencil application there is some conflict between the two application in IE11 and some errors show up in the console

Expected behavior:
In the dist build we should avoid compiling everything and should only compile the reusable components instead of the all unnecessary part of the application
Steps to reproduce:
creat two empty stencil project serve one of them, create a reusable component in the other app and make a build in dist mode, include the script tag in the other application which is serving now, open it in IE 11 and you'll see that it doesn´t work
ex:

Related code:
// insert any relevant code here
Other information:
If I put the tag in the footer the components will be loaded but the application will break and the same error show up in the console
I guess we experience the same - error code looks familar. We are moving to stencil more and more and since two stencil components working on the same page the IE11 sometimes does not render our component, or behaves error prone.
I guess we experience the same - error code looks familar. We are moving to stencil more and more and since two stencil components working on the same page the IE11 sometimes does not render our component, or behaves error prone.
Facing exactly the same. Sometimes the header loads with the components and then the application fails to get loaded completely.
We've encountered this issue as well. Seems like some collisions when loading the polyfills more than once.
Can anyone check if this is gone with the release of 1.8.1?
@stanley85 Hi Stanley.
I can confirm that I reproduced this issue today working with a Stencil library using v1.8.1 and viewing the application in IE11. Our use case is slightly different -- We're loading 2 Stencil JS libraries in a single app. I would consider this a major use case of StencilJS.
When loading either of the libraries individually, each one works. They have different namespaces. When loading both in the index.html, we get an error, attached below. As @lotz said, I would guess that it must somehow be related to loading duplicate polyfills.
The really odd thing is that while I was debugging this, I could get it to work a very small % of the time. The only time it worked seemed to be due to having breakpoints, so that the execution of the second script was interrupted. That reinforced the polyfill guess in my mind.
One other piece of evidence is that by switching the order of the <script> tags in the <head>, I could alternate which one would load properly and which one would fail. That's the nail in the coffin for me.
Can the StencilJS team please get eyes on this? This is a dealbreaker for further adoption, which I truly want to push for.
error information:
Here's a quick img snapshot...

Here's the text in full.
Error: Module http://localhost:8080/web-component-pattern-lib/p-ib32ojsv.system.entry.js did not instantiate
{
[functions]: ,
__proto__: {
[functions]: ,
__proto__: { },
message: "",
name: "Error",
Symbol()_5.5zfwrjyi02z: undefined,
Symbol(INITIAL_VALUE)_7.5zfwrjyi02z: undefined,
Symbol(rxSubscriber)_6.5zfwrjyi02z: undefined
},
description: "Module http://localhost:8080/web-component-pattern-lib/p-ib32ojsv.system.entry.js did not instantiate",
message: "Module http://localhost:8080/web-component-pattern-lib/p-ib32ojsv.system.entry.js did not instantiate",
name: "Error",
stack: "Error: Module http://localhost:8080/web-component-pattern-lib/p-ib32ojsv.system.entry.js did not instantiate
at Anonymous function (http://localhost:8080/web-component-pattern-lib/web-component-pattern-lib.js:201:730)
at ZoneDelegate.prototype.invoke (http://localhost:4200/polyfills.js:17053:13)
at onInvoke (http://localhost:4200/vendor.js:54219:17)
at ZoneDelegate.prototype.invoke (http://localhost:4200/polyfills.js:17053:13)
at Zone.prototype.run (http://localhost:4200/polyfills.js:16813:17)
at Anonymous function (http://localhost:4200/polyfills.js:17552:17)
at ZoneDelegate.prototype.invokeTask (http://localhost:4200/polyfills.js:17085:13)
at onInvokeTask (http://localhost:4200/vendor.js:54210:17)
at ZoneDelegate.prototype.invokeTask (http://localhost:4200/polyfills.js:17085:13)
at Zone.prototype.runTask (http://localhost:4200/polyfills.js:16858:21)",
Symbol()_5.5zfwrjyi02z: undefined,
Symbol(INITIAL_VALUE)_7.5zfwrjyi02z: undefined,
Symbol(rxSubscriber)_6.5zfwrjyi02z: undefined
}
ERROR Error: Uncaught (in promise): TypeError: Unable to get property 'isProxied' of undefined or null reference
TypeError: Unable to get property 'isProxied' of undefined or null reference
at Anonymous function (http://localhost:8080/web-component-pattern-lib/p-02ffc5fc.system.js:1:15792)
at l (http://localhost:8080/web-component-pattern-lib/p-02ffc5fc.system.js:1:1719)
at Anonymous function (http://localhost:8080/web-component-pattern-lib/p-02ffc5fc.system.js:1:1007)
at s (http://localhost:8080/web-component-pattern-lib/p-02ffc5fc.system.js:1:546)
at ZoneDelegate.prototype.invoke (http://localhost:4200/polyfills.js:17053:13)
at onInvoke (http://localhost:4200/vendor.js:54219:17)
at ZoneDelegate.prototype.invoke (http://localhost:4200/polyfills.js:17053:13)
at Zone.prototype.run (http://localhost:4200/polyfills.js:16813:17)
at Anonymous function (http://localhost:4200/polyfills.js:17552:17)
at ZoneDelegate.prototype.invokeTask (http://localhost:4200/polyfills.js:17085:13)
"ERROR"
{
[functions]: ,
__proto__: { },
description: "Uncaught (in promise): TypeError: Unable to get property 'isProxied' of undefined or null reference
TypeError: Unable to get property 'isProxied' of undefined or null reference
at Anonymous function (http://localhost:8080/web-component-pattern-lib/p-02ffc5fc.system.js:1:15792)
at l (http://localhost:8080/web-component-pattern-lib/p-02ffc5fc.system.js:1:1719)
at Anonymous function (http://localhost:8080/web-component-pattern-lib/p-02ffc5fc.system.js:1:1007)
at s (http://localhost:8080/web-component-pattern-lib/p-02ffc5fc.system.js:1:546)
at ZoneDelegate.prototype.invoke (http://localhost:4200/polyfills.js:17053:13)
at onInvoke (http://localhost:4200/vendor.js:54219:17)
at ZoneDelegate.prototype.invoke (http://localhost:4200/polyfills.js:17053:13)
at Zone.prototype.run (http://localhost:4200/polyfills.js:16813:17)
at Anonymous function (http://localhost:4200/polyfills.js:17552:17)
at ZoneDelegate.prototype.invokeTask (http://localhost:4200/polyfills.js:17085:13)",
message: "Uncaught (in promise): TypeError: Unable to get property 'isProxied' of undefined or null reference
TypeError: Unable to get property 'isProxied' of undefined or null reference
at Anonymous function (http://localhost:8080/web-component-pattern-lib/p-02ffc5fc.system.js:1:15792)
at l (http://localhost:8080/web-component-pattern-lib/p-02ffc5fc.system.js:1:1719)
at Anonymous function (http://localhost:8080/web-component-pattern-lib/p-02ffc5fc.system.js:1:1007)
at s (http://localhost:8080/web-component-pattern-lib/p-02ffc5fc.system.js:1:546)
at ZoneDelegate.prototype.invoke (http://localhost:4200/polyfills.js:17053:13)
at onInvoke (http://localhost:4200/vendor.js:54219:17)
at ZoneDelegate.prototype.invoke (http://localhost:4200/polyfills.js:17053:13)
at Zone.prototype.run (http://localhost:4200/polyfills.js:16813:17)
at Anonymous function (http://localhost:4200/polyfills.js:17552:17)
at ZoneDelegate.prototype.invokeTask (http://localhost:4200/polyfills.js:17085:13)",
name: "Error",
promise: { },
rejection: { },
stack: "Error: Uncaught (in promise): TypeError: Unable to get property 'isProxied' of undefined or null reference
TypeError: Unable to get property 'isProxied' of undefined or null reference
at Anonymous function (http://localhost:8080/web-component-pattern-lib/p-02ffc5fc.system.js:1:15792)
at l (http://localhost:8080/web-component-pattern-lib/p-02ffc5fc.system.js:1:1719)
at Anonymous function (http://localhost:8080/web-component-pattern-lib/p-02ffc5fc.system.js:1:1007)
at s (http://localhost:8080/web-component-pattern-lib/p-02ffc5fc.system.js:1:546)
at ZoneDelegate.prototype.invoke (http://localhost:4200/polyfills.js:17053:13)
at onInvoke (http://localhost:4200/vendor.js:54219:17)
at ZoneDelegate.prototype.invoke (http://localhost:4200/polyfills.js:17053:13)
at Zone.prototype.run (http://localhost:4200/polyfills.js:16813:17)
at Anonymous function (http://localhost:4200/polyfills.js:17552:17)
at ZoneDelegate.prototype.invokeTask (http://localhost:4200/polyfills.js:17085:13)
at resolv",
Symbol()_5.5zfwrjyi02z: undefined,
Symbol(INITIAL_VALUE)_7.5zfwrjyi02z: undefined,
Symbol(rxSubscriber)_6.5zfwrjyi02z: undefined,
task: { },
zone: { }
}
how do you actually load the multiple libraries @smzelek ? I've been using this for our applications...
import { applyPolyfills, defineCustomElements as defineCustomElementsLib1 } from 'myComponents/dist/loader';
import { defineCustomElements as defineCustomElementsLib2 } from 'myOtherComponents/dist/loader';
applyPolyfills().then(() => {
defineCustomElementsLib1(window);
defineCustomElementsLib2(window);
});
I load the Stencil libraries at run-time using <script> tags in the <head> of the index.html. This is a must for our use case. I think you're using including at build time in that snippet you posted.
Build time is not an option for us.
Can anyone from Ionic confirm that this is supposed to be a supported use-case?
Just to clarify, the issue isn't just using a stencil library in another stencil library. The issue is including two stencil libraries on the same page, in IE11. I would think a standard use case would be to have more than one stencil library included on a page at a time, in IE11.
Right now, the SystemJS polyfill is applied unconditionally, so last script wins. After I patched the components to conditionally load the SystemJS polyfill, the described scenario worked like a charm.
@mexx Great news! Are you able to share a code example of your approach - I am not 100% sure what you describe looks like in practice?
I've patched the output file of the component, to check whether the SystemJS is already present in the window and applied the polyfill only when it's not.
It's not a general fix, it's just a proof for the cause.
Another solution would be to provide at least an option to not bundle the polyfills at all. The integration website would be responsible to provide the required polyfills, and could do it more effectively as it would load them only once instead of like now multiple times, once per included component library.
I've seen the request for this option already on other issues as well.
@mexx Thank you for your investigation and PR! RE:
Another solution would be to provide at least an option to not bundle the polyfills at all.
It somewhat seems to me that both should be done. An easy first step is that StencilJS should work out of the box with multiple library includes, no questions asked.
I agree that StencilJS can also allow an option at compiletime to tune for increased performance by moving the polyfill outside of the application. Or, this can be the default going forward.
But the first one is simpler and not a big ask in my mind.
Thanks for debugging and figuring out the issue everyone. Awesome fix by @mexx, we'll get that merged in.
Additionally, the www directory does have the polyfills option where you can manually disable it, but I don't think that's an option for dist. I'll double check that quick so we might be able to provide best of both worlds. Thanks everyone!
The feature to exclude polyfills from the dist build will be available in the next compiler. The check that there are not two SystemJS polyfills will be in both 1.8.x and the next compiler. Thanks
@adamdbradley I've tried the polyfills: false option, but with no luck, as win is used but not defined. It would be defined by the otherwise included css-shim code. There need to be some adjustment on this part.
Also note that the polyfills for ie11 don't do feature-detection up front. We have a similar problem, but here the polyfill of stencil tries create window.customElementRegistry, however this registry is already created by another polyfill and it throws a assignment to read-only properties is not allowed in strict mode error.
I was able to solve some of the problems for Edge, but for IE11 I was unable to patch this.
hi @adamdbradley,
sorry to dig out some closed bug tickets but I became aware of this ticket when searching if someone is facing stencil polyfill problems with IE11 and unfortunately @justusromijn exactly described my problem.
actually we are using two different component bundles (one part of the application is written in vue, another one is based on stencil) and both bundles ship custom elements polyfill which leads to exactly the mentioned error above in IE11
window.customElementRegistry, however this registry is already created by another polyfill and it throws a assignment to read-only properties is not allowed in strict mode error.
so sorry again for commenting closed tickets but is this s.th. you are aware of or even want to fix in future releases ? any suggestions how to proceed on my side ? e.g actually couldn't figure out to disable including custom elements polyfill during rollup bundling. open for any suggestions.
thanks and regards Simon