feat: throw if parent and child routes have the same name #2267
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#2266 demonstrated an edge case that can lead to inconsistent internal state in the matcher.
The problem arises when using nested routes. If the child (or deeper descendant) has the same
name
as its parent, the parent is removed at the same time that the child is added.Removing a parent route should also remove its children, but in this case that removal happens just before the child is added to the matcher. The child still gets added to the matcher, and its
parent
property still points to the parent route, even though that has now been removed. The parent can no longer be resolved directly, but when resolving the child, thematched
array will still contain the removed parent.This problem can occur during the initial router creation:
It can also happen when adding a route dynamically:
This PR introduces a dev-only check for ancestors with the same name and throws an error if a duplicate is found.