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: Paginate adds unexpected trailing slash on index route #6676

Merged
merged 7 commits into from Mar 28, 2023

Conversation

bholmesdev
Copy link
Contributor

Changes

Testing

  • Add tests for next and prev pagination links

Docs

N/A

@changeset-bot
Copy link

changeset-bot bot commented Mar 27, 2023

🦋 Changeset detected

Latest commit: b7a4051

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 27, 2023
@bholmesdev
Copy link
Contributor Author

Will resolve that failed unit test tomorrow! Looks like we expect a / for the root path even with trailing slashes removed. This passed with a false positive since we added /s everywhere, so might special case if the generated route is still '' after generation.

@bholmesdev bholmesdev force-pushed the fix/paginate-build-format-file branch from 8228394 to 56099c1 Compare March 28, 2023 15:37
.changeset/eight-humans-push.md Outdated Show resolved Hide resolved
Comment on lines 58 to 64
if (color === 'blue' && p === 1) {
expect(prevHref).to.be.undefined;
expect(nextHref).to.equal('/posts/blue/2');
}
if (color === 'blue' && p === 2) {
expect(prevHref).to.equal('/posts/blue/1');
expect(nextHref).to.be.undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Do these tests every run? Say when p = '1' ===> p === 1 is false which will cause the test to not run

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, this is a super imperative way to check if the params entry matches one of the items in the list (see the lines just above). Brain-dead solution I know, but oddly the simplest I could find 😅

Copy link
Member

Choose a reason for hiding this comment

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

I meant that p is always a string so comparing it to the numbers will return false
'1' !=== 1

I'm I overlooking something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohhhh right you are! I'm a fool. Will fix

Co-authored-by: Happydev <81974850+MoustaphaDev@users.noreply.github.com>
packages/astro/src/core/render/paginate.ts Outdated Show resolved Hide resolved
@bholmesdev bholmesdev merged commit 5e33c51 into main Mar 28, 2023
14 checks passed
@bholmesdev bholmesdev deleted the fix/paginate-build-format-file branch March 28, 2023 20:05
@astrobot-houston astrobot-houston mentioned this pull request Mar 28, 2023
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.

paginate create broken page.url.prev link for second page (added trailing slash)
3 participants