-
Notifications
You must be signed in to change notification settings - Fork 1.1k
picImg.currentSrc = picImg.src; with 'use strict'. Writing to read only property #478
Comments
Huh. It should never get to that line in a browser where |
I'm not too familiar with the code. Where is the check to see if it is supported? |
Oh, Picturefill bails right away if responsive images are natively supported—at which point https://github.com/scottjehl/picturefill/blob/master/src/picturefill.js#L26 |
I think |
Some information, why I think we should remove A heavily simplified var src = img.currentSrc || img.src; The code above is simplified and will only return correct cross browser values, if the img is Well in current picturefill I just updated the code inside of the pf3.0 proposal to reflect the needed changes to implement |
Right, yeah I understand the problem better now. As Alexander said, in IE currentSrc and srcset are implemented while picture and sizes aren't. I'm on the IE team and we're seeing it break sites. Thanks Alexander for the code proposal. |
Yeah; we’re gonna need to look into a more granular way of handling our support tests—until now, we could safely assume that full we knew this day would come |
Interesting idea to factor out a |
Yeah, I dig this idea. |
I really like the mutation plugin, because as soon as you use it, it starts to make really fun to script responsive images (The polyfilled mutations are actually working better than in current Chrome). But I'm not so into adding the I can say for sure, that we don't need it internally. For a polyfilled browser only if(!('currentSrc' in document.createElement('img'))) {
Object.defineProperty(HTMLImageElement.prototype, 'currentSrc', {
set: function () {
if (window.console && console.warn) {
console.warn('currentSrc can\'t be set on img element');
}
},
get: function () {
return this.src || '';
},
enumerable: true,
configurable: true
});
} |
Thanks for the fix. Is there still some tests/documentation to be done before it can make its way into master? |
Thank you everyone for looking into this. I would greatly appreciate a solution for this to make its way into the trunk of picturefill as this has forced us to remove the currentSrc API from our implementation of srcset in Project Spartan. We have had to make this decision due to the assumption in the design of this library that the lack of Additionally I would like to request that when this fix makes its way through testing and into the trunk of polyfill that this library use any available community PR outlets to have sites update to the latest version of picturefill. We will be doing this as well in conjunction with you. Ultimately, we would like to add the API back in as soon as possible but we can't do that until we feel our end users will receive a good web viewing experience. Again, thank you for your work on this and please let us know if there is anything that we can do to help. |
add currentSrc support detection (fixes #478)
@andrew-jg and @gregwhitworth |
On the first set: #7 fails (https://cdn.rawgit.com/scottjehl/picturefill/2.4/tests/index.html?notrycatch=true&testNumber=7):
On the second set, all 3 fail, the first two are due to assignment of read-only props in strict mode, and the final one is due to picturefill not being defined. |
We’re going to work on getting a 2.3.1 patch out today. Definitely send us a heads-up if anything stands to trip up native respimg support in Spartan—we had no idea that this was a blocker for you guys. |
Awesome thanks! Yeah, we flighted it out to our insiders and a flood of new sites were submitted that were broken due to this issue. Please let me know when you get the lib fixed and @andrew-jg or I can test it against all of the bugs we have to ensure it works. |
Any way I can get CC’d on issues like that? Your issue tracker is private, yeah? |
Yeah it's private unless it's initially filed in the public via Connect. The second that @andrew-jg found that the issue was due to this library he posted it here; so it's about as good as a cc at this point since those are being triaged and reduced daily. |
Gotcha. We’ll keep an eye out for him! |
Merged, released in 2.3.1, and published to NPM. |
do not test currentSrc, if it is supported natively (see #478)
In src/picturefill.js, line 458 is:
currentSrc is a read only property. So this line does nothing in all major browsers. The currentSrc is updated when the src is, and that's done the line before. Not only does it do nothing, but since "use strict"; is used, some browsers will throw exceptions for trying to modify a read only property.
If you remove this line nothing will break and you will have improved your browser compatibility. New versions of IE throw the exception and the canary version of Chrome does as well :)
The text was updated successfully, but these errors were encountered: