Skip to content

fix(web): exit the reader through history so back doesn't re-open it - #281

Merged
Quick104 merged 4 commits into
Silo-Server:mainfrom
fluxis:fix/reader-back-history
Aug 20, 2026
Merged

Quick104 merged 4 commits into
Silo-Server:mainfrom
fluxis:fix/reader-back-history

Conversation

@fluxis

@fluxis fluxis commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Exiting the manga/ebook reader to the series page, then pressing back on the series page, re-opened the reader. The reader's header back control was a plain <Link> push: history became […, series, reader, series], so back landed on the reader again — an inescapable loop unless the user force-navigated elsewhere.

Approach

Plain left-clicks on the reader's back control now consume the reader's history entry (navigate(-1)) when in-app history exists, so history returns to wherever the reader was opened from. The href is preserved for modified clicks (open in new tab) and remains the fallback when the reader was opened as a direct deep link (no in-app history).

The history-availability predicate is extracted to lib/backNavigation.ts and shared with PageBack, which already implemented the same pattern — one definition instead of two copies.

Testing

New regression test: history seeded as [origin, reader] with backTo pointing at a third URL — clicking Back must land on the origin entry, not a fresh push of backTo (fails on the old push behavior). Existing backTo-sanitization tests still pass (the href is unchanged). Full EbookReader + PageBack suites green; pnpm run lint + format:check clean. (Two unrelated test files fail identically on clean origin/main — pre-existing upstream breakage, verified by stash comparison.)

Fixes #189

AI-use disclosure

Implemented with Claude Code (test-first); human-reviewed before submission.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved back navigation in the ebook reader when browsing from existing history.
    • Readers without navigation history are now taken to the appropriate fallback page.
    • Next-chapter navigation now returns readers to the series page correctly when navigating back.
    • Preserved standard link behavior for modified clicks and direct navigation.
    • Added regression coverage for reader back navigation and chapter transitions.

@coderabbitai

coderabbitai Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Quick104, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 47 minutes

Limit details: You’ve used all 2 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

Wait for the limit to reset, then comment @coderabbitai review or push new commits to the PR.

An organization admin can change what happens after included review limits in Billing.

How do review limits work?

CodeRabbit enforces per-developer PR review limits within each organization.

For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 74733ace-17ad-4d67-8a81-e760c446c0a5

📥 Commits

Reviewing files that changed from the base of the PR and between 0ca9aea and 74fdb27.

📒 Files selected for processing (1)
  • web/src/pages/EbookReader.test.tsx

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e567667a-9d48-4a3d-8301-d50726103ed7

📥 Commits

Reviewing files that changed from the base of the PR and between 147e9b0 and 0ca9aea.

📒 Files selected for processing (2)
  • web/src/pages/EbookReader.test.tsx
  • web/src/pages/EbookReader.tsx

Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The reader now checks router history before handling back clicks. Direct entries use route replacement. Next-chapter links replace the current reader entry. Tests cover history traversal, fallback navigation, and both next-chapter controls.

Changes

Reader navigation

Layer / File(s) Summary
Router history detection and page back integration
web/src/lib/backNavigation.ts, web/src/components/PageBack.tsx
Added hasRouterHistory() and used it to decide when to navigate backward.
Reader back and next-chapter controls
web/src/pages/EbookReader.tsx
Eligible back clicks use router history when available and replace the route for direct entries. Header and end-of-book next-chapter links replace the current reader entry.
Reader history regression coverage
web/src/pages/EbookReader.test.tsx
Tests cover existing-history back navigation, direct-entry fallback, next-chapter behavior, configurable progress, and history cleanup.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 0ca9a

This localized navigation change preserves direct-link and modified-click behavior while correcting the reader exit path; no actionable merge-blocking risk remains after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant EbookReader
  participant hasRouterHistory
  participant ReactRouter
  participant SeriesPage
  EbookReader->>hasRouterHistory: Check router history index
  hasRouterHistory-->>EbookReader: Return history availability
  EbookReader->>ReactRouter: Navigate -1 for eligible back click
  ReactRouter->>SeriesPage: Restore prior route
Loading

