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

Live server redirects static assets to wrong links #138

Closed
sophicshift opened this issue Aug 28, 2022 · 2 comments · Fixed by #139
Closed

Live server redirects static assets to wrong links #138

sophicshift opened this issue Aug 28, 2022 · 2 comments · Fixed by #139
Labels
bug Something isn't working

Comments

@sophicshift
Copy link
Collaborator

sophicshift commented Aug 28, 2022

Describe the bug
When clicking on anchor links that point to static files (AssetStatic) on the live server, the browser is redirected to the wrong address.

To Reproduce
Steps to reproduce the behavior:

  1. Clone ema-template
  2. Add a line like the following patch:
diff --git a/src/Main.hs b/src/Main.hs
index 314785f..3e7c022 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -80,6 +80,7 @@ renderBody :: Prism' FilePath Route -> Model -> HtmlRoute -> H.Html
 renderBody rp model r = do
   H.div ! A.class_ "container mx-auto mt-8 p-2" $ do
     renderNavbar rp r
+    H.a ! A.href (staticRouteUrl rp model "logo.svg") $ "Click me"
     H.h1 ! A.class_ "text-3xl font-bold" $ H.toHtml $ routeTitle r
     case r of
       HtmlRoute_Index -> do
  1. Run the live server
  2. Click on the new "Click me" link
  3. Browser is redirected to /static/logo.svg
  4. Get decodeRoute returned Nothing error

Note: the right /logo.svg path gets inserted into history, so pressing the back button makes the logo display as expected.

Expected behavior
Browser should be redirected to the /logo.svg link and logo displayed.

Desktop (please complete the following information):

  • Browser: Firefox, Chromium

Additional context
This is a bug related to the live server, since disabling JS on the browser fixes the issue. This also explains why like images, stylesheets and scripts get loaded without problems.

@sophicshift sophicshift added the bug Something isn't working label Aug 28, 2022
@sophicshift sophicshift changed the title Client JS redirects static assets to wrong links Live server redirects static assets to wrong links Aug 28, 2022
@sophicshift sophicshift mentioned this issue Aug 28, 2022
@srid srid closed this as completed in #139 Aug 28, 2022
srid added a commit that referenced this issue Aug 28, 2022
* live server: fix AssetStatic redirection

* Refactor: reorganize

* Changelog and version

Co-authored-by: Sridhar Ratnakumar <[email protected]>
@srid
Copy link
Owner

srid commented Aug 28, 2022

Note: the right /logo.svg path gets inserted into history, so pressing the back button makes the logo display as expected.

I find it weird that it goes back to the logo again; it should go back to the original route. That seems to be another bug. It happens even after #139

srid added a commit to srid/ema-template that referenced this issue Aug 28, 2022
@sophicshift
Copy link
Collaborator Author

sophicshift commented Aug 28, 2022

I find it weird that it goes back to the logo again; it should go back to the original route. That seems to be another bug. It happens even after #139

After the PR I see it behaving correctly in Firefox, and in Chrome too, but in Chrome the address is changed back to the original route while the page itself does not change. Is this what you see?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants