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

Trailing slashes (#2154) take 2 #2217

Merged
merged 9 commits into from
Feb 27, 2024
Merged

Conversation

skirsdeda
Copy link
Contributor

@skirsdeda skirsdeda commented Jan 21, 2024

Fixes regression in #2172. The problem was that it would count 1 path segment in root path ("/") instead of zero. Just moved root path special case to segment extractor function.

Router example tests now pass, also made sure router tests pass (at least with "ssr" feature). Might have missed smth else.

@skirsdeda
Copy link
Contributor Author

There are still differences in path matching corner-cases. In router example '//settings' or '/settings/' or '//settings/' (actual path entered in browser) no longer match settings page but it works fine in previous implementation.

@gbj
Copy link
Collaborator

gbj commented Jan 26, 2024

Thanks for updating this! I'm leaving a comment here just to note that I'll need to set aside some time to do a more in depth review, hopefully in the near future. I am going to be doing a pretty large router rewrite for 0.7, and will build this into it in any case. I'll try to get to this some time soon, but in the meantime it is good to be able to point people to this branch as a solution for the particular situation. I'm grateful for your work.

Copy link
Contributor

@zoomiti zoomiti left a comment

Choose a reason for hiding this comment

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

Not sure if I should've reviewed this, just wanted to leave my two cents about this

/// Overrides any setting applied to [`crate::components::Router`].
/// Serves as a default for any inner Routes.
#[prop(optional)]
trailing_slash: Option<TrailingSlash>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this being stored as an option? if there is a default value for TrailingSlash why don't we let #[prop(optional)] do the work of setting it to its default value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because None means "inherit trailing_slash setting from parent routes" (see routes::inherit_settings https://github.com/leptos-rs/leptos/pull/2217/files#diff-31f96b333e0c4d9391387d676c81a652b1a975d984ee51b3e2cbd1d4ecf8de8cR352)

/// Overrides any setting applied to [`crate::components::Router`].
/// Serves as a default for any inner Routes.
#[prop(optional)]
trailing_slash: Option<TrailingSlash>,
Copy link
Contributor

Choose a reason for hiding this comment

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

See previous comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as for Route.

/// Overrides any setting applied to [`crate::components::Router`].
/// Serves as a default for any inner Routes.
#[prop(optional)]
trailing_slash: Option<TrailingSlash>,
Copy link
Contributor

Choose a reason for hiding this comment

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

see previous comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as for Route.

use std::{cell::RefCell, rc::Rc};

#[component]
fn DefaultApp() -> impl IntoView {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe add a redundant test for Drop in case the default ever changes?

@gbj
Copy link
Collaborator

gbj commented Feb 16, 2024

@skirsdeda I have reviewed this and tested it out in some depth, including against the examples that caused broken behavior last time, and it looks to me like this is right. I agree with zoomiti's comments that if the trailing slash props implement Default, they don't need the Option<_>.

If you address that then I think this should be ready to merge.

@skirsdeda
Copy link
Contributor Author

@gbj Route components can inherit trailing slash behavior from parent routes, that's the reason for having Option<_> there. However, Router doesn't need Option<_> since it cannot be nested, so I can fix that.

NfNitLoop and others added 5 commits February 18, 2024 19:47
* retain trailing slashes in paths but leave matching trail-slash-insensitive

* fix: Allow trailing slashes to remain in leptos_path.

* Better handling for trailing slashes. (leptos-rs#2154)

This adds a trailing_slash option to <Router> and <Route>.

By default, this option is backward compatible with current Leptos
behavior, but users can opt into two new modes for handling trailing
slashes.

* cargo fmt

* Fix redirect routes for wildcard patterns.

* Clippy fixies

* (Re)Reduce the scope of PossibleBranchContext's internals.

* Test real code, not copied code.

* Test TrailingSlash redirects.

* Fixes and more tests for matching "" && "/".

This path is the exception to the rule and *should* be treated
as equivalent regardless of its trailing slash.

* cargo fmt

---------

Co-authored-by: Tadas Dailyda <tadas@dailyda.com>
@gbj
Copy link
Collaborator

gbj commented Feb 27, 2024

Okay, thanks very much for the updates and for all your work on this! Merging now 🎉

@gbj gbj merged commit aa97700 into leptos-rs:main Feb 27, 2024
61 checks passed
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.

None yet

4 participants