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

Routes with missing optional parameters do not work without a trailing slash (/) #40

Closed
Nickersoft opened this issue Dec 17, 2021 · 3 comments · Fixed by #41
Closed

Comments

@Nickersoft
Copy link

Hey! Great work on this library. Really hope it takes off more because it really is a great solution for routing in SwiftUI.

A minor bug I noticed is that while wildcards do not rely on trailing slashes, optional parameters do. So for example, I had

Route("/chats/*")

which would render regardless of whether I was going to /chats or /chats/:chatID. However, if I redefine this as /chats/:chatID?, then navigating to /chats produces an empty screen. Only if I navigate to /chats/ will the SwiftUI component appear.

It's a minor regex fix I imagine, but nevertheless thought I'd raise it. I can help open a fix if you don't have the time :)

@Nickersoft Nickersoft changed the title Optional parameters do not work without a trailing slash (/) Routes with missing optional parameters do not work without a trailing slash (/) Dec 17, 2021
@Nickersoft
Copy link
Author

Actually, upon further testing, it seems there are times where the routes with optional params aren't matching at all, regardless of whether there is a trailing slash

frzi added a commit that referenced this issue Dec 17, 2021
@frzi
Copy link
Owner

frzi commented Dec 17, 2021

Oof, sorry for the inconvenience! Well caught! A new branch has been created that attempts to fix the problem addressed in your first post. If you'd like, you can test this by changing the package in Xcode to use the fix/issue-40 branch.
Edit: Scratch that, this seems to break other stuff. 🥲

As for the second problem, I presume this is the same problem as addressed in issue #39. Which I'm having some trouble with when it comes to consistently reproducing. So far my only hunch is that some weird optimization in SwiftUI 3 kicks in at a random time and decides to not call the body of some Routes inside a SwitchRoutes - probably because the SwiftUI diffing engine determines that nothing has changed, and thus doesn't bother requesting a new body from the Route... Which is problematic considering the logic of path matching is done inside the body. 😞

But the key problem here is that I'm unable to consistently reproduce this problem... Even when making this example I only encountered this problem once, and have been unable to reproduce it since. So if anyone has a sample project or knows the steps to consistently activate this odd behaviour, I'd be most grateful 🙏

@frzi frzi mentioned this issue Dec 17, 2021
@frzi
Copy link
Owner

frzi commented Dec 17, 2021

Okay let's try that again. The first addressed issue should be fixed in the branch fix/issue-40. You can tell Xcode to use this branch for the SwiftUI Router package if you want to test it out. Will do some testing before merging this to main.

@frzi frzi closed this as completed in #41 Dec 26, 2021
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.

2 participants