Skip to content

refactor(sdk): drop the dead hasNextPage page param and stabilise the display select - #1327

Merged
feruzm merged 2 commits into
developfrom
bugfix/sdk-ranked-select-stability
Aug 3, 2026
Merged

refactor(sdk): drop the dead hasNextPage page param and stabilise the display select#1327
feruzm merged 2 commits into
developfrom
bugfix/sdk-ranked-select-stability

Conversation

@feruzm

@feruzm feruzm commented Aug 3, 2026

Copy link
Copy Markdown
Member

Both CodeRabbit notes from #1324, which were correct and not merge blockers.

The page param field was dead

hasNextPage on the page param existed so the query function could short-circuit once the feed ended. Termination now happens by getNextPageParam returning undefined, which means the field is never set to false again and the guard reading it is unreachable. Field and guard both removed.

The test that covered that guard goes with it. Flagging that deliberately rather than quietly, because a test was already lost once on this file: the behaviour it described no longer exists, and termination is covered by the empty-page case added in #1324.

The select was rebuilt every render

select was an inline arrow. React Query reuses its previous result only when both the data and the select function are unchanged, and these options are constructed during render, so the arrow was a new function each time and every page was re-sorted on every render of every community feed.

One stable select per sort restores the memoisation. Keyed by sort rather than a single shared function because the ordering differs: hot keeps the bridge order, everything else sorts by creation date.

Verification

596 SDK tests pass, typecheck clean, package builds. Two new tests cover the select identity, and inlining the arrow again fails the first of them.

Summary by CodeRabbit

  • Bug Fixes
    • Improved ranked-post pagination to reliably fetch subsequent pages.
    • Pagination now correctly stops when the final page is empty.
    • Preserved consistent post ordering after additional pages load.
    • Improved stability when changing sort options.
    • Simplified pagination behavior for more predictable loading across supported sorting options.

… display select

Follow-up to #1324, both review notes from that PR.

hasNextPage became vestigial once getNextPageParam returned undefined to
terminate: it was never set to false again, so the query function's
short-circuit on it was unreachable. Field and guard both removed. The
test that covered that guard goes with it, since the behaviour it
described no longer exists; termination is covered by the empty-page case.

`select` was an inline arrow, and React Query only reuses its previous
result when both the data and the select function are unchanged. These
options are rebuilt on every render, so every page was re-sorted on every
render. One stable select per sort restores the memoisation.
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1df1661a-7836-470a-9bf9-3d135e767b30

📥 Commits

Reviewing files that changed from the base of the PR and between da16f66 and ecefc8b.

