Skip to content

AO3-6081 Add optional scroll history tracking#5641

Open
mjec wants to merge 13 commits intootwcode:masterfrom
mjec:AO3-6081_save_scroll_location
Open

AO3-6081 Add optional scroll history tracking#5641
mjec wants to merge 13 commits intootwcode:masterfrom
mjec:AO3-6081_save_scroll_location

Conversation

@mjec
Copy link

@mjec mjec commented Mar 16, 2026

Pull Request Checklist

Issue

https://otwarchive.atlassian.net/browse/AO3-6081

Purpose

Adds a scroll history tracking feature, restoring your last scroll position on reload.

Current features:

  • Gracefully degrades if features not available (localStorage, onscrollend event)
  • Automatically restores last known scroll position on page load
  • SCROLL_DISTANCE_MINIMUM_FOR_HISTORY sets minimum pixel length scrolled to record a history entry

Controlled by a dialog raised by a button next to the Comments button.

Code supports a more comprehensive back/forward, but that might be overkill and I'm not sure the right interface for it anyway (maybe history.pushState()?)

I don't have a lot of (any) experience with cucumber but I'll try to put together a test with that later if you'd like.

I'd of course squash these commits before merge, let me know if/when you want me to squash and force push.

Testing Instructions

Start the service and navigate to a work. Click on the "scroll history is off" button to open a dialog.

Your scroll state will then be automatically restored on a fresh page load, stored independently per page (by URL).

You can view the saved state in the page localStorage, and only your preference is stored if you opt out.

I have tested this on Firefox and Chrome on Windows only right now.

Credit

What name and pronouns should we use to credit you in the Archive of Our Own's Release Notes? mjec (they/them)

Current features:
* Gracefully degrades if features not available (localStorage,
  onscrollend event)
* Prompts for permission to store data
* Automatically restores last known scroll position on page load
* Stores last 20 scroll positions in localStorage, with functions to
  move back and forward
* `SCROLL_DISTANCE_MINIMUM_FOR_HISTORY` sets minimum pixel length
  scrolled to record a history entry

Things that still need work:
* Code is just kind of dropped in application.js
* Scroll history is enabled on every page, not just (e.g.) /works
* Lacks translations
* Prompt is very invasive - is there a better way?
* No UI to change preference (browser or user) - might be good to have
  a global disable user preference?
* No UI to delete history
* No UI to navigate through history

const scroll_history = getScrollHistory();
const previous_position = scroll_history.list[scroll_history.index];
const new_position = document.scrollingElement?.scrollTop ?? 0;

This comment was marked as resolved.

@mjec mjec marked this pull request as draft March 16, 2026 01:40
@mjec mjec marked this pull request as ready for review March 16, 2026 06:14
@mjec mjec changed the title AO3-6081 [WIP] Add optional scroll history tracking AO3-6081 Add optional scroll history tracking Mar 16, 2026
@Bilka2
Copy link
Contributor

Bilka2 commented Mar 16, 2026

Hi, mjec!

Thank you so much for this pull request. Someone will be along to review it soon.

I've updated the Jira issue status to In Review so no one mistakenly opens a duplicate pull request. If you'd like the ability to comment on, assign, and transition issues in the future, you're welcome to create a Jira account! It makes things a bit easier for us on the organizational side if the Full Name on your Jira account either closely matches the name you'd like us to credit in the release notes or includes it in parentheses, e.g. "Nickname (CREDIT NAME)."

Once you've done that (or if you've already done it -- Jira has been unreliable about showing us new accounts in the admin panel lately), you can either reply here or send an email to otw-coders@transformativeworks.org with your account name and email address and we'll set up the permissions for you.

Thanks again for contributing! If you have any questions, you can contact us at the same email address listed above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants