-
-
Notifications
You must be signed in to change notification settings - Fork 144
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
Should provide better errors when DOM has unexpectedly changed (e.g. if a library like fontawesome modifies the DOM, I get an invalid memory address or nil pointer dereference instead of human-readable error) #236
Comments
More or less is related to #204 |
Apologies for not taking a look into this yet. From a cursory glance, this definitely looks like it should work today and appears to be a bug in Vecty. |
#204 is about supporting interoperability with JS libraries in a form that is even better than how React does it, AFAIK, or having better documentation for how to do so today. |
The problem here is that FontAwesome applies its own modifications to the DOM structure and violates work that Vecty has done and expects in subsequent renders. In specific, when your So when Vecty comes back around next time expecting to find the div it previously rendered -- it doesn't and things go kaboom (we should handle reporting such cases better, of course, it is a bug that we do not do this today). The right way to deal with this is to ensure that the changes FontAwesome makes are isolated to an element solely owned by FontAwesome, which Vecty will treat as an opaque element it doesn't manage. You can do this by using elem.Div(
vecty.Markup(
vecty.UnsafeHTML(`<div class="fas" style="color: green">\uf058</div>`),
),
), Now, while this "works" in the fact that it doesn't explode it will not have the effect you want because you really shouldn't be making use of FontAwesome's JS here. The above gives you the same thing you would get in React if you tried to do this: https://play.jsgo.io/6042429512bbaab1ed1563f2c215c7e0e815c3ee What you actually want is something like react-fontawesome but for Vecty: https://fontawesome.com/how-to-use/on-the-web/using-with/react But that requires basically porting that React code to Vecty. The alternative, which is probably a lot better, is to just use the version of FontAwesome that is based on web fonts and not SVGs so it doesn't require any JS logic to replace divs with generated SVG elements. This works much more nicely, and you don't even need to use Here is an example with what you want: https://play.jsgo.io/dc2b897cc9c7a1b542dc343eda9ad42e348c1888 |
I updated the issue title to reflect that we should make this much more obvious when this occurs. Let me know if the above helps or not! :) |
Your response was amazing! And updating the title works for me. I can't disagree that human-readable errors would be great but doing would require a lot of work. Additionally, thank you for bits on the |
It looks like the fontawesome library (v5.8.2) doesn't play nicely with vecty.
The example below shows the check-mark icon in grey but should change to green after typing anything followed by pressing the enter key :
https://play.jsgo.io/119fb23848322ed3323ad3b28614a6674e5a3571
Instead of turning green it produces the following error:
Any thoughts?
The text was updated successfully, but these errors were encountered: