-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Polyfill for mediaQuery breaks in IE11 #11358
Comments
Never had this issue in current projects which use accordions. Can you test Foundation Sites 6.5.0 RC1? |
Could reproduce it with a project here. And can you share the used markup and code? |
Probably related: tus/tus-js-client#77 (comment) |
Newest release is here: https://github.com/paulirish/matchMedia.js/blob/master/matchMedia.js |
My UI/UX team member decided to go with an alternate solution, so I'm afraid I didn't save the code or markup changes and have since moved on to other things. But I can tell you that I used webpack to bundle the code (as did the person who reported the issue in your aforementioned "probably related" link... perhaps that's the common denominator?), and for me the error bubbled up from within the |
We had a similar issue and could also trace it back to the patch-package
--- a/node_modules/foundation-sites/js/foundation.util.mediaQuery.js
+++ b/node_modules/foundation-sites/js/foundation.util.mediaQuery.js
@@ -63,6 +63,8 @@ let matchMedia = window.matchMedia || (function() {
}
})();
+window.matchMedia = matchMedia;
+
var MediaQuery = {
queries: [],
@@ -109,7 +111,7 @@ var MediaQuery = {
var query = this.get(size);
if (query) {
- return matchMedia(query).matches;
+ return window.matchMedia(query).matches;
}
return false;
@@ -160,7 +162,7 @@ var MediaQuery = {
for (var i = 0; i < this.queries.length; i++) {
var query = this.queries[i];
- if (matchMedia(query.value).matches) {
+ if (window.matchMedia(query.value).matches) {
matched = query;
}
} |
I also think we should also use polyfills from polyfill.io by the Financial Times https://github.com/Financial-Times/polyfill-service |
@DanielRuf I don't think you want to lock users into using any particular polyfill solution. I'd rather Foundation not use any polyfills at all because some people may only be targeting evergreen browsers (in which case a polyfill only adds unnecessarily to the download size), and not everyone is going to want to create an external dependency on the polyfill.io site (some may prefer to bundle the polyfill with their own code). It should be documented that Foundation has a dependency on this or other newer features of JavaScript/ECMAScript which are only supported in newer browsers, and you can suggest 3rd-party polyfill solutions but it should ultimately be up to the developer as to what polyfill, if any, they want to use. |
Please check the repository and see package.json, this is on npm. |
Well, currently we internally use a matchMedia polyfill (which has bugs) and is a thirdparty code snippet. |
…ow-fix-ie11 fix: set matchMedia on window to fix issue on IE11, fixes #11358
…ill-window-fix-ie11 for v6.5.0 e7554d6 fix: set matchMedia on window to fix issue on IE11, fixes foundation#11358 1a36a44 chore: update MatchMedia polyfill to v0.3.1 Co-Authored-By: Nicolas Coden <nicolas@ncoden.fr> Signed-off-by: Nicolas Coden <nicolas@ncoden.fr>
What should happen?
Foundation should load all of its JavaScript (in this case, trying to initialize an accordion) in IE11 without throwing any exceptions.
What happens instead?
In IE11, get error
SCRIPT65535: Invalid Calling object
in the console window and the accordion does not work.Possible Solution
The cause seems to be the polyfill for
window.matchMedia
. There is a local variablematchMedia
, to whichwindow.matchMedia
is being assigned, and calling this as a function in foundation.util.mediaQuery.js is what seems to trigger the error.The preferable solution would be to remove the polyfill from foundation altogether (just use the native
window.matchMedia
), and leave a note in the setup guide specifying that for older browsers a third-party polyfill will be required (https://github.com/paulirish/matchMedia.js)... Foundation should not be baking in its own polyfills.Steps to Reproduce
How to reproduce:
$(document).foundation()
Context
I'm just trying to use the Accordion plugin. It works in Chrome, but not IE11 b/c of the aforementioned polyfill.
Your Environment
Checklist (all required):
The text was updated successfully, but these errors were encountered: