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

[fixed] Match routes piece-by-piece #2421

Merged
merged 1 commit into from
Oct 30, 2015
Merged

[fixed] Match routes piece-by-piece #2421

merged 1 commit into from
Oct 30, 2015

Conversation

taion
Copy link
Contributor

@taion taion commented Oct 30, 2015

Fixes #2355

This is mostly straightforward, except for adding some special-casing to check that we only match at path boundaries.

@@ -44,13 +44,13 @@ function getIndexRoute(route, location, callback) {
}

function assignParams(params, paramNames, paramValues) {
return paramNames.reduceRight(function (params, paramName, index) {
return paramNames.reduce(function (params, paramName, index) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a leftover from a direction I ended up abandoning, but it seems like it simplifies this function a bit to not use reduceRight.

Copy link
Member

Choose a reason for hiding this comment

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

reduceRight uses the last params first, so subsequent params that are named the same thing appear after previous values in the params array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems simpler but equivalent to use reduce and push over reduceRight and unshift, though.

@taion
Copy link
Contributor Author

taion commented Oct 30, 2015

Rebased.

knowbody added a commit that referenced this pull request Oct 30, 2015
[fixed] Match routes piece-by-piece
@knowbody knowbody merged commit b57580e into remix-run:master Oct 30, 2015
@knowbody
Copy link
Contributor

thanks!

@taion taion deleted the matching branch October 30, 2015 21:08
@mjackson
Copy link
Member

This PR makes me nervous. No tests? What are you trying to fix?

@mjackson
Copy link
Member

@knowbody Please wait for me to review stuff like this before merging!

@knowbody
Copy link
Contributor

I did it again, I stop merging lol 🙈

@mjackson
Copy link
Member

If we have great tests around something, then merge away. But I think @taion made some changes to behavior that we don't actually have tests for.

I was demo-ing the router last night to a crowd in Vancouver, and some of the examples on master are broken. So we're in danger of regressing when we make major changes like this without any tests.

@taion
Copy link
Contributor Author

taion commented Oct 30, 2015

@mjackson

Most of the code exercised here is covered by https://github.com/rackt/react-router/blob/master/modules/__tests__/matchRoutes-test.js. I didn't get a chance to add tests for a potentially new error case, which would be something like

<Route path="a">
  <Route path="b" />
</Route>

matching something like /ab, nor did I get a chance to add a test to actually cover #2355. I wanted to get this PR up and get some feedback before spending more time on this.

Are you on Discord or IRC? Might be easier to explain what this is trying to do on chat.

@mjackson
Copy link
Member

Sorry, I'm busy right now. I can probably talk about this later tonight. For now, would you be ok reverting and opening another PR?

@mjackson
Copy link
Member

BTW, just wanted to say thanks for working on this @taion. I don't mean to be unappreciative.

It's just been really tricky to get this right, hence the subtle bugs. Whenever we're making changes around this kind of thing we need to take the time to add stringent tests, preferably the kind that fail before we make the change to the code.

@taion
Copy link
Contributor Author

taion commented Oct 30, 2015

I'm okay with reverting. I believe this code works, though - I'm putting together a PR right now that adds test cases that fail against the code prior to this PR, and verifies that the new code for splitting on path separators works.

@taion
Copy link
Contributor Author

taion commented Oct 31, 2015

I just realized one consequence of this change - this now causes us to normalize duplicate slashes between route segments, e.g.

<Route path="/foo">
  <Route path="bar" />
</Route>

will now match e.g. /foo////////bar, whereas previously it would only have matched /foo/bar (but also e.g. /foo/bar///////). But #2425 is not consistent with that behavior (since it only normalizes slashes at the end).

Not sure what behavior is desirable here.

@taion taion mentioned this pull request Apr 12, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants