readium / swift-toolkit

A toolkit for ebooks, audiobooks and comics written in Swift
https://readium.org/mobile/
BSD 3-Clause "New" or "Revised" License
222 stars 96 forks source link

Nondeterministic loading issue with `EPUBNavigatorViewController` #413

Closed domkm closed 2 months ago

domkm commented 2 months ago

Describe the bug

I'm experiencing an interesting issue with EPUBNavigatorViewController and would appreciate help in diagnosing and potentially fixing it. I've tried reproducing it in a minimal codebase but, so far, have been unable to, so I'll describe what I'm experiencing and hope that may be enough.

Sometimes, EPUBNavigatorViewController works exactly as I would expect. The book loads, I can swipe between pages, and I can use go(to: Locator) to navigate elsewhere in the book.

However, more often than not, the book loads, I can swipe between pages, but I can not use go(to: Locator), which always returns false. When the view loads, I observe the following state changes:

  1. on(load(nil))
  2. transitioning from loading(pendingLocator: nil) to loading(pendingLocator: nil)
  3. on(loaded)
  4. transitioning from loading(pendingLocator: nil) to idle

After that, I run go(to: Locator) and observe that:

  1. somehow the state is loading(pendingLocator: nil) instead of idle (I have no idea how this can happen without triggering the didSet on state)
  2. spreads is empty
  3. needsReloadSpreads is false

This causes the navigator to be stuck thinking it's loading and unable to go, yet rendering correctly and able to manually swipe between pages.

Do you have any idea what might be causing this or any tips that may help me figure it out? Thank you.

How to reproduce?

I have been unable to reproduce it outside of my codebase.

Readium version

2.7.0

OS version

iOS 17.4, macOS (iPad version) 14.4

Testing device

iPhone 15 Pro Max (simular), MacBook Pro

Environment

macOS: `sw_vers -productVersion`
platform: `uname -m`
carthage: `carthage version`
Xcode 15.3
Build version 15E204a

Additional context

No response

domkm commented 2 months ago

I discovered that EPUBNavigatorViewController was being initialized twice. Resolving this seems to have fixed the issue, though I still don't understand how that caused this issue. Perhaps there is some global state which can break when two EPUBNavigatorViewControllers coexist? Anyway, I'll close this issue. Sorry for the noise.

mickael-menu commented 2 months ago

There are no shared global state between two instances of EPUBNavigatorViewController, AFAIK. And I already displayed two EPUBs side-by-side.

Could it be that you were doing the go() calls on the instance that was not visible?