question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

crossOrigin attribute needs to be applied before <img src> attribute

See original GitHub issue

Do you want to request a feature or report a bug?

bug

What is the current behavior?

React doesn’t handle changing the crossOrigin attribute properly

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn’t have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:

Same img going from no crossorigin attribute to crossorigin=anonymous

In pure JS: http://jsfiddle.net/R6DWN/39/ On first load Origin is not set (as should be according to chrome):

Referer: http://fiddle.jshell.net/_display/
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36

When clicking reload:

Origin: http://fiddle.jshell.net
Referer: http://fiddle.jshell.net/_display/
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36

In React: https://jsfiddle.net/69z2wepo/316905/

when clicking reload the img element does get updated with crossorigin but the image isn’t reloaded

Same img loading twice with crossorigin=anonymous

In pure JS: http://jsfiddle.net/R6DWN/40/

The request is only fired once if you check the network tab with those headers:

Referer: https://fiddle.jshell.net/_display/
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36

In React: https://jsfiddle.net/69z2wepo/316907/

On first load you have those headers:

Origin: https://fiddle.jshell.net
Referer: https://fiddle.jshell.net/_display/
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36

On clicking reload for some reason the request is fired again WITHOUT the origin header even with the crossOrigin=‘anonymous’:

Referer: https://fiddle.jshell.net/_display/
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36

What is the expected behavior?

When rerendering an img with the same src but defining the crossorigin attribute it should reload the image with the origin header

When rerendering an img with the same src and crossorigin=anonymous again it should not fire a new request without origin header

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

Google Chrome Version 69.0.3497.100 (Official Build) (64-bit)

React v16.6.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13

github_iconTop GitHub Comments

17reactions
arackafcommented, Jun 10, 2020

I just bumped into this. Can we re-open this issue please?

4reactions
rodovichcommented, Mar 22, 2019

If you change the JSX to have the crossorigin tag before the src then it looks like it works correctly.

Can this be relied on? As far as I can tell neither Babel docs nor the JSX spec specify that the input order is preserved in the output (although empirically it does appear to be with Babel), and MDN states that object iteration order is implementation-dependent (although empirically it does appear to match the declaration order, at least with object literals with string keys).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is crossorigin attribute necessary to load images into a ...
Yes, img element src URL requests only send Origin headers if a crossorigin attribute is set. That comes from html.spec.whatwg.org/… and html.
Read more >
Allowing cross-origin use of images and canvas - HTML
HTML provides a crossorigin attribute for images that, in combination with an appropriate CORS header, allows images defined by the <img> ...
Read more >
If you set img.crossOrigin attribute before the img.src, it taints a ...
Issue 678265: If you set img.crossOrigin attribute before the img.src, it taints a canvas when painted ; Status: Untriaged (was: Available)
Read more >
HTML img crossorigin Attribute - Dofactory
The crossorigin attribute on an <img> tag specifies that CORS is supported when loading an image from a third party server or domain....
Read more >
<img crossorigin=""> » - HTML
The crossorigin attribute specifies how cross-origin images (images that violate the same origin policy) are treated. This is relevant in JavaScript web apps ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found