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: remark-lsx pagination #9513

Merged
merged 1 commit into from
Dec 23, 2024
Merged

Conversation

miya
Copy link
Member

@miya miya commented Dec 23, 2024

Task

  • #159497 Lsx の "Load more" をクリックした時に正しくページングされない

@miya miya requested a review from yuki-takei December 23, 2024 04:27
@miya miya self-assigned this Dec 23, 2024
Copy link

changeset-bot bot commented Dec 23, 2024

⚠️ No Changeset found

Latest commit: 8217a12

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@miya miya changed the title Convert query parameters 'offset' and 'limit' to integers fix: remark-lsx pagination Dec 23, 2024
query('offset').optional().isInt(),
query('limit').optional().isInt(),
query('offset').optional().isInt().toInt(),
query('limit').optional().isInt().toInt(),
Copy link
Member Author

Choose a reason for hiding this comment

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

バグの原因

offset が文字列になっていたことにより、 ("50" ?? 0) + pages.length の結果が 5050 のようになってしまっていた。

const cursor = (offset ?? 0) + pages.length;

API のレスポンスである cursor は次の Road more をクリックした時に走る API リクエストのクエリパラメーターである offset に入る。

async([endpoint, pagePath, options, offset, limit, parseErrorMessage]) => {
if (parseErrorMessage != null) {
throw new Error(parseErrorMessage);
}
const apiOptions = Object.assign({}, options, { num: undefined }) as LsxApiOptions;
const params: LsxApiParams = {
pagePath,
offset,
limit,
options: apiOptions,
};
try {
const res = await axios.get<LsxApiResponseData>(endpoint, { params });

解決策

express-validation でクエリパラメータに指定された文字列を Number に変換する
https://express-validator.github.io/docs/api/validation-chain/#toint

mergify bot added a commit that referenced this pull request Dec 23, 2024
@mergify mergify bot merged commit d9c56db into master Dec 23, 2024
24 checks passed
@mergify mergify bot deleted the fix/159499-remark-lsx-pagination branch December 23, 2024 08:07
@github-actions github-actions bot mentioned this pull request Dec 23, 2024
@github-actions github-actions bot mentioned this pull request Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants