Page MenuHomePhabricator

Image Browsing: Add basic support for history navigation
Closed, ResolvedPublic3 Estimated Story Points

Description

Note: if this is considered out of scope for the prototype, this task can be declined

Overview

We may want to introduce support for basic history navigation for the Image Browsing feature. Consider the use-case of someone skimming an article via the Visual TOC component. Once they click a "view in article" button here, the overlay will close and they'll be scrolled down on the page to wherever the given image is embedded.

Once a user does this, there is no way for them to easily get back to the previous state. If they click the relevant image in the article text that they just scrolled to, that will launch the traditional MediaViewer UI (not our new ImageBrowsing prototype). And if a user clicks the "back" button to try to restore where they just were (something which does work in MMV), they will be dumped on whatever previous web page they were looking at prior to landing on the current Wiki article.

Users may find this jarring or frustrating. Any intra-article navigation using the VTOC is a one-way trip.

A production version of this feature would implement support for URL fragments and history navigation. In this hypothetical scenario, launching the image browser would add a URL fragment to the page URL and would be recorded as a history entry. Changing the image in the detail view would probably update that URL fragment and add a new history entry; closing the image browsing overlay would remove the url fragment, and using the "forward" and "backwards" controls built into most Web browsers would allow users to move back and forth between previous UI states. Pasting an appropriate URL fragment into the browser's address bar would immediately trigger the UI in its appropriate state.

MVP scope

Doing all of the above is likely out-of-scope for our initial prototype. However, we may find it beneficial to the experience of users (even during early testing) to add some basic support for history navigation, without also introducing URL fragments for now.

This would mean that users who navigated to a specific part of the article page by clicking "view in article" in the VTOC would gain the ability to go back to where they were via the browser's "Back" button.

The simplest possible approach here would involve only adding a single entry to the browser history when the Image Browsing UI is opened, as well as another new one when it is closed. If desired, each update to the Detail View image could also be treated as a new history entry. No URLs would change, but using the forwards / backwards buttons would allow the user to move between history entries (however many we decide to define here).

Requirements

Assuming we want to support some basic version of this feature now, here are the requirements:

  • Opening the Image Browsing UI (by clicking on a Carousel image) should cause an entry to be added to the Browser History via history.pushState. Key parts of UI state like the current active image should be serialized and stored as part of the state object this method receives as an argument.
    • Optional Each update to the Detail View image should also be stored this way if we wish to record changes here
  • Closing the Image Browsing UI should also be recorded as a history entry
  • When the user leaves the page entirely, the state should be stashed in LocalStorage so that backwards-navigation from elsewhere will restore the appropriate state of the Image Browsing UI
  • Event listeners for popstate and pagehide events should be added (likely in the top-level App component)
  • When the app first initalizes, it should check for prior history state that needs to be restored and handle it accordingly

Note: The code here could likely be adapted quickly as a starting point

QA
  1. Navigate to an article page where the Image Browsing feature shows up
  2. Trigger the UI (and change the detail view a few times if we are recording that event), and then:
    • Navigate to other parts of the article (using the VTOC "view in article" buttons), then hit "Back" to ensure the previous UI state restores successfully
    • Navigate to a new page entirely (by clicking a link in caption or paragraph text) and then click "back" to return to this article page; confirm that the previous UI state restores successfully
    • Move backwards and forwards through browser history in various ways and ensure the UI always restores itself successfully

BDD

Feature: Basic history navigation for Image Browsing

  Scenario: Opening and closing Image Browsing UI
    Given I am on an article with Image Browsing enabled
    When I open the Image Browsing UI from a carousel image
    Then a browser history entry is added with current UI state
    When I close the Image Browsing UI
    Then another browser history entry is added

  Scenario: Navigating inside article and back
    Given I have opened the Image Browsing UI and changed images
    When I click a VTOC “view in article” button
    And I press the browser Back button
    Then the previous Image Browsing UI state is restored

  Scenario: Navigating to a different page and back
    Given I have opened the Image Browsing UI
    When I click a link to navigate to a different article
    And I press the browser Back button
    Then the previous Image Browsing UI state is restored

  Scenario: Browser history navigation
    Given I have opened the Image Browsing UI and changed images multiple times
    When I move backwards and forwards using the browser history buttons
    Then the Image Browsing UI restores the correct state for each entry

