Skip to content

fix(core): navigate next into the next book's intro - #464

Merged
camrun91 merged 5 commits into
mainfrom
bdh/YPE-6400_adjacent-chapter-next-intro
Nov 4, 2026
Merged

camrun91 merged 5 commits into
mainfrom
bdh/YPE-6400_adjacent-chapter-next-intro

Conversation

@arinthros

@arinthros arinthros commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Why

getAdjacentChapter handles book intros differently in each direction. previous from chapter 1 of a book with an intro goes to that intro, but next from the last chapter of the previous book skips it and goes to chapter 1. So next and previous are not inverses, and a reader paging forward in BibleReader never reaches an intro:

getAdjacentChapter(books, 'GEN', '50', 'next');        // before: { EXO, '1' }  after: { EXO, 'INTRO' }
getAdjacentChapter(books, 'EXO', '1', 'previous');     // { EXO, 'INTRO' } (unchanged)
getAdjacentChapter(books, 'EXO', 'INTRO', 'previous'); // { GEN, '50' } (unchanged)

The Swift reader goes to the intro: goToNextChapter in BibleReaderViewModel+Navigation.swift moves to the next book with showBookIntro = true when that book has an intro.

Jira: YPE-6400

What changed

  • Next from a book's last chapter returns the next book's intro when it has one; otherwise its first numbered chapter, as before.
  • Reversed the two tests from YPE-1343: Bible Reader next and prev chapter btns #168 that asserted the skip (next chapter cross-book, skipping intro and cross-book next skips intro in chapters array of next book).
  • Added a case for a next book without an intro, and a round-trip test: for every chapter and intro in reading order, next returns the following position and previous the one before.

Scope

  • Only cross-book next. Within-book navigation, previous, and the Bible start and end are unchanged.
  • The intro is detected the same way getPrevious already detects it (book.intro).

Tradeoffs

#168 (YPE-1343) added the skip with tests but no stated reason. If skipping intros going forward was deliberate (for example, to match the Android Bible app), the fix should probably go the other way: make previous from chapter 1 skip the intro too, so both directions match. This PR follows Swift, the reference for reader behavior. Reviewers, please flag it if the skip was intentional.

Blast Radius

BibleReader's next-chapter button: from the last chapter of a book, it now opens the next book's intro, for versions that have intros. Hosts calling getAdjacentChapter directly get the intro in that one case. Versions without intros are unaffected.

Verification

  • Before the fix, the two reversed tests and the round-trip test failed ({ EXO, '1' } instead of { EXO, 'INTRO' }). After the fix: 18 passed in src/getAdjacentChapter.test.ts.
  • pnpm exec turbo test for core, hooks, and ui: 345 (2 skipped), 200, and 536 passed.
  • pnpm build, pnpm lint, and pnpm exec turbo typecheck --force pass.

Test plan

  • In the Vite example, pick a version with book intros and open the last chapter of a book. Next opens the following book's intro, and next again opens chapter 1.
  • From that intro, previous returns to the last chapter of the previous book.
  • With a version that has no intros, next from a book's last chapter opens chapter 1 of the next book.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge.

Summary

Forward navigation now opens the next book’s intro when one exists.

  • Forward reading visits the next book's intro when it has one.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Last chapter] --> B{Next book exists?}
  B -->|No| C[Return null]
  B -->|Yes| D{Has intro?}
  D -->|Yes| E[Open intro]
  D -->|No| F[Open first numbered chapter]
  E -->|Next| F
Loading

Reviews (4) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

getAdjacentChapter skipped the next book's intro going forward but visited
it going back, so previous(next(x)) did not return x and BibleReader's next
button never reached an intro. Next from a book's last chapter now goes to
the next book's intro when it has one, matching Swift's goToNextChapter.

Reverses the two tests from #168 that asserted the skip and adds a
round-trip check over every chapter and intro.

YPE-6400

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 272e3a4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@youversion/platform-core Patch
@youversion/platform-react-hooks Patch
@youversion/platform-react-ui Patch
vite-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@camrun91 camrun91 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi! Thank you for this fix. The logic is correct, and it agrees with Swift and Kotlin. All CI checks pass, and the tests fail on the old code, so they catch the bug.

I have one required change:

Update the JSDoc for getAdjacentChapter (packages/core/src/getAdjacentChapter.ts:10-18)

getAdjacentChapter is public API. Core exports it, and UI exports it again. This PR changes the value that it returns, but the JSDoc still says only "Computes the next or previous chapter across book boundaries." Our review guidelines tell us to document API changes with JSDoc (docs/review-guidelines.md).

Please add the intro behavior. For example:

Reading order is each book's intro (when book.intro is present), then its numbered chapters. next from the last chapter of a book returns the intro of the next book when it has one. If not, it returns chapter 1. previous from chapter 1 returns the intro of the book.

After you make this change, I can approve. Thanks again!

@arinthros

Copy link
Copy Markdown
Contributor Author

Thanks @camrun91. Added the reading-order JSDoc to getAdjacentChapter in 2142ef1. Two additions to your wording: previous from chapter 1 falls back to the previous book's last chapter when there is no intro, and next and previous are inverses of each other. The @youversion/platform-react-ui export is a plain re-export, so it carries the same doc comment. I also merged main again (#470).

@arinthros
arinthros requested a review from camrun91 November 4, 2026 20:34

@camrun91 camrun91 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@camrun91

camrun91 commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

@arinthros I am going to merge this so it can make it in the release I am about to do.

@camrun91
camrun91 merged commit 669db59 into main Nov 4, 2026
20 checks passed
@camrun91
camrun91 deleted the bdh/YPE-6400_adjacent-chapter-next-intro branch November 4, 2026 20:53
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