Description
Consumer UIs built on the SDK must re-fetch state after every mutation, causing visible flicker. This issue introduces an OptimisticCache that applies a predicted outcome to cached Invoice and Payment objects immediately upon submission, then either confirms or rolls back the prediction based on the settled transaction result. The cache integrates with the existing fetch methods in SplitClient so that reads during a pending transaction return the optimistic version.
Technical Context
- New file:
src/cache/OptimisticCache.ts; extends the internal ResponseCache already used by SplitClient
OptimisticCache.applyOptimistic(key, predictedValue, rollbackValue) stores both values and returns a commit() / rollback() function pair
SplitClient passes the pair into the transaction lifecycle hooks (onSettled, onFailed) from the retry policy
- The cache must be keyed by a composite of
(invoiceId, version) to avoid stale reads across concurrent mutations
- Expose
cache.pendingCount and cache.onRollback(handler) for UI integration
Acceptance Criteria
Description
Consumer UIs built on the SDK must re-fetch state after every mutation, causing visible flicker. This issue introduces an
OptimisticCachethat applies a predicted outcome to cachedInvoiceandPaymentobjects immediately upon submission, then either confirms or rolls back the prediction based on the settled transaction result. The cache integrates with the existing fetch methods inSplitClientso that reads during a pending transaction return the optimistic version.Technical Context
src/cache/OptimisticCache.ts; extends the internalResponseCachealready used bySplitClientOptimisticCache.applyOptimistic(key, predictedValue, rollbackValue)stores both values and returns acommit()/rollback()function pairSplitClientpasses the pair into the transaction lifecycle hooks (onSettled,onFailed) from the retry policy(invoiceId, version)to avoid stale reads across concurrent mutationscache.pendingCountandcache.onRollback(handler)for UI integrationAcceptance Criteria
applyOptimistic(), reads for the same key return the predicted value untilcommit()orrollback()is calledrollback()restores the previous value, emits anonRollbackevent, and leaves no stale optimistic entriesOptimisticCacheis exported from the package index and documented with JSDoc types