Skip to content
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

Embed does not update on re-render after src property changes #12665

Closed
stackptr opened this issue Apr 21, 2018 · 5 comments
Closed

Embed does not update on re-render after src property changes #12665

stackptr opened this issue Apr 21, 2018 · 5 comments

Comments

@stackptr
Copy link

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

Bug

What is the current behavior?

There is a component which renders a child <embed>. The src property is retrieved from an endpoint and depends on the props passed to the component. When the property changes on an existing <embed>, the contents of that embed does not change. To fix, the component has to entirely replace the <embed> with something else (for instance, a loading state), and then put a new <embed> with the updated src.

I've reproduced this on jsfiddle, below. Two trivia jsfiddles are referred to by the embed, but transitioning by clicking a button does not update the embed despite the property being visibly updated in the DevTools.

https://jsfiddle.net/n5u2wwjg/33890/

What is the expected behavior?

When the src of the <embed> changes, the content should change with it.

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

Reproduced on 16.2.0, unclear which version jsfiddle is using.

Version 65.0.3325.181, macOS 10.13.4 Beta (17E190a)

@gaearon
Copy link
Collaborator

gaearon commented Apr 21, 2018

Have you verified this problem only exists in React and isn’t a DOM issue?

@gruszks
Copy link

gruszks commented Apr 21, 2018

Your are not able to change the src of already rendered embed element.

$('embed').src = 'https://jsfiddle.net/hh11g50z/embedded/result';

Above plaing JS code will not change the content of embed object. I think the solution is to fully recreate embed object with new src.

@aweary
Copy link
Contributor

aweary commented Apr 21, 2018

I think the solution is to fully recreate embed object with new src.

A workaround that accomplishes this without loading states would be to set a key on the embed with the source.

<embed src={this.state.src} key={this.state.src} />

@gaearon gaearon closed this as completed Apr 21, 2018
@gaearon
Copy link
Collaborator

gaearon commented Apr 21, 2018

Closing as this is how the DOM works (and you can force React to recreate the element by using keys).

@soubhikchatterjee
Copy link

This is a browser issue, so you need to programmatically refresh the iframe's content on useEffect()

document.getElementById("iframe").contentDocument.location.reload(true);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants