Skip to content
Source
Sign inSign up
TanStack/db

fix(trailbase-db-collection): handle 403 on subscribe/* with polling fallback #1521

Closedroyalcala(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/1521/headopened

Showing 1 changed file with 37 additions and 19 deletions.

x
0 of 1 viewed, 1 left
37 additions and 19 deletionspackages/trailbase-db-collection/src/trailbase.tsModified
View file
@@ -140,6 +140,12 @@
​
const internalSyncMode = config.syncMode ?? `eager`
let fullSyncCompleted = false
+ // Tracks whether subscribe("*") succeeded. Set to true inside start() when SSE
+ // connects. When false (e.g. 403 due to row-level access rules that can't be
+ // evaluated at wildcard subscription time), onInsert/onUpdate/onDelete skip
+ // awaitIds() — which relies on SSE events to populate seenIds — to avoid a
+ // 120 s timeout that would roll back every optimistic mutation.
+ let sseAvailable = false
​
const awaitIds = (
ids: Array<string>,
@@ -294,12 +300,25 @@
​
async function start() {
- const eventStream = await config.recordApi.subscribe(`*`)
- const reader = (eventReader = eventStream.getReader())
+ // Attempt to subscribe to live updates. Some TrailBase configurations
+ // deny wildcard subscriptions (403) when table access rules use
+ // row-level predicates (_ROW_.*) that can't be evaluated without a
+ // concrete record. In that case we fall back to polling only.
+ let liveUpdatesAvailable = false
+ try {