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

Add base to paginate #11253

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Add base to paginate #11253

wants to merge 9 commits into from

Conversation

kevinzunigacuellar
Copy link
Sponsor Member

@kevinzunigacuellar kevinzunigacuellar commented Jun 14, 2024

Changes

Testing

Updated tests

Docs

withastro/docs#8569

Copy link

changeset-bot bot commented Jun 14, 2024

🦋 Changeset detected

Latest commit: b3c395c

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 Jun 14, 2024
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

A changeset is missing

@@ -77,12 +79,11 @@ export function generatePaginateFunction(
};
}

function correctIndexRoute(route: string) {
function addRouteBase(route: string, base: string) {
Copy link
Member

Choose a reason for hiding this comment

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

I would type base using AstronConfig['base'], so if the type of base changes, this one changes too

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

good observation! maybe I could also update other types that were changed when prop drilling

return '/';
}
return route;
let routeWithBase = base === '/' ? route : removeTrailingForwardSlash(base) + route;
Copy link
Member

Choose a reason for hiding this comment

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

You can use the joinPaths utility here:

export function joinPaths(...paths: (string | undefined)[]) {

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

I thought about using joinPaths but wouldn't it remove the trailingSlash in case it is set to "always"?. My assumption was that both base and route urls were coming in already formatted so I didn't want override them.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

disregard my last comment, updated in 67a81bb

@bluwy
Copy link
Member

bluwy commented Jun 14, 2024

There's no changeset, but presumably this would be a major as existing users would've manually added the base now, and we might break them?

@ematipico
Copy link
Member

But isn't this a bug? Users were using a workaround for the bug. Or do we document that those URLs were meant to be without base?

@github-actions github-actions bot added the semver: major Change triggers a `major` release label Jun 14, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

This PR is blocked because it contains a major changeset. A reviewer will merge this at the next release if approved.

@bluwy
Copy link
Member

bluwy commented Jun 14, 2024

@ematipico The docs doesn't explicit mention about the base. I think it has always worked this way for very long and it's risky to fix it now even if it may be a bug.

I was thinking of documenting that you need to add the base manually. Or maybe paginate() can accept an option to prepend base, which we will turn on automatically in Astro 5?

@ematipico
Copy link
Member

@ematipico The docs doesn't explicit mention about the base. I think it has always worked this way for very long and it's risky to fix it now even if it may be a bug.

I was thinking of documenting that you need to add the base manually. Or maybe paginate() can accept an option to prepend base, which we will turn on automatically in Astro 5?

Yeah, that sounds like a reasonable approach!

@kevinzunigacuellar
Copy link
Sponsor Member Author

I am leaning towards the most simple solution to just edit docs and mention that base is not prepended by default. If it's okay with everyone, I will close the PR an open one in docs. Thanks for all the support @bluwy and @ematipico

@ematipico
Copy link
Member

I am leaning towards the most simple solution to just edit docs and mention that base is not prepended by default. If it's okay with everyone, I will close the PR an open one in docs. Thanks for all the support @bluwy and @ematipico

Make sure to not delete the branch. We will recreate this PR once we start the works towards Astro 5.0

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) semver: major Change triggers a `major` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The "page" prop in paginated dynamic routes doesn’t handle base URLs
3 participants