Skip to content

Commit 345bc5a

Browse files
committed
fix(webflow): set listingCapped on within-page maxItems truncation
When a collection's items fit in a single API page but maxItems cuts the list within that page, neither hasMoreInCollection nor hasMoreCollections is true, so listingCapped was not set and the sync engine could hard-delete still-existing documents. Add the within-page drop signal to the guard.
1 parent b8c1876 commit 345bc5a

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

apps/sim/connectors/webflow/webflow.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,13 @@ export const webflowConnector: ConnectorConfig = {
152152
}
153153

154154
const items = data.items || []
155-
let documents: ExternalDocument[] = items.map((item) =>
155+
const pageDocuments: ExternalDocument[] = items.map((item) =>
156156
itemToDocument(item, currentCollectionId, collectionName)
157157
)
158158

159+
let documents = pageDocuments
159160
if (maxItems > 0) {
160-
const remaining = maxItems - totalDocsFetched
161+
const remaining = Math.max(0, maxItems - totalDocsFetched)
161162
if (documents.length > remaining) {
162163
documents = documents.slice(0, remaining)
163164
}
@@ -171,8 +172,20 @@ export const webflowConnector: ConnectorConfig = {
171172
const hasMoreInCollection = cursorState.offset + pagination.limit < pagination.total
172173
const hasMoreCollections = cursorState.collectionIndex < cursorState.collections.length - 1
173174
const hitMaxItems = maxItems > 0 && totalDocsFetched + documents.length >= maxItems
174-
175-
if (hitMaxItems && (hasMoreInCollection || hasMoreCollections) && syncContext) {
175+
/**
176+
* When the cap stops the sync, flag the listing as capped so the sync engine
177+
* skips deletion reconciliation — otherwise still-existing documents that
178+
* were never listed get hard-deleted. "More" means any of: items dropped
179+
* from this page (`pageDocuments.length > documents.length`), more pages in
180+
* this collection, or more collections still to visit. The within-page drop
181+
* is the only signal when a collection fits in a single API response.
182+
*/
183+
const droppedWithinPage = documents.length < pageDocuments.length
184+
if (
185+
syncContext &&
186+
hitMaxItems &&
187+
(droppedWithinPage || hasMoreInCollection || hasMoreCollections)
188+
) {
176189
syncContext.listingCapped = true
177190
}
178191

0 commit comments

Comments
 (0)