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

<a> elements without href cause page reloads with Browser.application in Elm 0.19 #17

Open
glennsl opened this issue Oct 8, 2018 · 5 comments · May be fixed by #19
Open

<a> elements without href cause page reloads with Browser.application in Elm 0.19 #17

glennsl opened this issue Oct 8, 2018 · 5 comments · May be fixed by #19

Comments

@glennsl
Copy link

glennsl commented Oct 8, 2018

This is because "empty" links will cause a UrlRequest with Browser.External "".

My solution is to pattern match on this and just do nothing. You'll most likely pattern match on the UrlRequest anyway to get at the contents of it, so it's a small change, but not terribly obvious. So it might be a good idea to warn of this in the documentation.

Unless there are better solutions that can be implemented in the library to avoid the user dealing with this entirely, but I do not think there is.

JolandaNava added a commit to JolandaNava/elm-bulma that referenced this issue Oct 28, 2018
adds a `href = ""` attribute to all elements using <a>
relies on reordering of elements in `node` function to work (user specified `href` attribute will take precedence because specified last)

closes surprisetalk#17
@JolandaNava
Copy link
Contributor

A workaround is to provide a href attribute with an empty string as input - this prevents the reload behaviour. Sending in a PR that would make this a default in any <a> elements.

@glennsl
Copy link
Author

glennsl commented Oct 28, 2018

@JolandaNava Does href "" not also generate Browser.External "", and therefore also reload the page unless handled the same way in update? That's what I claim in https://github.com/elm/compiler/issues/1820 at least.

Also, there's a PR with a proper fix in elm/virtual-dom#142, but not easy to say when that'll get merged and released. A (temporary) fix here seems like a good idea still.

@JolandaNava
Copy link
Contributor

@glennsl it doesn't reload the page in my current project (hence the suggestion). I am following the SPA example for how I handle routing so maybe I'm implicitly doing what you suggested in my update?
Agreed that, if this works, it's at best a temporary fix.

@glennsl
Copy link
Author

glennsl commented Oct 28, 2018

Interesting, I guess I somehow got it wrong before then, and that it generates a Browser.Internal rather than a Browser.External. This might be what fixes it in the SPA example. I have to test this out, but if it is then your PR doesn't really "fix" the issue so much as make it a slightly different issue, that you might already have addressed if you follow the SPA example closely. But if you don't, it seems you might still experience the same symptoms.

@surprisetalk
Copy link
Owner

Sorry I've been out of the loop! And thanks for the amazing work @JolandaNava !
I'm going to hold off on any decisions until I see what happens in the issues @glennsl referenced above. For now, you should be able to add href and onClick events on each Bulma element from your app. If you want a "nothing" button, it's probably best to pattern-match it on Nothing like @glennsl says.
Thanks again!

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

Successfully merging a pull request may close this issue.

3 participants