-
Notifications
You must be signed in to change notification settings - Fork 22
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
Make the polyfill work in IE & Edge #28
Conversation
I think this makes sense if you have immediate access to IE11. As for polyfills, IE supports |
I did also want to say this package should not include its own polyfills for Promise or Map to ensure compatibility with other tools that might be used. Instead please add notes inside the README that note what will be needed. For example, if I'm running an Angular application, I want the Promise used in this polyfill to be the same one loaded by Angular (or any other framework). I can still be convinced on the |
Oh, does it? I thought that it is a ES6 thing for some reason. That's the good news.
You mean to transpile the existing code? Well, we can do that but, AFAIK, all polyfills are written with ES5 to make manual tweaks (I did them in the code as well) and get the resulting code size smaller. I personally would prefer to follow this tradition. What do you think about it?
Sure, I completely agree here. Polyfills should not be dependencies, they are the support code that the end user adds if necessary.
BTW, I think I found a workaround to not use the polyfill at all. The idea is that if we have |
@calebdwilliams, are you aware how to work with the ShadyCSS? I'm kinda stuck with it. It has its own implementation for |
Really good thought on Not sure what you mean here:
|
@calebdwilliams, hmm, I'm about your mention of the Rollup. I might mistunderstood you; what did you mean regarding Rollup? |
So thinking about this a bit, I believe it would be better to keep the src file in ES6+ and Babel down to IE11 support (primarily to keep the code as maintainable as possible). My ideal setup would use Rollup and split out the source into src and maybe divide the code a bit. Then use Babel to output the file in the project’s root. I realize you have done a lot of work on this already, let’s pause though and consider what approach is s most sustainable long term. |
Well, I don't think that keeping the code in ES5 would be harder than work with it in ES6. I rewrote it, and I don't see much difference. The most visible changes are the following:
So, I don't see a lot of disadvantages while there is some advantages:
Plus, as I mentioned above, the polyfills are primarily written in ES5 to be consumed by old browsers directly. I believe we should follow this tradition. That are my ideas regarding this question. I do not totally disagree with ES6 solution, but while debugging the code in Edge and IE11, I found that it would be way easier to work with ES5 code than a transpiled ES6 (especially it is connected with |
Ok, from the #30 it looks like that we would need more files to properly support |
Hmm, I would say that I'm kinda stuck with the ShadyCSS. I'm not sure it can be properly integrated; all my attempts are like making the polyfill more complicated than it should be. I'm going to push all changes in the current state, then purge all ShadyCSS-related things and then make PR available. For IE it will work only for the document but not for polyfilled custom elements. Tests will be passed only in Firefox, Chrome, and Safari (or we can disable Custom Element tests for IE & Edge). So there will be a history of ShadyCSS attempts, and if someone can make it work, it would be great. |
By the way, I'm not sure we should try to integrate it since ShadyCSS has its own implementation already. Support of adopted style sheets in shadow roots is tightly coupled with supporting web components, and polyfilling web components is definitely out of scope for this project. |
* Split code to separate files * Add Rollup build with detection injection * Attempt to work together with ShadyCSS
Codecov Report
@@ Coverage Diff @@
## master #28 +/- ##
==========================================
+ Coverage 95.42% 95.59% +0.17%
==========================================
Files 1 7 +6
Lines 153 159 +6
==========================================
+ Hits 146 152 +6
Misses 7 7
Continue to review full report at Codecov.
|
Hmm, the version of Firefox and Chrome in travis is rather old (56 when the current is 68), it might be a reason why tests fail. I have all of them passing on my local Firefox 68. |
Sorry I've been out of the pocket over the weekend, it was a holiday here in the US yesterday, but I'm back online. Can you get some info about why the tests are failing? I'll see if I can't figure out how to upgrade Firefox in Travis (or if that's even possible). |
@calebdwilliams, probably, it does not support Web Components. AFAIK, Firefox supports them starting from the version 63 (October of 2018) while Travis suggests version 56. I really don't understand why it does provide such old browsers. My project runs on the Chrome 76, and my .travis.yml file does not have much difference from yours. The only big difference I can see is that your project runs on https://travis-ci.com (the new one) and my - on the https://travis-ci.org (the old one). But I don't see any particular reason to load such different versions. However, let's try setting Firefox from |
By the way, what do you think about my suggestion of not supporting ShadyCSS at all since it has its own support? We would be able to support only the |
Let's put ShadyCSS support on the back burner for now. That might be something to revisit in the future, but that is tangential to the primary goal of this PR. As for Firefox, please feel free to update the Travis config. I saw both versions listed on the Travis documentation, so it could have been a mis-type somewhere. EditFWIW, let's remove any attempt to get ShadyCSS working (maybe create a new branch to retain what you currently have so we can revisit later). Before this update is ready, I'd like these commits to be squashed, too. |
I already purged all attempts to get ShadyCSS working.
Maybe, it would be better to squash the whole PR? You can do it via the Github interface: |
Ok, looks like it works :) Tests are passed |
Oh wait, one more thing to remove |
Ok, this PR is ready, let's squash it and merge 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't had time to give this a thorough look through just yet, but I do have a couple initial questions/feedback.
I was also thinking |
Unfortunately, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really minor comments. Also add the instanceof
language to README so the limitation in IE11 is documented. Once those last few things are ready I'll squash and merge.
test/_index.html
Outdated
@@ -5,6 +5,6 @@ | |||
<body> | |||
<h1>Hello world</h1> | |||
</body> | |||
<script src="../adoptedStyleSheets.js"></script> | |||
<script type="module" src="../src/index.js"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to load from dist or set up a script to run this from localhost otherwise this doesn't work from file://
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, I forgot about this part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, it's still [type=module]
which won't load from file://
test/index.html
Outdated
@@ -3,12 +3,12 @@ | |||
<head> | |||
<title>Constructed style sheets test</title> | |||
<meta charset="UTF-8"> | |||
<script src="../adoptedStyleSheets.js"></script> | |||
<script src="../src/index.js" type="module"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to load from dist or set up a script to run this from localhost otherwise this doesn't work from file://
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
test/_index.html
Outdated
@@ -5,6 +5,6 @@ | |||
<body> | |||
<h1>Hello world</h1> | |||
</body> | |||
<script src="../adoptedStyleSheets.js"></script> | |||
<script type="module" src="../src/index.js"></script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, it's still [type=module]
which won't load from file://
README.md
Outdated
required. | ||
|
||
For browsers that do not support the web components specification (currently | ||
IE 11 and Edge) only the document-level style sheets adoption works. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And checking instanceof
will not work in IE11 due to Symbol
not being natively supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I am sure that I fixed it and the previous one. It looks the following now:
<script src="../dist/adoptedStyleSheets.js"></script>
and
## Support
This polyfill supports all modern browsers and IE 11.
For browsers that do not support the web components specification (currently
IE 11 and Edge) only the document-level style sheets adoption works.
### IE 11
To make this polyfill work with IE 11 you need the following tools:
- `Symbol` polyfill (with support for `Symbol.hasInstance`).
- [@babel/plugin-transform-instanceof](https://www.npmjs.com/package/@babel/plugin-transform-instanceof)
applied to your code that uses `instanceof` against `CSSStyleSheet`.
…sts are ignored for IE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
🚀 This PR has been merged! Once a new release is created, any changes will become available on npm. Until then, you can load and install it directly from the Pika CDN:
|
Resolves #12.
Resolves #25.
Fixes #29.
This PR provides support for IE in the polyfill.
@calebdwilliams, sorry for jumping in, I know that you're working on the IE support but you mentioned that you don't have IE11 machine now. So I decided to start working on it in parallel since I have both IE11 and Edge on my machine. Please, feel free to add any solution you prefer.
PR is still in the early stage, a lot of tests are red in IE and Edge now. It may take some time to find a fix all of them.