HeinrichApfelmus / threepenny-gui

GUI framework that uses the web browser as a display.
https://heinrichapfelmus.github.io/threepenny-gui/
Other
439 stars 77 forks source link

URLs with anchors in them prevent JS hook from running #128

Closed blitzcode closed 7 years ago

blitzcode commented 8 years ago

When using anchors to navigate across the page, a URL like 'http://127.0.0.1:8001/#a2' will be used. This URL seems to confuse the JS hook. Only the static page is served, but none of the elements generated by the setup code are added.

HeinrichApfelmus commented 8 years ago

Not sure what's happening here. It looks like clicking a link with anchors to navigate within the page will somehow lead to a reload of the whole page.

blitzcode commented 8 years ago

IIRC, navigating with achors works just fine, but once I refreshed the page the request with the anchor URL will cause the hook to stop working after reload.

HeinrichApfelmus commented 8 years ago

Weird. Could you provide a minimal example, so that I can have a go at testing this?

blitzcode commented 8 years ago

When I connect to http://localhost:8001, everything works as expected. Anything added to the URL will break the JS. So i.e. http://localhost:8001/abc or http://localhost:8001/123 are both broken. It just happens that using anchor tags appends the anchor name to the URL, triggering this issue on refresh. Since threepenny has no API for controlling URL routing, I'd expect this bug to be universal to all threepenny apps. Can you reproduce this behavior by simply appending some garbage to the URL which you use to bring up the page?

HeinrichApfelmus commented 7 years ago

Ah, I think I see what you mean. Navigation with anchor links works fine as long as you do not refresh the page. After you refresh the page (which means that you would loose all state that was local to this page, of course), the connection to the websocket no longer works, because the anchor was added to the URL, and Threepenny tried to use the full URL when connecting to the websocket.

I have attempted to fix this in the latest commit above. Does that work for you?

blitzcode commented 7 years ago

Gave your fix a try, seems like it's fixed now! In the meantime, I could fortunately use JQuery's scrollTo as a workaround for real anchors. The issue was mostly that as stated in #130 the websocket would disconnect, forcing a reload and then surfacing this issue.

HeinrichApfelmus commented 7 years ago

Great! I'll be closing this, then, but feel free to reopen if necessary.