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: explode optional segments for relative paths in nested routes #9684

Merged
merged 6 commits into from
Dec 7, 2022

Conversation

pcattori
Copy link
Contributor

@pcattori pcattori commented Dec 6, 2022

#9650 added support for matching routes with optional path segments, but did not work for nested routes.
This PR fixes that.

It also refactors the approach to explicitly "explode" a path with optional path segments into the equivalent set of valid combinations of paths without optional segments (see explodeOptionalSegments jsdoc for an example). The paths are "exploded" prior to creating the route metadata, which means that when the route metadata gets initialized its already correct. Previously, we needed to surgically modify route metadata for a branch (which we were only handling correctly for unnested routes).

@changeset-bot
Copy link

changeset-bot bot commented Dec 6, 2022

⚠️ No Changeset found

Latest commit: 6f4c824

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pcattori pcattori mentioned this pull request Dec 6, 2022
7 tasks
@pcattori pcattori changed the title Pedro/explode optional segments Explode optional segments for relative paths in nested routes Dec 6, 2022
@pcattori pcattori force-pushed the pedro/explode-optional-segments branch from 9d5a7d9 to ae6a2db Compare December 6, 2022 02:06
explicitly 'explode' path with optional path segments.
@pcattori pcattori force-pushed the pedro/explode-optional-segments branch from ae6a2db to 8688e60 Compare December 6, 2022 02:07
@pcattori pcattori marked this pull request as ready for review December 6, 2022 02:12
@pcattori pcattori changed the title Explode optional segments for relative paths in nested routes fix: explode optional segments for relative paths in nested routes Dec 6, 2022
packages/router/utils.ts Outdated Show resolved Hide resolved
});
for (let exploded of explodeOptionalSegments(route.path)) {
flattenRoute(route, index, exploded);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is close - but I'm still seeing some ?'s in flattened paths (and also in the then-generated routesMeta.relativePath. I think always as part of the last optional segment? Here's the flattened/ranked paths for the unit test above:

Screenshot 2022-12-06 at 6 22 02 PM

Otherwise the routesMeta relative paths are looking right to me though!

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll try to hit this with a few more complex unit tests scenarios tomorrow as well 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, forgot to update code to handle empty segments for nested routes. Should work now!

@pcattori pcattori force-pushed the pedro/explode-optional-segments branch from d76bc59 to e4cc374 Compare December 7, 2022 17:33
packages/router/utils.ts Outdated Show resolved Hide resolved
@pcattori pcattori merged commit c6c8c3b into dev Dec 7, 2022
@pcattori pcattori deleted the pedro/explode-optional-segments branch December 7, 2022 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants