[SOLVED] Double replay of offline transactions on initialization
In OfflineExecutor.ts:initialize():
https://github.com/TanStack/db/blob/main/packages/offline-transactions/src/OfflineExecutor.ts
The problem:
1. requestLeadership() launches lock acquisition but returns immediately before the lock is actually acquired
2. setupEventListeners() registers the onLeadershipChange callback
3. First replay: Manual call at line 274 (inside the if block)
4. A few milliseconds later: lock acquired → notifyLeadershipChange(true) fires
5. Second replay: Callback executes loadAndReplayTransactions() again
In the console, I can see duplicate calls of the mutations with the same idempotencyKey.
Potential fix:
Remove the manual replay:
Keep only setupEventListeners(), which might be sufficient since loadAndReplayTransactions() is automatically called when leadership is acquired through the callback.
What do you guys think?