Skip to content

Bug in TimelineComponent #9

@ghost

Description

TimelineComponent currently assumes that when it asks its target for a range of content, the union of its current range and the additional range is equal to the range represented by its contents.

This is not necessarily the case.

Consider the following scenario. As defined in the Makestagram tutorial, the timeline table view has a default range of [0, 5). If the user has, say, 3 posts, then after loading is complete, the timeline component's currentRange is [0, 5), but the contents array represents the range [0, 3). Suppose the user then uploads a series of posts, such that they now have 6 posts. They then scroll to the bottom of the list.

A bug manifests when we call targetWillDisplayEntry. It determines whether it should load more content by comparing the last index of the current range with the index of the entry being displayed. However, if the index of the last element in the contents array is less than the last index in the current range, no additional data will ever be loaded.

This could superficially be fixed by adding a condition such as || entryIndex == self.content.count - 1 inside targetWillDisplayEntry, which will cause the component to attempt to load more content if the entry being displayed is the last in the contents array despite the fact that its index doesn't match the last index in currentRange.

This could be fixed in a deeper way by more carefully maintaining the invariant that the length of the current range is always the same as the length of the contents array. After all, if both supposedly represent the same contiguous range of content, this is probably a desirable invariant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions