(feat): Added optional lock context for diff trigger creation and disposal#888
Merged
Chriztiaan merged 3 commits intomainfrom Mar 12, 2026
Merged
(feat): Added optional lock context for diff trigger creation and disposal#888Chriztiaan merged 3 commits intomainfrom
Chriztiaan merged 3 commits intomainfrom
Conversation
…ntext to the cleanup function returned by createDiffTrigger, this allows you to dispose and recreate a diffTrigger inside a single writeLock.
🦋 Changeset detectedLatest commit: fcc7bf1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 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 |
stevensJourney
approved these changes
Mar 11, 2026
Collaborator
stevensJourney
left a comment
There was a problem hiding this comment.
The changes here make sense and look good to me.
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.
For the query-driven sync implementation of powersync-ja/temp-tanstack-db#6, we need to recreate the diff trigger as the live queries clause set changes. Recreation involves disposing the current trigger and calling create again with the new new clause set. During testing of this feature we found edge cases where if mutations against the TanstackDB collection were still pending when we called dispose+create the mutations would be dropped.
The simplest approach to fixing this is to flush the data and then dispose and recreate the trigger- all during a single write lock. Diff triggers currently do not work inside a write lock and don't accept a lock option.
To support this work, this PR updates the diff trigger and cleanup callback to take in an optional lock context which is used instead of the db reference when provided.
For the TanstackDB PR it changed the usage from:
to
Alternative
An alternative solution which worked to an extent was #881, which put full control of the diff trigger's life cycle in the user's hands. While useful, it does complicate the API and would need some more work to be able to work in a multiple tab scenario.