Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foliate keep opening the same page #653

Closed
medeotl opened this issue Jan 6, 2021 · 10 comments
Closed

Foliate keep opening the same page #653

medeotl opened this issue Jan 6, 2021 · 10 comments
Labels
bug Something isn't working epub.js Related to Epub.js

Comments

@medeotl
Copy link

medeotl commented Jan 6, 2021

Describe the bug
Reading an ebook of 2073 pages, after reading over the 1265 page (example, until page 1310) and closing foliate, when opening again, it will display page 1265. If i close the book at a page minor of 1265 everything is ok.

To Reproduce
Steps to reproduce the behavior:

  1. Open my ebook (can upload if needed)
  2. Go to a page > 1265 (example, page 1310)
  3. Close the ebook
  4. Reopen foliate

Expected behavior
Foliate open the book to correct page (in the example, page 1310)

Actual behavior
Foliate keep opening at page 1265

Version:

  • Foliate version: 2.5.0
  • OS/Distribution and version: Fedora 33 (Workstation Edition)
  • Desktop environment: 3.38.2
  • Installation method: both Flatpak and rpm

Additional context
Problem doesn't seem related to saving the last position correctly: if I go to library instead of closing foliate, I can see that the book's percentage of reading is correct. But if I reopen it it will be opened at the same, wrong, page.

@medeotl medeotl added the bug Something isn't working label Jan 6, 2021
@johnfactotum
Copy link
Owner

If you do the following:

  1. Press Ctrl + L
  2. Copy the CFI
  3. Close the app
  4. Ctrl + L, paste the CFI, then hit

Does it go to the correct page?

@medeotl
Copy link
Author

medeotl commented Jan 9, 2021

Yes, it goes.
I've modified something of the app (window size and/or font size) so now it keep going to page 1255 (still 61% of the book as percentage).
Problem is with chapter 6, chapter 7 save and restore page correctly.

@johnfactotum
Copy link
Owner

johnfactotum commented Jan 10, 2021

Okay, I think I can reproduce this problem.

It seems the problem is that, when a chapter (spine item) is not yet loaded, so for some reason, Epub.js has trouble going to locations after a certain point in that chapter. After the chapter is loaded, the problem no longer occurs.

This can be verified by:

  1. Press Ctrl + L
  2. Copy the CFI
  3. Go to a different chapter
  4. Ctrl + L, paste the CFI, then hit

So a quick fix is probably just go to the saved location twice:

diff --git a/src/web/epub-viewer.js b/src/web/epub-viewer.js
index 5d80be7..dd67d85 100644
--- a/src/web/epub-viewer.js
+++ b/src/web/epub-viewer.js
@@ -470,6 +470,7 @@ const loadLocations = async locations => {
 
 const display = lastLocation =>
     rendition.display(lastLocation)
+        .then(() => rendition.display(lastLocation))
         .then(() => dispatch({ type: 'book-displayed' }))
 
 // get book cover for "about this book" dialogue

@johnfactotum johnfactotum added the epub.js Related to Epub.js label Jan 15, 2021
@itprojects
Copy link
Contributor

@johnfactotum This fix of going to location twice has been known for some time. There may even be an old bug or discussion that was closed.

@johnfactotum
Copy link
Owner

johnfactotum commented Jan 16, 2021

I do remember putting that in the code at some point (seems to be d0b8fb9), but that was for another unrelated issue.

@johnfactotum
Copy link
Owner

This problem don't seem to happen with the new renderer. I believe it's fixed by the new anchor mechanism which works to keep you at the same location even if the content dimensions changes while being loaded.

@emes81
Copy link

emes81 commented May 29, 2023

I'm experiencing this same problem on Foliate 2.6.4 (RPM version), Fedora 37. The copy/pasting the CFI also works in my case.

@johnfactotum
Copy link
Owner

Right, v2.6.4 uses Epub.js, which has this problem.

By the way, it probably doesn't matter anymore, since the issue is already fixed, but for the record, the theory above in my previous comment was wrong. It is true that I have since added anchoring when the page content resizes (johnfactotum/foliate-js@20254e3), but this was not true at the time I made that comment. The real reason was, I now believe, simply because the custom stylesheet is injected before it scrolls to the target page (and even before it even starts paginating). After scrolling to the target page, since the whole page is already loaded at this point, nothing will cause a resize (except for interactive elements), so the resize observer wasn't really doing anything useful. It's easy to show this, since the resize observer actually does nothing in Firefox (https://bugzilla.mozilla.org/show_bug.cgi?id=1832939). But the renderer works perfectly in Firefox anyway, as long as you don't trigger resizes by e.g. loading a non-local resource such as fonts.

@emes81
Copy link

emes81 commented May 29, 2023

Thanks for the update and explanation - do you know when the new renderer will be coming to the version of Foliate in the Fedora repositories? And is it already implemented in the Flatpak? (I'd prefer to use the repo version as that makes it marginally easier to sync the Foliate system files between devices via Syncthing)

@johnfactotum
Copy link
Owner

The new renderer is used in the gtk4 branch. It's not released yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working epub.js Related to Epub.js
Projects
None yet
Development

No branches or pull requests

4 participants