Test Steps

Test Case 1: History entry on open/close

  1. Open https://30eaa87caa.catalyst.wmcloud.org/wiki/Paris.
  2. Click a carousel image to open Image Browsing UI.
  3. AC1: A history entry is added.
  4. Close the Image Browsing UI.
  5. AC2: Another history entry is added.

Test Case 2: Navigate inside article and back

  1. Open Image Browsing UI and navigate between detail images.
  2. Click a “view in article” button in the VTOC.
  3. Press browser Back.
  4. AC3: The Image Browsing UI reopens with the same image shown as before.

Test Case 3: Navigate to new page and back

  1. With Image Browsing UI open, click a text link to another article.
  2. Press browser Back.
  3. AC4: The Image Browsing UI reopens in the same state as before navigation.

Test Case 4: Move through history entries

  1. Open Image Browsing UI and switch between several images if supported.
  2. Use the browser Back and Forward buttons.
  3. AC5: The UI restores to the correct state at each history step (open/closed and image selection).

QA Results - Patchdemo

Event Timeline

HSwan-WMF moved this task from Incoming/Inbox to Needs Refinement on the Reader Growth Team board.
ovasileva lowered the priority of this task from High to Medium.Sep 15 2025, 3:58 PM
ovasileva set the point value for this task to 3.Sep 15 2025, 5:12 PM
ovasileva raised the priority of this task from Medium to High.Sep 16 2025, 4:53 PM

Change #1189497 had a related patch set uploaded (by Matthias Mullie; author: Matthias Mullie):

[mediawiki/extensions/ReaderExperiments@master] Add router/history navigation

https://gerrit.wikimedia.org/r/1189497

Test wiki created on Patch demo by Mmullie (WMF) using patch(es) linked to this task:
https://561a5d5247.catalyst.wmcloud.org/w/

Change #1189497 merged by jenkins-bot:

[mediawiki/extensions/ReaderExperiments@master] Add router/history navigation

https://gerrit.wikimedia.org/r/1189497

This patch is ready for QA, but I'm getting errors when attempting to create a patchdemo instance (Could not update repository mediawiki/services/parsoid, for example).

I'll try again later today or Monday, or someone else can attempt and see if they get better results.

This patchdemo instance can be used to QA (I was able to successfully create one using the Catalyst backend, which is supported again):

https://30eaa87caa.catalyst.wmcloud.org/wiki/Paris

Edtadros subscribed.

Test Result - Patchdemo

Status: ✅ PASS
Environment: PatchDemo: https://30eaa87caa.catalyst.wmcloud.org
OS: macOS Sequoia 15.5
Browser: Chrome Canary (latest as of test date)
Device: MS
Emulated Device: NA

Test Case 1: History entry on open/close

  1. Open https://30eaa87caa.catalyst.wmcloud.org/wiki/Paris.
  2. Click a carousel image to open Image Browsing UI.
  3. AC1: A history entry is added
  4. Close the Image Browsing UI.
  5. AC2: Another history entry is added.

screenshot 49.mov.gif (1×1 px, 2 MB)

Test Case 2: Navigate inside article and back

  1. Open Image Browsing UI and navigate between detail images.
  2. Click a “view in article” button in the VTOC.
  3. Press browser Back.
  4. AC3: The Image Browsing UI reopens with the same image shown as before.

screenshot 50.mov.gif (1×1 px, 3 MB)

Test Case 3: Navigate to new page and back

  1. With Image Browsing UI open, click a text link to another article.
  2. Press browser Back.
  3. AC4: The Image Browsing UI reopens in the same state as before navigation.

screenshot 51.mov.gif (1×1 px, 3 MB)

Test Case 4: Move through history entries

  1. Open Image Browsing UI and switch between several images if supported.
  2. Use the browser Back and Forward buttons.
  3. AC5: The UI restores to the correct state at each history step (open/closed and image selection).

screenshot 53.mov.gif (1×1 px, 2 MB)

Looks good, resolving!

Test wiki on Patch demo by Mmullie (WMF) using patch(es) linked to this task was deleted:

https://561a5d5247.catalyst.wmcloud.org/w/