Skip to content

refactor(queries): group query and mutation options into 'xxxQueries' and 'xxxMutations' factories like the Query React examples - #1637

Open
sukvvon wants to merge 1 commit into
mainfrom
refactor/queries-factory
Open

sukvvon wants to merge 1 commit into
mainfrom
refactor/queries-factory

Conversation

@sukvvon

@sukvvon sukvvon commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Summary

Reshape the modules in src/queries to follow the pattern used across the TanStack Query React examples (services/<domain>/queries.ts): one xxxQueries object per domain that builds keys hierarchically and returns queryOptions, plus an xxxMutations object of mutationOptions.

  • docFeedbackQueries / docFeedbackMutations
  • showcasesQueries / showcasesMutations
  • statsQueries, intentQueries, rolesQueries, usersQueries, docsConfigQueries, docsManifestQueries

Details

  • Query key values are unchanged; keys are now derived from a parent (e.g. [...docFeedbackQueries.all(), 'page', params]).
  • Literal keys at call sites (['docFeedback'], ['docFeedback', 'moderation'], ['showcases'], ['showcases', 'mine'], ['stats', 'oss'], ['stats', 'homepage-npm-summary']) now come from the factories.
  • xxxMutations only hold mutationFn; onMutate / onSuccess / onSettled stay at the call site via useMutation({ ...xxxMutations.foo(), ... }).
  • The showcase vote mutation in ShowcaseModerationPage now uses the shared showcasesMutations.vote(), so its mutate call passes { showcaseId, value } instead of { data: { showcaseId, value } }.
  • ossStatsQueryOptions is folded into statsQueries.ossSummary.
  • tests/docs-manifest-cache.test.ts is updated to the new name.

Verified on preview

Signed in on the PR preview by reusing a session_token cookie, then checked the cache before and after each server response:

  • Showcase vote and unvote on /showcase (ShowcaseGallery) and /showcase/$id (ShowcaseDetail): optimistic score and vote update immediately, active queries refetch to the same values, and inactive showcases queries are invalidated.
  • Doc feedback note create, edit, collapse/expand, and delete (DocFeedbackProvider, DocFeedbackNote): optimistic updates apply, server results persist after refetch, and the deleted note is also gone from /account/notes.

Not checked

  • Rollback when a mutation fails, since the real server can't be made to fail on demand.
  • Moderation approve / deny, featured toggle, admin delete, and admin npm stats refresh (admin-only).
  • Account submissions delete.

Summary by CodeRabbit

  • Refactor
    • Updated documentation, feedback, showcase, statistics, user, and role data loading to use consistent shared query and mutation definitions.
    • Existing filters, pagination, cache behavior, and displayed content remain unchanged.
  • Tests
    • Updated documentation manifest cache tests to use the current query definitions.

… and 'xxxMutations' factories like the Query React examples
@sukvvon
sukvvon requested a review from a team November 25, 2026 08:35
@sukvvon sukvvon self-assigned this Nov 25, 2026
@changeset-bot

changeset-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: e4df06a

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.

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

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Query and mutation option builders are consolidated into domain-specific collections. Components, routes, documentation utilities, and a cache test are updated to use the collections. Existing request parameters and query behavior are retained in the described migrations.

Changes: Query and mutation collection migration

