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.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.
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.
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
- iOS
- Android
- React Native
boundary defaults to .unseen. The remaining cases are .afterCount(keepUpcoming:) and .afterItem(afterId:untilId:). The method is main-actor bound.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.- iOS
- Android
- React Native
Result fields
All fields describe the same splice. The example below runs one call and labels each field against it.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.
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.
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.
With a relative boundary this is your only record of where the cut landed.
Entries that survived ahead of the cut, meaning items 0 through 5 with the boundary included.
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.
Entries taken out of the replaced range: items 6, 7 and 8.
Compare against insertedCount to see whether the queue grew or shrank. Here it shrank by one.
How many of your items actually went in. You sent three; one was refused.
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.
The ids of the entries that left the queue. The named form of removedCount.
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.
Items you sent that never entered the queue. Nothing listed here was ever in the feed.
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.
How long the queue is now: six kept plus two inserted.
On a rejection this is 0, meaning unknown rather than empty, because the call was refused before the feed was consulted.
Entries ahead of the viewer once the splice has landed. This is the runway left before the feed needs more content.
Use it to decide whether to paginate. Same 0-means-unknown caveat as queueLength.
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
| Reason | Mode | Meaning |
|---|---|---|
feed_not_ready | any mode | The 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_current | afterItem or afterCount | From afterItem, the viewer moved past it. From afterCount, keepUpcoming was negative |
boundary_not_found | afterItem | afterId was not present in the queue when the boundary resolved |
until_not_found | afterItem | untilId was supplied but was not present in the queue |
until_not_after_boundary | afterItem | untilId resolved at or before afterId |
superseded | any mode | The queue was reset between the call and the apply |
invalid_items | any mode | React 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.