Skip to main content
replaceFeedItems replaces a trailing range of a custom feed queue. Items up to and including the boundary are preserved; everything after it is replaced. Use it to revise upcoming content while the feed is in use. Typical cases are applying updated recommendations, reflecting a user action, and correcting a ranking decision after playback has begun. To replace the whole queue, use setFeedItems. To add to the end, use appendFeedItems. This operation requires a custom feed. Set feedSource to custom first. See Configuration and Custom feed input.

Boundary resolution

A boundary identifies the last item to keep. Every call requires one. All three are resolved when the replacement is applied, against the queue and the viewer’s position as they stand at that moment. The difference is what each one is anchored to. unseen and afterCount are relative. They are recomputed from the viewer’s live position, so they follow the viewer. afterItem is absolute. You name an item before the call and the SDK locates it later.
Prefer a relative boundary when the viewer can move during the call.With afterItem you commit to a boundary before your network request and the SDK resolves it after. If the viewer scrolls past that item in the meantime, the boundary lands behind the item on screen and the call is rejected with boundary_behind_current. Honouring it would replace the video being watched. The rejection rate scales with round-trip time: frequent over mobile connections, rare over a local network, which makes it straightforward to miss during development.Use afterCount or unseen for interaction-triggered replacement. Use afterItem when the queue position cannot move during the request. A server-driven replacement, a paused feed and a backgrounded surface all qualify.
keepUpcoming counts entries in the queue, which is what itemIds lists. afterItem also accepts an optional untilId to bound the end of the range, replacing a window rather than the entire tail.
No boundary can replace the item on screen or anything before it: a replacement always keeps the queue up to at least the viewer’s current position.unseen keeps more than that. It anchors to the deepest item the viewer has reached, reported as deepestSeenItemId in the queue state. That marker only ever moves forward. Programmatic activation advances it too, so startAt and scrollToItem move it.The consequence shows up when the viewer scrolls back. unseen still preserves everything up to the deepest item they reached. afterCount and afterItem ignore that marker and are bounded only by the current item, so they can replace the stretch between the two.

Usage

RecommendationRefresh.swift
boundary defaults to .unseen. The remaining cases are .afterCount(keepUpcoming:) and .afterItem(afterId:untilId:). The method is main-actor bound.
Passing an empty items array is legal, and truncates the queue at the boundary. Give each item a stable id. Items are matched by id alone, so reusing an id for materially different content will not rebind the cell.

Queue state

Read the queue as it currently stands. The snapshot carries the ordered item ids, the current item, and the deepest item the viewer has reached. Use it to compute a boundary, or to reconcile the outcome of a call.

Result fields

All fields describe the same splice. The example below runs one call and labels each field against it.
before
012345678
you sent
n1n2n3
after
012345n1n2
keptremovedcurrent itemboundaryinserteddropped
A nine-item queue. The viewer is on item 3, the boundary resolved to item 5, and items 6 to 8 are replaced. You sent three items; one duplicated something already in the kept head.
status”applied”

Whether the splice happened. The value is always applied or rejected. There is no partial outcome.

A rejection leaves the queue unchanged. There is nothing to undo.

reasonabsent

Why it was refused. Present only when status is rejected.

Branch on this rather than on the counts: a rejection zeroes every count, so keptCount: 0 does not mean the queue is empty.

boundaryId”item-5”

The last item kept. With afterItem this echoes what you asked for. With unseen and afterCount it reports which item the SDK chose, which you had no way to know in advance.

012345678

With a relative boundary this is your only record of where the cut landed.

keptCount6

Entries that survived ahead of the cut, meaning items 0 through 5 with the boundary included.

012345678

With untilId this counts the head only. Items preserved beyond the far end of the range are excluded, so keptCount + removedCount will not equal the original length.

removedCount3

Entries taken out of the replaced range: items 6, 7 and 8.

012345678

Compare against insertedCount to see whether the queue grew or shrank. Here it shrank by one.

insertedCount2

How many of your items actually went in. You sent three; one was refused.

012345n1n2

When this is lower than what you sent, the difference is in droppedIds. Check it, because a silent shortfall is how a feed quietly thins.

removedIds[“item-6”,“item-7”,“item-8”]

The ids of the entries that left the queue. The named form of removedCount.

012345678

Use this to prune host-side state keyed by item id, such as cached metadata, like counts and analytics rows. Do not use droppedIds, which answers a different question.

droppedIds[“n3”]

Items you sent that never entered the queue. Nothing listed here was ever in the feed.

n1n2n3

An item is dropped when its id duplicates a kept item or an earlier item in the same batch, when its playback id duplicates a kept item’s, or when the viewer dismissed that video earlier in the session. Dismissal blocks the playback id too, so re-sending under a fresh id is still refused.

queueLength8

How long the queue is now: six kept plus two inserted.

012345n1n2

On a rejection this is 0, meaning unknown rather than empty, because the call was refused before the feed was consulted.

remainingCount4

Entries ahead of the viewer once the splice has landed. This is the runway left before the feed needs more content.

012345n1n2

Use it to decide whether to paginate. Same 0-means-unknown caveat as queueLength.

Dedup runs against the survivors, which are the kept head plus any tail preserved by untilId, and not against the range being replaced. An item you remove in the same call can therefore come straight back, which is what makes reordering a stretch of content possible.

Rejection reasons

ReasonModeMeaning
feed_not_readyany modeThe feed is not registered, is empty, is not a custom feed, its view was torn down, or the wait for the feed to settle was exhausted
boundary_behind_currentafterItem or afterCountFrom afterItem, the viewer moved past it. From afterCount, keepUpcoming was negative
boundary_not_foundafterItemafterId was not present in the queue when the boundary resolved
until_not_foundafterItemuntilId was supplied but was not present in the queue
until_not_after_boundaryafterItemuntilId resolved at or before afterId
supersededany modeThe queue was reset between the call and the apply
invalid_itemsany modeReact Native only. The items or options payload was malformed at the bridge
superseded warrants explicit handling. It indicates that the queue was replaced between the call and the apply, by a pull-to-refresh, a preload reseed, or your own setFeedItems. The replacement was discarded rather than applied to a queue that no longer existed. Re-read the queue state to determine whether the replacement remains appropriate. Retry behaviour differs by reason. A feed_not_ready from an exhausted settle wait, and a boundary_behind_current from an afterItem boundary, are both worth retrying. A boundary_behind_current from afterCount means keepUpcoming was negative, which is a static bug. Do not retry it.
Results differ if the surface is torn down during apply.If the feed is dismissed while a replacement is being applied, iOS resolves rejected with feed_not_ready, while Android resolves applied with the real counts. This is deliberate rather than a defect: on Android the change is applied and persists, on iOS it is not. Do not treat the two results as equivalent in this case; read the queue state to establish the outcome.