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(routing): partially dynamic segments are being truncated #10379

Merged
merged 6 commits into from Mar 15, 2024

Conversation

1574242600
Copy link
Contributor

Changes

fix #10122

partially dynamic segments are being truncated and affecting routing.

Testing

units/routing/manifest.test.js

Docs

Copy link

changeset-bot bot commented Mar 10, 2024

🦋 Changeset detected

Latest commit: 402050e

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Mar 10, 2024
@Fryuni
Copy link
Member

Fryuni commented Mar 10, 2024

I reviewed it from my phone, so it was just a quick look over. I'll review it more carefully later today.

Thanks for the PR!

"astro": patch
---

Fix the issue of partially truncated dynamic segments.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Fix the issue of partially truncated dynamic segments.
Fixes a routing issue with partially truncated dynamic segments.

Would be great to add an example as well maybe?

Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
const [{ dynamic, content }] = segment;

return segment.length > 1
? segment.map((s) => d([s])).join('')
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you confirm I have got this right?

This one line is the fix.

Previously, we ignored all but the first RoutePart.

Now, each RoutePart gets passed to this d() function. And the function ultimately still wraps the dynamic RouteParts in square brackets same as it was done before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, you've got it right.
Would there be any issues with this?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, this is great - just took me a while to understand the recursive map, so I thought I'd double check.

Copy link
Contributor

@lilnasy lilnasy left a comment

Choose a reason for hiding this comment

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

Looks great to me! Great work on the test as well.

Copy link
Member

@Fryuni Fryuni left a comment

Choose a reason for hiding this comment

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

I think the recursive mapping is more confusing than needed and either two normal for loops or two nested maps would make it easier to comprehend.

There is one test check that was removed instead of updated.

Besides that, looking good! Sorry for the delay in the review

@1574242600 1574242600 requested a review from Fryuni March 15, 2024 05:46
Copy link
Member

@Fryuni Fryuni left a comment

Choose a reason for hiding this comment

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

LGTM

@ematipico ematipico merged commit 3776ecf into withastro:main Mar 15, 2024
13 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Mar 15, 2024
@1574242600 1574242600 deleted the fix-redirect branch March 18, 2024 06:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redirects for dynamic routes break when files with same name but different extensions exist
6 participants