Fix leading slash creating incorrect conflict resolution between pages generated from static routes and rest parameters #10607
+44
−2
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.
Changes
Following the PR #10298 to fix issue #9103, my specific problem was still not fixed, as mentioned in #9103 (comment).
In #9103 (comment) I explained my following findings:
//test/ing/
//
with/
frankbits@737d407route.generate()
withstringifyParams()
which callsroute.generate()
internally, after trimming slashes frankbits@78d604cJSON.stringify()
of the return-value ofstringifyParams()
, as the returned value ofroute.generate()
is already a string, and I had to parse it back to a string without""
and the other 2 places where the function is used should not have any problem anywhere without theJSON.stringify()
, as the return-value i used as an array-key to store/retrieve "static path"-objects and only have to fit to each other.Testing
I added frankbits@a913d04 ( edited frankbits@7cba77b, frankbits@22fb67e) a test with the slug having a leading slash (similar to the failing path in my MRE of my original issue #9103)
Also added a test for leading slash in a dynamic route d4bd99e (see #10607 (comment))
All test in
packages/astro/test/dynamic-route-collision.test.js
finish successfully.I couldn't run all test of the project, as
pnpm run test
ran into errors setting up tests.Docs
/cc @withastro/maintainers-docs for feedback!
I have not updated the docs, as my change is not in conflict with the documented behaviour.
But it could probably be sensible to add information to the routing-doc about leading and trailing slashes in dynamic and rest-parameters. (as mentioned in #9103 (comment))