Suggested reviewers: quick104

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the reader history-navigation fix and its effect on Back behavior.
Linked Issues check ✅ Passed The changes implement history-aware reader exit behavior and prevent chapter navigation from reopening prior reader entries, satisfying issue #189.
Out of Scope Changes check ✅ Passed The helper, reader changes, PageBack integration, and regression tests are directly related to the linked navigation objective.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 800873ce96

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread web/src/pages/EbookReader.tsx Outdated
Comment on lines +619 to +620
event.preventDefault();
navigate(-1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve reader exit target after Next chapter

When a manga chapter is opened with the in-reader Next link, that link is a normal <Link> push, so the previous history entry is another /reader/ebook/... page while backHref still points at the series via backTo. This handler now prevents the backHref navigation and always calls navigate(-1) whenever history exists, so Back on chapter 2 returns to chapter 1 instead of exiting to the series, and users who advanced through several chapters have to walk back through each prior reader page.

Useful? React with 👍 / 👎.

@Quick104

Quick104 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Code review

Found 1 issue:

  1. The new Back handler pops exactly one history entry (navigate(-1)), but the reader's "Next chapter" links are plain pushing Links with no replace. After advancing through chapters (history: [series, reader-ch1, reader-ch2, ...]), clicking Back lands on the previous chapter's reader page instead of exiting the reader — the user must click Back once per chapter read, which contradicts the PR's goal of exiting the reader through history. Note handleFileChange already uses navigate(..., { replace: true }) for the same reason; making the chapter-nav links replace navigations would keep the reader at a single history entry so the one-pop exit works. (This matches the unresolved Codex inline comment on this PR; verified independently.)

Back handler that pops a single entry:

<Button asChild variant="ghost" size="icon" aria-label="Back">
<Link
to={backHref}
onClick={(event) => {
// Exiting the reader must consume the reader's history entry,
// not push the target on top of it — otherwise pressing back
// on the destination re-opens the reader (issue #189). The
// href stays for modified clicks (new tab) and as the
// fallback when the reader was opened directly.
if (
event.defaultPrevented ||
event.button !== 0 ||
event.metaKey ||
event.ctrlKey ||
event.shiftKey ||
event.altKey ||
!hasRouterHistory()
) {
return;
}
event.preventDefault();
navigate(-1);
}}
>

Pushing next-chapter links (header and end-of-book CTA):

>
<Link to={nextChapterHref}>
<span className="text-muted-foreground max-w-36 truncate text-xs">

>
<Link to={nextChapterHref}>
Next: {nextChapter.label}

Contrast with the existing replace: true file switch:

navigate(`/reader/ebook/${encodeURIComponent(contentId)}?${nextParams.toString()}`, {
replace: true,
});

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

The reader's header back control was a plain Link push: exiting to the
series page stacked a second series entry on top of the reader, so
pressing back on the series page navigated to the reader again. Plain
left-clicks now consume the reader's history entry (navigate(-1)) when
in-app history exists; the href remains for modified clicks and as the
fallback for direct deep links into the reader.

The history-availability check is extracted to lib/backNavigation and
shared with PageBack, which already used the same pattern.

Fixes Silo-Server#189

Co-Authored-By: Claude Fable 5 <[email protected]>
@Quick104
Quick104 force-pushed the fix/reader-back-history branch from 800873c to 3b4eec6 Compare July 10, 2026 17:35

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 147e9b02ba

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread web/src/pages/EbookReader.tsx Outdated
Comment on lines +615 to +617
!hasRouterHistory()
) {
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Replace the reader entry when no history exists

When the reader is opened directly in a fresh tab or after a full-page navigation, React Router initializes the current entry with idx === 0, so this branch returns and lets the <Link> perform a push. The resulting history is [reader, backHref], meaning pressing browser Back on the destination immediately reopens the reader—the same loop this change is intended to eliminate. The no-history fallback should replace the reader entry with backHref rather than push it.

Useful? React with 👍 / 👎.

@Quick104
Quick104 merged commit 1fdc5e8 into Silo-Server:main Aug 20, 2026
4 checks passed
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.

Pressing back on series page after exiting reader re-opens the reader

2 participants