Layer / File(s) Summary
Doc feedback queries and mutations
src/queries/docFeedback.ts, src/components/DocFeedback*.tsx, src/components/Feedback*.tsx, src/components/NotesModerationPage.tsx, src/routes/account/{feedback,notes}.tsx, src/routes/admin/feedback*.tsx, src/routes/admin/notes.index.tsx, src/routes/feedback-leaderboard.tsx
Feedback query and mutation options are grouped in shared collections. Components and routes use the collections for queries, mutations, and cache invalidation.
Showcase queries and mutations
src/queries/showcases.ts, src/components/Showcase*.tsx, src/routes/showcase/*, src/routes/community-projects.tsx, src/routes/account/submissions.tsx, src/routes/admin/showcases*.tsx
Showcase query and mutation options move into shared collections. Components and routes use their query options and keys, including for optimistic vote updates and invalidation.
Intent query collection
src/queries/intent.ts, src/components/intent/SkillDiffViewer.tsx, src/routes/intent/registry/*
Intent query option builders are grouped in intentQueries. Registry routes and the skill diff viewer use the collection.
Statistics query collection
src/queries/stats.ts, src/components/OpenSourceStats.tsx, src/components/landing/LibraryLanding.tsx, src/components/npm-stats/NPMSummary.tsx, src/routes/-library-landing-route.tsx, src/routes/index.tsx, src/routes/admin/npm-stats.tsx
Statistics query options move into statsQueries. Components and routes use it for summary and recent-download queries, and the admin route uses its query keys for invalidation.
Documentation query collections
src/queries/docsConfig.ts, src/queries/docsManifest.ts, src/routes/_library/*, src/utils/docs.ts, tests/docs-manifest-cache.test.ts
Documentation config and manifest query options move into named collections. Loaders, utilities, and cache tests use the new methods.
User and role query collections
src/queries/users.ts, src/queries/roles.ts, src/routes/admin/users.tsx
User and role query option functions are grouped into usersQueries and rolesQueries. The admin users route uses the new factories.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Suggested reviewers: tannerlinsley, ladybluenotes

Merge Risk: Minimal · up to e4df0

This refactor groups query and mutation options into domain factories without changing behavior, so there is no concrete merge-blocking risk. The usual type check and unit tests should still run before merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: query and mutation options are grouped into 'xxxQueries' and 'xxxMutations' factories in src/queries, which matches the changeset. The title follows the conventional c…
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.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the main change: query and mutation options are grouped into 'xxxQueries' and 'xxxMutations' factories in src/queries, which matches the changeset. The title follows the conventional commit prefix 'refactor(queries):' and is specific enough for a teammate scanning history. It is long (128 characters), but it is not vague or off-topic.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 78412e77-c813-472b-b0a2-fc8bfebec6b0
Commits

Reviewing files that changed from the base of the PR and between 7169840 and e4df06a.

Files selected for processing: 46

  • src/components/DocFeedbackNote.tsx
  • src/components/DocFeedbackProvider.tsx
  • src/components/FeedbackLeaderboard.tsx
  • src/components/FeedbackModerationPage.tsx
  • src/components/NotesModerationPage.tsx
  • src/components/OpenSourceStats.tsx
  • src/components/ShowcaseDetail.tsx
  • src/components/ShowcaseGallery.tsx
  • src/components/ShowcaseModerationPage.tsx
  • src/components/ShowcaseSection.tsx
  • src/components/intent/SkillDiffViewer.tsx
  • src/components/landing/LibraryLanding.tsx
  • src/components/npm-stats/NPMSummary.tsx
  • src/queries/docFeedback.ts
  • src/queries/docsConfig.ts
  • src/queries/docsManifest.ts
  • src/queries/intent.ts
  • src/queries/roles.ts
  • src/queries/showcases.ts
  • src/queries/stats.ts
  • src/queries/users.ts
  • src/routes/-library-landing-route.tsx
  • src/routes/_library/$libraryId/$version.tsx
  • src/routes/_library/charts.catalog.tsx
  • src/routes/_library/highlight.$version.theme-editor.tsx
  • src/routes/account/feedback.tsx
  • src/routes/account/notes.tsx
  • src/routes/account/submissions.tsx
  • src/routes/admin/feedback.index.tsx
  • src/routes/admin/feedback_.$id.tsx
  • src/routes/admin/notes.index.tsx
  • src/routes/admin/npm-stats.tsx
  • src/routes/admin/showcases.index.tsx
  • src/routes/admin/showcases_.$id.tsx
  • src/routes/admin/users.tsx
  • src/routes/community-projects.tsx
  • src/routes/feedback-leaderboard.tsx
  • src/routes/index.tsx
  • src/routes/intent/registry/$packageName.$skillName.tsx
  • src/routes/intent/registry/$packageName.index.tsx
  • src/routes/intent/registry/$packageName.tsx
  • src/routes/intent/registry/index.tsx
  • src/routes/showcase/$id.tsx
  • src/routes/showcase/index.tsx
  • src/utils/docs.ts
  • tests/docs-manifest-cache.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
tanstack-com e4df06a Commit Preview URL

Branch Preview URL
Nov 25 2026, 08:37 AM

@github-actions

Copy link
Copy Markdown
Asset Main PR merge build Change
JavaScript 19580.91 KiB 19582.04 KiB 🔴 +1.14 KiB (+0.01%)
JavaScript (gzip) 6443.54 KiB 6444.78 KiB 🔴 +1.23 KiB (+0.02%)
CSS 823.32 KiB 823.32 KiB 0.00 KiB (0.00%)
CSS (gzip) 126.01 KiB 126.01 KiB 0.00 KiB (0.00%)
Page Main (gzip) PR merge build (gzip) Change
/ 595.03 KiB 595.11 KiB 🔴 +0.08 KiB (+0.01%)
/libraries 537.89 KiB 537.94 KiB 🔴 +0.04 KiB (+0.01%)
/start/latest 562.68 KiB 562.76 KiB 🔴 +0.08 KiB (+0.01%)
/router/latest 562.98 KiB 563.06 KiB 🔴 +0.08 KiB (+0.01%)
/query/latest 561.43 KiB 561.50 KiB 🔴 +0.07 KiB (+0.01%)
/table/latest 594.24 KiB 594.31 KiB 🔴 +0.07 KiB (+0.01%)
/charts/latest 643.54 KiB 643.60 KiB 🔴 +0.06 KiB (+0.01%)
/ai/latest 588.36 KiB 588.45 KiB 🔴 +0.09 KiB (+0.02%)
Docs article 548.95 KiB 549.02 KiB 🔴 +0.07 KiB (+0.01%)
Framework docs article 548.96 KiB 549.03 KiB 🔴 +0.07 KiB (+0.01%)
/blog 542.10 KiB 542.16 KiB 🔴 +0.06 KiB (+0.01%)
/maintainers 541.20 KiB 541.25 KiB 🔴 +0.05 KiB (+0.01%)
/showcase 539.15 KiB 539.33 KiB 🔴 +0.18 KiB (+0.03%)
/chat 537.63 KiB 537.68 KiB 🔴 +0.05 KiB (+0.01%)
/chat/c/:conversationId 538.35 KiB 538.39 KiB 🔴 +0.04 KiB (+0.01%)

Page sizes sum the JS and CSS in the TanStack Start manifest for each route and its layouts. Shared files count once per page.

Compared with main at 7169840. Gzip sizes are summed per file. Build run

@tannerlinsley

Copy link
Copy Markdown
Member

Thanks for spelling out the sign-in limitation. The source review hasn't turned up a regression. Can you add focused coverage for the mutation call sites and their cache updates so the authenticated paths aren't left entirely to manual checks?

AI review notes:
Reviewed all 46 changed files at e4df06afc89a3219b01d7d4d26baa921d00fd499. An isolated comparison passed 30 query-builder cases against 7169840796df0968f6d1d7cd0cea3624fb77c1dc, plus the showcase vote argument wrapper. A deliberately incorrect query key failed the comparison as expected.
Those checks use stubbed server functions. They do not exercise React interactions, optimistic updates, rollback, invalidation after mutations, or authenticated server behavior. The source review found the existing callbacks and invalidation prefixes preserved, including the moderation vote call's new argument shape.
Useful focused coverage would exercise the vote caller and its optimistic update/rollback, feedback mutations and invalidation, and account deletion or moderation success invalidation with mocked server calls. This is requested coverage, not a claim that those interaction tests have run. All 11 reported checks currently pass; required maintainer review is still outstanding.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants