Skip to content

wrong location when OpenPublication with location #76

@buihongvinh

Description

@buihongvinh

🐛 Issue: Initial Locator Changes Automatically When Opening EPUB

Description

When opening an EPUB with a predefined initialLocator (used to restore reading history), the locator values are automatically changed after the publication is opened.

I expect the reader to open exactly at the provided locator, but instead, it navigates to a different location.
How to Reproduce

Run the example project.

Go to the BookshelfPage class.

Replace this code:

final fakeInitialLocator = publication.locatorFromLink(
  publication.readingOrder[
    math.min(2, publication.readingOrder.length - 1)
  ],
);

with:

final locator = Locator.fromJson({
  "href": "OEBPS/2360721518641290303_2701-h-1.htm.xhtml",
  "type": "application/xhtml+xml",
  "locations": {
    "position": 52,
    "progression": 0.015037593984962405,
    "totalProgression": 0.09497206703910614,
    "fragments": [
      "page=3",
      "totalPages=133",
      "toc=pgepubid00014"
    ],
    "cssSelector": "pre"
  }
});

Run the app on a physical device.

Open the EPUB moby_dick.epub.

Then go back to the previous screen and tap on epub moby_dick.epub again.

Expected Behavior

The reader should open exactly at:

position: 52
progression: 0.015037593984962405
cssSelector: pre
Actual Behavior

After opening, the location automatically changes:

onPageChanged:
{
  href: OEBPS/2360721518641290303_2701-h-1.htm.xhtml,
  type: application/xhtml+xml,
  locations: {
    fragments: [page=5, totalPages=133, toc=pgepubid00014],
    progression: 0.03007518796992481,
    position: 53,
    totalProgression: 0.09683426443202979,
    cssSelector: body > :nth-child(9)
  }
}

The LocatorChanged event confirms the reader has moved to:

position: 53
progression: 0.03007518796992481
cssSelector: body > :nth-child(9)
Image

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions