Skip to content

fix: re-render digest when restored from back/forward cache - #16

Open
ennis-ma wants to merge 1 commit into
philoking:mainfrom
ennis-ma:fix/refocus-digest-after-bfcache-restore
Open

ennis-ma wants to merge 1 commit into
philoking:mainfrom
ennis-ma:fix/refocus-digest-after-bfcache-restore

Conversation

@ennis-ma

Copy link
Copy Markdown

Bug Description

After opening an article in the reader and going Back, the story's card leaves an empty gap on the digest page.

Root Cause

dismiss() hides a card with opacity: 0 but deliberately keeps its layout box so triage doesn't shift the page; the layout is only rebuilt on the next render(). Returning from /reader.html via the browser Back button restores the page from the back/forward cache, which does not run JavaScript. The rebuild never happens, so read cards remain as invisible, space-consuming boxes.

Fix

Add a pageshow listener: when the page is restored from bfcache (e.persisted) while the digest view is active, call render() to rebuild the layout from current state. Read stories drop out entirely instead of leaving gaps.

window.addEventListener('pageshow', (e) => {
  if (e.persisted && currentView === 'digest') render();
});

How to Verify

  1. Open the digest, click a story (opens /reader.html, marks it read).
  2. Press the browser Back button.
  3. Before: blank gap where the card was. After: layout reflows cleanly without it.

Risk Assessment

Low. 9 added lines, single event listener, no changes to existing logic. Normal (non-bfcache) loads fire pageshow with persisted === false, which is a no-op.

Opening a story marks it read and dismiss() hides its card with
opacity: 0 while intentionally keeping the layout box so triage
doesn't shift the page. The layout is only rebuilt on the next
render(), but returning from reader.html via the browser Back
button restores the page from the back/forward cache, which runs
no JavaScript. Invisible read cards are left behind as blank gaps.

Listen for pageshow with event.persisted and re-render the digest
view on bfcache restores.
@philoking

philoking commented Aug 26, 2026 •

Copy link
Copy Markdown
Owner

Thanks for the fix. I am curious how it's working in practice? I actually started with it this way and I didn't like the page re-rendering it's layout everytime I dismissed or saved something for later. I am happy to go back to it if the experience is better for most people.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants