-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
base: main
Are you sure you want to change the base?
Add base to paginate #11253
Conversation
🦋 Changeset detectedLatest 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 |
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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)[]) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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? |
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? |
There was a problem hiding this 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.
@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 |
Yeah, that sounds like a reasonable approach! |
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 |
Changes
paginate()
Testing
Updated tests
Docs
withastro/docs#8569