⛔ Files ignored due to path filters (7)
  • packages/sdk/dist/browser/index.d.ts is excluded by !**/dist/**
  • packages/sdk/dist/browser/index.js is excluded by !**/dist/**
  • packages/sdk/dist/browser/index.js.map is excluded by !**/dist/**, !**/*.map
  • packages/sdk/dist/node/index.cjs is excluded by !**/dist/**
  • packages/sdk/dist/node/index.cjs.map is excluded by !**/dist/**, !**/*.map
  • packages/sdk/dist/node/index.mjs is excluded by !**/dist/**
  • packages/sdk/dist/node/index.mjs.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (4)
  • packages/sdk/CHANGELOG.md
  • packages/sdk/package.json
  • packages/wallets/CHANGELOG.md
  • packages/wallets/package.json

📝 Walkthrough

Walkthrough

The ranked-post query now uses cursor-only pagination. It removes hasNextPage from page parameters and cursors. It also caches display-order selectors per sort value and adds identity tests. The SDK and wallets packages receive patch release updates.

Changes

Ranked post query

Layer / File(s) Summary
Cursor-only pagination contract
packages/sdk/src/modules/posts/queries/get-posts-ranked-query-options.ts, packages/sdk/src/modules/posts/queries/get-posts-ranked-query-options.spec.ts
Pagination no longer uses hasNextPage. Empty final pages produce an undefined next-page parameter. Returned cursors contain only the last entry’s author and permlink.
Stable sort-specific selectors
packages/sdk/src/modules/posts/queries/get-posts-ranked-query-options.ts, packages/sdk/src/modules/posts/queries/get-posts-ranked-query-options.spec.ts
The query uses cached selectors for each sort value. Tests verify shared selector identity for the same sort and distinct identity across sorts.
Patch release metadata
packages/sdk/CHANGELOG.md, packages/sdk/package.json, packages/wallets/CHANGELOG.md, packages/wallets/package.json
The SDK version changes to 2.3.73. The wallets version changes to 5.0.73 and records the SDK update.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • ecency/vision-next#1183: Both PRs modify the ranked-post query and tests, including pagination-related typing and behavior.
  • ecency/vision-next#1324: This PR follows changes in the same ranked-post query and refines pagination and selector behavior.

Poem

A rabbit follows each cursor trail,
While empty pages end the tale.
Stable sorts keep selectors bright,
Same sorts share one cached delight.
Patch notes mark the changes done—
Hop, hop, ranked posts run!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes both main changes: removing the unused page parameter and stabilizing the display select.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/sdk-ranked-select-stability

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/sdk/src/modules/posts/queries/get-posts-ranked-query-options.spec.ts (1)

243-257: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test React Query behavior instead of selector reference identity.

a.select === b.select asserts the factory implementation. Test that rebuilding options with unchanged query data does not cause another display transformation. Keep the existing ordering tests for visible output.

As per coding guidelines, use Vitest for tests and “test user-visible behavior rather than implementation details.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/sdk/src/modules/posts/queries/get-posts-ranked-query-options.spec.ts`
around lines 243 - 257, Replace the selector reference-identity assertions in
the “select identity” tests with Vitest coverage of React Query’s behavior:
rebuild options for the same sort with unchanged query data and verify the
display transformation is not rerun. Preserve the existing ordering/output
tests, and assert observable transformation behavior rather than function
identity.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@packages/sdk/src/modules/posts/queries/get-posts-ranked-query-options.spec.ts`:
- Line 56: Remove the explicit any casts in the affected tests and use typed
helpers to narrow options.queryFn before invoking it. Preserve type-safe access
to getNextPageParam and select while keeping the existing test behavior
unchanged.

---

Nitpick comments:
In
`@packages/sdk/src/modules/posts/queries/get-posts-ranked-query-options.spec.ts`:
- Around line 243-257: Replace the selector reference-identity assertions in the
“select identity” tests with Vitest coverage of React Query’s behavior: rebuild
options for the same sort with unchanged query data and verify the display
transformation is not rerun. Preserve the existing ordering/output tests, and
assert observable transformation behavior rather than function identity.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ee777c23-e5f7-4f9f-90f5-40220ecc6d44

📥 Commits

Reviewing files that changed from the base of the PR and between c895aa2 and da16f66.

📒 Files selected for processing (2)
  • packages/sdk/src/modules/posts/queries/get-posts-ranked-query-options.spec.ts
  • packages/sdk/src/modules/posts/queries/get-posts-ranked-query-options.ts


const options = getPostsRankedInfiniteQueryOptions('created', 'hive')
const result = await (options.queryFn as any)(makeInfiniteContext(options, { hasNextPage: true }))
const result = await (options.queryFn as any)(makeInfiniteContext(options, {}))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Remove the explicit any casts.

These changed lines produce configured ESLint errors. Use typed helpers that narrow options.queryFn before invocation. Preserve typed access to getNextPageParam and select.

Also applies to: 66-66, 80-80, 111-111, 129-129, 141-141, 225-225, 227-227, 233-233

🧰 Tools
🪛 ESLint

[error] 56-56: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/sdk/src/modules/posts/queries/get-posts-ranked-query-options.spec.ts`
at line 56, Remove the explicit any casts in the affected tests and use typed
helpers to narrow options.queryFn before invoking it. Preserve type-safe access
to getNextPageParam and select while keeping the existing test behavior
unchanged.

Source: Linters/SAST tools

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Checked this against the configured lint scope rather than acting on it, and it does not hold as a finding against this PR.

Two things. First, the casts are the existing convention in this file, not something this PR introduces: develop has 15 occurrences of as any in it and this branch has 14, so the change reduces them by one. The lines cited are almost all restored original code.

Second, the SDK's own linter does not currently run. packages/sdkhas"lint": "eslint ."and aneslint.config.mjs, but invoking it throws from @typescript-eslint/utils` RuleCreator: the workspace resolves eslint 8.57.1 while the installed typescript-eslint build targets eslint 9. So nothing is reporting these errors today, which is also why the CI lint job is green.

Narrowing the types here would mean typing queryFn, getNextPageParam and select off infiniteQueryOptions through their generics, which is worth doing for the whole file rather than for the two lines this PR touched. The eslint version mismatch is worth fixing first, since otherwise the convention will keep drifting with nothing to catch it. Happy to open an issue for both if useful.

@feruzm feruzm added the patch Bug fixes and patches (1.0.0 → 1.0.1) label Aug 3, 2026
@feruzm
feruzm merged commit 35f23d9 into develop Aug 3, 2026
3 of 4 checks passed
@feruzm
feruzm deleted the bugfix/sdk-ranked-select-stability branch August 3, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Bug fixes and patches (1.0.0 → 1.0.1)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant