perf(plugin-react-query): dispatch operations to one matching generator family - #728
Closed
stijnvanhulle wants to merge 3 commits into
Closed
perf(plugin-react-query): dispatch operations to one matching generator family#728stijnvanhulle wants to merge 3 commits into
stijnvanhulle wants to merge 3 commits into
Conversation
…or family Classifies each operation as query or mutation once via a new operationGenerator, then calls only the matching hook generators, instead of registering all five (query, suspenseQuery, infiniteQuery, suspenseInfiniteQuery, mutation) as separate core generators that each run for every operation with four returning early. Fixes kubb-labs/kubb#3816. Generated output is unchanged (snapshot parity verified via tests/3.0.x/pluginReactQuery.test.ts). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LnAWjXX2zoWWScgn7NsLaf
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
🦋 Changeset detectedLatest commit: 1b86e09 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
Contributor
|
Size Change: +2.09 kB (+0.71%) Total Size: 296 kB 📦 View Changed
ℹ️ View Unchanged
|
More templates
@kubb/plugin-axios
@kubb/plugin-cypress
@kubb/plugin-faker
@kubb/plugin-fetch
@kubb/plugin-mcp
@kubb/plugin-msw
@kubb/plugin-react-query
@kubb/plugin-redoc
@kubb/plugin-swr
@kubb/plugin-ts
@kubb/plugin-vue-query
@kubb/plugin-zod
commit: |
Fold the query/mutation classification and dispatch directly into plugin.ts instead of a separate generator file, so this PR doesn't add net-new files on top of the five existing generators. Each matching generator's JSX result is rendered and upserted directly (no `renderer` needed on the dispatcher), so plugin.ts stays plain TypeScript like every other plugin's entry file. Coverage now relies on the existing per-generator unit tests plus the tests/3.0.x/pluginReactQuery.test.ts snapshot suite, which still passes unchanged. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LnAWjXX2zoWWScgn7NsLaf
…/tanstack-query Move the query/mutation classify-and-dispatch generator into @internals/tanstack-query as createOperationDispatcher, next to the classifyOperation it's built on, instead of duplicating it inline in plugin-react-query's plugin.ts. Other TanStack-family plugins (vue-query, swr) have the same query/mutation config shape and can reuse it later. plugin.ts now just builds the query and mutation generator lists and passes them to the shared factory. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LnAWjXX2zoWWScgn7NsLaf
This was referenced Jul 18, 2026
stijnvanhulle
added a commit
to kubb-labs/kubb
that referenced
this pull request
Jul 18, 2026
#3828) * feat(core): add a match predicate to Generator Add an optional match(node, ctx) => boolean to Generator, checked by KubbDriver#runGenerators before calling schema/operation. A generator whose match resolves false is skipped for that node entirely, with no extra context work and no render call. Omitting match keeps today's behavior of always running, so this is purely additive. renderGeneratorSchema/renderGeneratorOperation in mocks.ts honor match too, so a generator's own unit tests exercise the same skip behavior as real dispatch. This replaces the need for a plugin to hand-roll its own dispatcher when several of its generators only apply to a subset of nodes each, as plugin-react-query's createOperationDispatcher does today in kubb-labs/plugins#728. Fixes #3826. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LnAWjXX2zoWWScgn7NsLaf * refactor(ast,core): rename Macro's when gate to match, and clean up await checks Macro.when hasn't shipped yet (still part of the pending, unreleased macro-ast-transform-layer changeset), so rename it to match for consistency with the new Generator.match predicate added in the previous commit — same concept, same name, across both abstractions. Also extract the await out of the compound if conditions in KubbDriver#runGenerators and the mocks.ts test helpers into a plain matches variable first, for readability. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LnAWjXX2zoWWScgn7NsLaf * docs: tighten the match predicate changeset Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LnAWjXX2zoWWScgn7NsLaf --------- Co-authored-by: Claude <noreply@anthropic.com>
stijnvanhulle
added a commit
that referenced
this pull request
Jul 18, 2026
…d of the dispatcher (#730) * refactor(plugin-react-query): use the new core match predicate instead of the dispatcher Give each of the five hook generators a match predicate instead of classifying and bailing out inside operation(). This is what createOperationDispatcher (added in #728 to fix kubb-labs/kubb#3816) was working around: @kubb/core's Generator now supports match natively, so the core driver skips a non-matching generator before calling it and plugin.ts goes back to registering the five generators directly. Generated output is unchanged (verified against tests/3.0.x/pluginReactQuery.test.ts's 11-config snapshot suite, run locally against a kubb build linked from ../kubb via pnpm-workspace.yaml's commented-out overrides). Requires kubb-labs/kubb#3828 to merge and release before this is mergeable: without match support in the driver, these generators would run unconditionally for every operation, since the old classify-and-bail guards were moved into match. Do not merge until the kubb catalog version here is bumped past that release. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LnAWjXX2zoWWScgn7NsLaf * docs: tighten the match predicate changeset Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LnAWjXX2zoWWScgn7NsLaf * chore: bump kubb catalog to 5.0.0-beta.104 and simplify match predicates The published beta.104 carries the match predicate support this branch depends on. Simplify each generator's match to narrow SchemaNode | OperationNode via a single cast plus isHttpOperationNode instead of a node.kind string check, and drop the queryParam regex normalization in favor of a plain includes() check against both the plain and optional key. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LnAWjXX2zoWWScgn7NsLaf --------- Co-authored-by: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Changes
Every operation used to run through all five
plugin-react-queryoperation generators (query,suspenseQuery,infiniteQuery,suspenseInfiniteQuery,mutation), each independently re-classifying the node and bailing out early when it didn't match. So a mutation likeaddPethit all five generators and four did nothing.This adds a new
operationGeneratorthat classifies each operation as query or mutation once (via the existingclassifyOperation), then calls only the generators for the matching family:mutationGeneratorqueryGenerator,suspenseQueryGenerator,infiniteQueryGenerator,suspenseInfiniteQueryGenerator(each still gated by its ownsuspense/infinite/hooksoptions, as before)plugin.tsnow registers this single dispatcher instead of the five generators directly, so the core AST walk invokes one operation generator per node instead of five. The individual generator files, their exports, and their existing unit tests are untouched.Generated output is unchanged:
tests/3.0.x/pluginReactQuery.test.ts's snapshot suite (11 configs covering suspense, infinite, custom query/mutation methods, groups, includes/excludes, etc.) passes without modification.Fixes kubb-labs/kubb#3816.
✅ Checklist
pnpm run test.🚀 Release Impact
Generated by Claude Code