Skip to content

feat: Add hash-based article navigation for back/forward button support#8764

Open
sliekens wants to merge 2 commits into
FreshRSS:edgefrom
sliekens:feat/back
Open

feat: Add hash-based article navigation for back/forward button support#8764
sliekens wants to merge 2 commits into
FreshRSS:edgefrom
sliekens:feat/back

Conversation

@sliekens
Copy link
Copy Markdown

@sliekens sliekens commented May 2, 2026

Closes #8759

Changes proposed in this pull request:

  • Add hash-based article navigation to support back/forward button functionality
  • Modify toggleContent() in p/scripts/main.js to update URL hash when articles are expanded or collapsed
  • Add new init_article_history() function to handle hash change events and initial page load with hash
  • Enable bookmarkable URLs for individual articles using #article-{id} hash fragments

How to test the feature manually:

  1. Click on any article header to expand it (notice URL changes to #article-{id}), then press your browser's back button - the article should collapse instead of leaving FreshRSS
  2. After collapsing via back button, press forward - the article should re-expand
  3. Expand an article, copy the URL with the hash fragment, then paste it in a new tab - the article should be automatically expanded on page load

Pull request checklist:

  • clear commit messages
  • code manually tested
  • unit tests written (optional if too hard)
  • documentation updated

Unit tests: FreshRSS uses PHPUnit for backend tests; there are no JavaScript unit tests in this codebase, so this is N/A for JS changes

Documentation: no user attention required for this change.

Copilot AI review requested due to automatic review settings May 2, 2026 15:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds hash-based navigation for expanding/collapsing articles so browser back/forward traversal can close/reopen articles and allow bookmarking of specific entries.

Changes:

  • Update toggleContent() to set/clear location.hash when switching/expanding/collapsing articles.
  • Add init_article_history() to expand/collapse articles on initial load and hashchange.
  • Initialise the new history handler from init_main_afterDOM().

Comment thread p/scripts/main.js Outdated
Comment thread p/scripts/main.js Outdated
Comment thread p/scripts/main.js Outdated
Comment thread p/scripts/main.js Outdated
@Frenzie
Copy link
Copy Markdown
Member

Frenzie commented May 2, 2026

What concretely does it do when navigating through multiple articles?

@sliekens
Copy link
Copy Markdown
Author

sliekens commented May 2, 2026

What concretely happens when navigating through multiple articles?
Each article you open is added as a new history entry. So if you open several articles in a row, pressing “back” will take you through them in reverse order, one at a time.

If you’d rather, I can change this behavior so that only a single history entry is kept. In that case, navigating between articles wouldn’t build up a stack, but that would require a bit more implementation work.

@Frenzie
Copy link
Copy Markdown
Member

Frenzie commented May 2, 2026

I think I'd prefer the latter, but I suppose we'll see what the others have to say.

@sliekens
Copy link
Copy Markdown
Author

sliekens commented May 2, 2026

In fact I would also prefer the single history entry, which aligns better with the intended design of getting back to the overview quickly.

Current behavior:

stack.mp4

@Alkarex Alkarex added this to the 1.30.0 milestone May 2, 2026
@Alkarex Alkarex added the UX User experience label May 2, 2026
@sliekens
Copy link
Copy Markdown
Author

sliekens commented May 2, 2026

Updated to the single history entry, I believe this is closer to what most people expect when pressing back:

single.mp4

The difference is especially noticeable on mobile 🙂.

@Inverle Inverle added the javascript Pull requests that update Javascript code label May 3, 2026
@Frenzie
Copy link
Copy Markdown
Member

Frenzie commented May 4, 2026

The interaction's a bit odd if you go back to a page where the article ID doesn't exist because it was from further down, then open some article, scroll down, and press back. Instead of closing the opened article it'll now open the previously opened article.

sliekens added 2 commits May 6, 2026 23:45
- Update URL hash when articles are expanded/collapsed (#article-{id})
- Listen for hashchange events to handle browser back/forward
- Enable bookmarkable URLs for individual articles
- Auto-expand articles when loading URL with hash fragment
@sliekens
Copy link
Copy Markdown
Author

sliekens commented May 6, 2026

@Frenzie not completely sure I understood, but I identified a problem where article IDs could still be stacked in some circumstances, like when the article is not in view. I think that might explain what you saw, and is fixed in 3dc1cb3.

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

Labels

javascript Pull requests that update Javascript code UX User experience

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] close article on back button

5 participants