-
Notifications
You must be signed in to change notification settings - Fork 161
Deprecate magic return APIs from collection handlers #843
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
Open
KyleAMathews
wants to merge
16
commits into
main
Choose a base branch
from
claude/fix-mutation-callbacks-01HTYzMduGUSY1Dvt3B7YBEa
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5ac7f31
deprecate: handler return values in favor of manual refetch/sync
claude e5239fe
docs: update collection options creator guide for deprecated return v…
claude b0e3dd4
deprecate: remove ALL magic return values, including Electric's txid …
claude b5f7e38
docs: remove redundant 'manually' wording from mutation handler docum…
claude 9eaee4a
chore: add changeset for mutation handler deprecation
claude 7f36cbc
feat: add runtime deprecation warnings for handler return values
claude 8d9f691
Prettier
kevin-dp c53c232
ci: apply automated fixes
autofix-ci[bot] 2716d59
feat: improve deprecation annotations for mutation handlers
github-actions[bot] 46b052f
docs: update examples to use new explicit sync pattern instead of dep…
github-actions[bot] 64ba501
docs: fix timeout documentation and increase awaitTxId default to 15s
KyleAMathews bbd00ac
ci: apply automated fixes
autofix-ci[bot] 5d564f7
feat: add warnOnce utility and improve deprecation warnings
KyleAMathews 7b1aa37
ci: apply automated fixes
autofix-ci[bot] 0d7d054
Merge remote-tracking branch 'origin/main' into claude/fix-mutation-c…
KyleAMathews d0b2c41
refactor: simplify code and fix review issues
KyleAMathews File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| --- | ||
| '@tanstack/db': major | ||
| '@tanstack/electric-db-collection': major | ||
| '@tanstack/query-db-collection': major | ||
| --- | ||
|
|
||
| **BREAKING (TypeScript only)**: Deprecate returning values from mutation handlers (`onInsert`, `onUpdate`, `onDelete`). | ||
|
|
||
| **What's changed:** | ||
|
|
||
| - Handler types now default to `Promise<void>` instead of `Promise<any>` | ||
| - TypeScript will error on `return { refetch: false }` or `return { txid }` | ||
| - Runtime still supports old return patterns for backward compatibility | ||
| - **Deprecation warnings** are now logged when handlers return values | ||
| - Old patterns will be fully removed in v1.0 RC | ||
|
|
||
| **New pattern (explicit sync coordination):** | ||
|
|
||
| - **Query Collections**: Call `await collection.utils.refetch()` to sync server state | ||
| - **Electric Collections**: Call `await collection.utils.awaitTxId(txid)` or `await collection.utils.awaitMatch(fn)` to wait for synchronization | ||
| - **Other Collections**: Use appropriate sync utilities for your collection type | ||
|
|
||
| This change makes the API more explicit and consistent across all collection types. All handlers should coordinate sync explicitly within the handler function using `await`, rather than relying on magic return values. | ||
|
|
||
| Migration guide: | ||
|
|
||
| ```typescript | ||
| // Before (Query Collection) | ||
| onInsert: async ({ transaction }) => { | ||
| await api.create(transaction.mutations[0].modified) | ||
| // Implicitly refetches | ||
| } | ||
|
|
||
| // After (Query Collection) | ||
| onInsert: async ({ transaction, collection }) => { | ||
| await api.create(transaction.mutations[0].modified) | ||
| await collection.utils.refetch() | ||
| } | ||
|
|
||
| // Before (Electric Collection) | ||
| onInsert: async ({ transaction }) => { | ||
| const result = await api.create(transaction.mutations[0].modified) | ||
| return { txid: result.txid } | ||
| } | ||
|
|
||
| // After (Electric Collection) | ||
| onInsert: async ({ transaction, collection }) => { | ||
| const result = await api.create(transaction.mutations[0].modified) | ||
| await collection.utils.awaitTxId(result.txid) | ||
| } | ||
| ``` | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
@claude make these minor — we're < 1.0
Uh oh!
There was an error while loading. Please reload this page.
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.
Claude finished @KyleAMathews's task in 1m 52s —— View job
Changeset updated to use minor versions
I've updated the changeset file locally to change version bumps from
majortominorfor all three packages since the project is < 1.0:@tanstack/db: major → minor@tanstack/electric-db-collection: major → minor@tanstack/query-db-collection: minor → minorStatus: The change is committed locally but cannot be pushed automatically due to concurrent changes on the remote branch (likely from another Claude instance addressing Kevin's deprecation comment).
Next steps: You'll need to either:
.changeset/deprecate-handler-return-values.md(lines 2-4: changemajortominor)Local commit:
ad9f319a - chore: change version bumps from major to minor (< 1.0)