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

fix: avoid infinite loop when hitting an inexistent route #49

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

giacomocerquone
Copy link

@giacomocerquone giacomocerquone commented Aug 21, 2024

closes #48

Testing the pr

When testing the pr, remember to

  1. Add ElmBook.ThemeOptions.useHashBasedNavigation in the UI/ElmBook.elm file
  2. Modify a chapter so to add an inexistent link to test the bugfix

FYI: The links must be in this format #/guides/inexistent

Rationale

When hashBasedNavigation is true and a route that can't be found among the chapters is hit, this is what happens:

  1. OnUrlChange is triggered
  2. extractPath url_ is called and returns /guides/inexistent (url.fragment) which is then assigned to url
  3. The catch all "_" case executes
  4. An urlChapter can't be found so it goes in the Nothing case
  5. The Nothing case navigates to #/
  6. The OnUrlChange is triggered again
  7. extractPath url_ is called and returns / (url.fragment is Nothing hence Maybe.withDefault kicks in) which is then assigned to url
  8. The "/" case executes
  9. It gets the fallback chapter's url (/overview in the case of this repo) and navigates there, which is a problem because we have hashBasedNavigation set to true
  10. The OnUrlChange is triggered again
  11. extractPath url_ is called and when hashBasedNavigation is true it returns the fragment or / and in the case of /overview the fragment is Nothing.
  12. From now on it repeats from 8 to 12 infinitely

Screenshot 2024-08-21 at 20 52 51

Solution

How do we stop it? Should be simple honestly, when the fallback chapter is retrieved, let's add the hashtag on front.

Screencast

Screen.Recording.2024-08-22.at.00.29.09.mov

Copy link

netlify bot commented Aug 21, 2024

Deploy Preview for elm-book-in-elm-book failed.

Name Link
🔨 Latest commit 224f406
🔍 Latest deploy log https://app.netlify.com/sites/elm-book-in-elm-book/deploys/66c66847e57956000849a21e

@@ -346,6 +356,7 @@ update config msg model =
targetChapter =
if Array.isEmpty filteredChapters then
Nothing

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default elm formatter added this

@giacomocerquone
Copy link
Author

Pipe is failing because of this

image

@giacomocerquone giacomocerquone changed the title fix: avoid infinite loop on hitting an inexistent route fix: avoid infinite loop when hitting an inexistent route Aug 21, 2024
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 this pull request may close these issues.

bug: when hashBasedNavigation is true and url route can't be found, apps become unresponsive
1 participant