Skip to content

lightbox: Fix Hero when multiple images in one message have same URL #44

@chrisbobbe

Description

@chrisbobbe

When you tap an image preview in a message, the Hero animation needs a "tag" that uniquely identifies the image on the route (i.e., among all other images in the message list).

Currently, _LightboxHeroTag fails to uniquely identify an image when there are multiple image previews with the same URL in a message. The effect is that there is no Hero animation, and an error is logged to the console:

======== Exception caught by scheduler library =====================================================
The following assertion was thrown during a scheduler callback:
There are multiple heroes that share the same tag within a subtree.

Within each subtree for which heroes are to be animated (i.e. a PageRoute subtree), each Hero must have a unique non-null tag.
In this case, multiple heroes had the following tag: […]

The bug is a bit tricky to reproduce: the open-lightbox-on-tap handler is on the image preview widget itself, not on the image link text, and (empirically) servers try to deduplicate image previews in a message with the same URL. Try something like this to thwart that deduplication:

[image](/user_uploads/2/fd/AogAK3meEt4GkXJaDvDXNwyy/image.png)
[image](https://chat.zulip.org/user_uploads/2/fd/AogAK3meEt4GkXJaDvDXNwyy/image.png)

This TODO on _LightboxHeroTag gives a recipe for a potential fix:

// TODO: Add index of the image preview in the message, to not break if
//   there are multiple image previews with the same URL in the same
//   message. Maybe keep `src`, so that on exit the lightbox image doesn't
//   fly to an image preview with a different URL, following a message edit
//   while the lightbox was open.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a-lightboxThe lightbox / image-viewer screen

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions