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
Yew for some reason interacts poorly with the twttr widgets API #2484
Comments
Well, I've copied your files into a test directory and I can't get the tweet to load on the correct HTML. But after some playing I realized, this is an issue of when your script is ran. I'm not too familiar with the all inner-workings but the solution is to add |
Yew clears the element where you mount the app, by default the The reconciler of yew does not try to preserve elements that exist before an app is mounted, it's concerned with managing the virtual dom as returned from component view functions. Modifying the same part of the DOM that yew expects to have control over will lead to poor results. There are safety hatches, in the form of |
So I still don't know why, but it's clear now that it's some form of ordering issue as @rand0m-cloud pointed to above. Twitter has a loader snippet which defines the <script>window.twttr = (function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0],
t = window.twttr || {};
if (d.getElementById(id)) return t;
js = d.createElement(s);
js.id = id;
js.src = "https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);
t._e = [];
t.ready = function(f) {
t._e.push(f);
};
return t;
}(document, "script", "twitter-wjs"));</script> The So doesn't seem like it's a yew issue to me but just the first setup where I encountered this particular issue so I'm closing this. Thanks for the help everyone! |
Problem
When I try to use yew (through
trunk
) and build a component which makes use of the twitter factory API, any use of the twitter API causes it to do nothing and produce aPromise
which never resolves.Steps To Reproduce
Cargo.toml
:index.html
:src/main.rs
:Run with:
With the above, the tweet is expected to render after a 1 second delay. It doesn't! Just doing this however works as expected:
The issue seems to trigger when loading into the WASM application. Everything produced by
trunk
seems to work up until the point we load into the WASM instance through__wbindgen_start
. Simply commenting it out allows it to work again:index-<hash>.js
whiletrunk serve
is running (note that you also have to add a<div id="tweet"></div>
inindex.html
):// wasm.__wbindgen_start();
Beyond that, I do not have the necessary understanding of WASM to troubleshoot this. And there's the issue that it's an issue triggered somewhere within Twitters widgets API.
Environment:
0.19.3
1.59.0
trunk
google chrome 98.0.4758.102
andfirefox 97.0.1
.The text was updated successfully, but these errors were encountered: