-
Notifications
You must be signed in to change notification settings - Fork 491
Can't use ES5 with v1.0.0-rc.6 #737
Comments
You may have something not setup quite correctly - it's doing the correct es6 vs es5 loading for me across all browsers (Chrome, FF, Safari, Edge, IE11). How are you building / serving / testing? |
I've installed it via I tried manually building now and here are my observations:
|
When you say "serving from" ... how - using When you use When you build, by default you are choosing to either compile or not compile. So you are making a choice on whether you are going to ship an es6 version (leaving out IE11 / Edge) or an es5 version (imposing a slight perf penalty for Chrome etc...) But another option is to add two build configs, one doing the compile and one not and make the decision either on the client or on the server which built files to reference (i.e. doing what polyserv does but without it running). I'm just experimenting with this now but it seems to work great and gives the optimal results. example polymer.json to create the two builds:
|
Sorry I'm not using Polymer. I'm serving files using I've been using webcomponents.js 0.7.x, and document-register-element to use custom elements v1, and I was hoping to replace both with webcomponents.js v1. |
It works fine with a pure / direct webcomponent (i.e. no polymer) but the same compilation steps are needed. It sounds like you're compiling the webcomponents polyfills for some reason but not your component, that's not going to work. |
Yes I would have to serve ES6 for Chrome, and no polyfills, but then I'd lose uglify minification, and add complexity for building/serving. So I was hoping that webcomponents.js would do the necessary shimming for Chrome when serving ES5 classes. I only tried building the polyfills because the ES5 files use ES6 syntax (I mean the files in the repo itself). https://github.com/webcomponents/webcomponentsjs/blob/master/webcomponents-ce-es5.js#L4 I am transpiling my code to ES5, I'm not sure what you mean by "compiling [...] your component". |
I'd stick to using the built packages, there's really little reason to build your own unless you are working on them. You are looking at the sources, the pre-built es5 files are already in es5. You should setup a hosted example / repo somewhere that people can look at. |
Hi, First of all I would like to thank everyone involved in the latest polyfills, superb work! 😃 I really appreciate it (for what that's worth). I've experienced (what I assume) exactly the same issue with a simple vanilla Web Component. I think it might be a slight misunderstanding as to how the CE ES5 polyfill works. Basically I want to ship an ES5 version of my simple component called
In IE11 this works fine but in Chrome you get:
The reason I expected this to work is that the documentation here shows the same example except the main difference is that the Web Component is being loaded as a HTML Import, not via a script file which is more common with vanilla Web Components. Basically the trick here is that you need to load
Once you've done that everything works! I hope this stops anyone else being caught out like I was 👍 |
Ha, I think we posted the same core findings within minutes of each other, linking them up for reference: |
@RevillWeb since <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Rw Star Rating</title>
<script src="bower_components/webcomponentsjs/webcomponents-es5-loader.js"></script>
<!-- contains <script src="dist/rw-star-rating.js"></script> -->
<link rel="import" href="rw-star-rating.html">
</style>
</head>
<body>
<rw-star-rating></rw-star-rating>
</body>
</html> |
You can get errors doing that. If you're on a browser that already supports html-imports then the It's essential to wait for the WebComponentsReady event. |
I just wanted to share what I've learned while digging into this issues through serving bundled, ES5-compiled code in Chrome. This is a common combination and the issue is affecting a lot of people in the CLI: https://github.com/Polymer/polymer-cli/issues/605 It looks like the two loaders call Repro instructions:
This is most obvious in the bundled case because a large portion of the app is executed before the bundle. However this doesn't seem to affect most unbundled applications. My best guess is that other imports end up giving the appended loader enough time to load and execute. tl;dr: |
I suspect the reason unbundled apps may not see it quite as much is that unless they are using http/2, the chance of some affected code running before the polyfill is pushed back somewhat (because of the cumulative latency from the chain of html imports). But, and kind of related because it effectively speeds up the "get" of the imports, when a service-worker is involved this triggers the issue more frequently. |
I wish we could just do <script src="webcomponents-lite.js" defer></script>
<script src="app.js" defer></script> That way we don't need to wait for an event before downloading the |
You can load the webcomponents-loader async no problem, just as long as you don't have anything that depends on it directly in the page as an html import. The native support in Chrome (from webcomponents v0) means Chrome will download and execute it often before the polyfills have loaded. Right now you have to wait for the event as the trigger that the app code can be processed. |
Sure but I still need to rely on the |
|
Hmm, I'd really like to avoid using @notwaldorf WDYT about using |
yea, specifically document.write might not even solve this problem... see last note on page https://developer.mozilla.org/en-US/docs/Web/API/Document/write
Injecting and executing a script is exactly what we're trying to do. |
There are a few more clauses for when those restrictions apply, more details here: https://developers.google.com/web/updates/2016/08/removing-document-write |
The only difference between webcomponents-s5-loader and webcomponents-loader is that on chrome and STP the es5 loader will load the native shim. <script src="../custom-elements/src/native-shim.js"></script>
<script src="../webcomponentsjs/webcomponents-loader.js"></script> The gambit is: only the shim is needed synchronously, all the rest can be polyfilled async. |
@valdrinkoshi and I have been talking, and I think requiring users that compile their elements to use the native shim (with a better name), is the right approach. Basically, the decision of which By providing the |
We've provided the |
Uh oh!
There was an error while loading. Please reload this page.
Hello,
So I'm trying out v1.0.0-rc.6 with the intent of supporting IE11 and better, but I'm facing a few issues:
webcomponents-lite.js
does not support ES5 codewebcomponents-es5-loader.js
, but it ends up loadingwebcomponents-lite.js
anyway.webcomponents-ce-es5.js
out of curiosity, but its use of arrow functions is not ES5 friendly...Would it be possible to provide a version of
webcomponents-lite.js
with ES5 support?Thank you.
The text was updated successfully, but these errors were encountered: