Skip to content

[tvOS] focus navigation issue in series details page #1640

@OlivierAlbertini

Description

@OlivierAlbertini

Describe the bug

Issue summary

When navigating down from season buttons to episodes on the tvOS series details page, focus gets lost instead of moving to the first episode thumbnail. This creates a poor user experience where users have to manually search for focus or repeatedly attempt navigation.

Devices

Apple Tv 4k A1842
tvOS 18.5[22L572]

Apple TV (just before the 4k one)
tvOS 18.5[22L572]

Note: It seems not to happen on the simulator Apple Tv 4k 3rd generation (18.4)

Root cause investigation

Initial Symptoms

  • Focus disappears when navigating from season selector to episodes section
  • Sometimes focus navigation works, sometimes it doesn't
  • User gets "stuck" around season buttons unable to proceed smoothly
  • Issue does NOT occur in the old Swiftfin project

Technical details

The race condition

  1. User navigates down from seasons to episodes
  2. Focus guide onContentFocus fires → calls getContentFocus() → sets focusedEpisodeID
  3. Season selection change fires → calls getContentFocus() again → overwrites focusedEpisodeID
  4. Multiple rapid assignments cause SwiftUI focus system to fail
  5. Result: focusedEpisodeID ends up as nil despite valid assignments

Debug logs showing the issue

🎯 EpisodeHStack: Focus guide onContentFocus triggered
🎯 EpisodeHStack: getContentFocus() called, state: content
🎯 EpisodeHStack: Setting focus to lastFocused: 78d37e0779f1a4671f6ac0c26a04f36a
🎯 EpisodeHStack: About to set focusedEpisodeID = 78d37e0779f1a4671f6ac0c26a04f36a
🎯 EpisodeHStack: After assignment, focusedEpisodeID = nil  ← BUG HERE

🎯 SeasonHStack: Focus guide onContentFocus triggered
🎯 SeasonHStack: focusedSeason changed
🎯 EpisodeHStack: Focus guide onContentFocus triggered  ← SECOND CALL CONFLICTS

My current solution

Simplified Natural Focus (Current Solution)

.focusGuide(focusGuide, tag: "episodes", onContentFocus: {
    if focusedEpisodeID == nil {
        focusedEpisodeID = viewModel.elements.first?.id
    }
})

Application version

latest on master branch

Where did you install the app from?

None

Device information

Apple Tv 4k A1842

OS version

18.5[22L572]

Jellyfin server version

10.10.7


Let me know if you want a PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    tvOSImpacts tvOS

    Type

    Projects

    Status

    In-Progress

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions