Conversation
…book open
The initial scan was triggered from the XRayPlugin:init() hook, but at that
point X-Ray's per-book entity tables are still the empty ones init() just
assigned (self.characters = {} etc.). They are only restored from the sidecar
cache in autoLoadCache(), which runs from onReaderReady after init. So the
init-hook scan collected 0 terms, took the "#terms == 0" branch, and set
entity_xp_matches = {} -- the "scanned, nothing to show" marker -- which then
made every later automatic call to ensureEntityFootnotesSetup skip the scan.
Net effect: no underlines on book open; they only came back after a manual
Scan/Rescan from the X-Ray menu. On the very first book of a session the init
hook doesn't fire at all (see the existing comment above
ensureEntityFootnotesSetup), so that case had no automatic scan either.
Hook XRayPlugin:autoLoadCache instead and run the full setup once it returns,
i.e. once characters/locations/historical_figures/terms are actually
populated. This also covers the first book of a session, because the wrapper
sits on the class table and onReaderReady happens after the patch has run.
The init hook is kept for the localization/mount setup (harmless to do early)
but now passes skip_scan=true so it can no longer poison entity_xp_matches
before the tables exist.
Tested on Kindle Colorsoft, KOReader 2026.07.1, X-Ray 26.8.x and 26.9.10-beta3.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The initial entity scan runs from the
XRayPlugin:init()hook, but at that point X-Ray's per-book tables are still the empty onesinit()just assigned (self.characters = {}etc.). They're only restored from the sidecar inautoLoadCache(), which runs fromonReaderReadyafter init.So the init-hook scan collects 0 terms, takes the
#terms == 0branch and setsentity_xp_matches = {}— the "scanned, nothing to show" marker. Every later automatic call toensureEntityFootnotesSetupthen seesentity_xp_matchesis non-nil and skips. Result: no underlines on book open; they only appear after a manual Scan/Rescan from the X-Ray menu. (On the very first book of a session the init hook doesn't fire at all, per the existing comment, so that case had no automatic scan either.)Fix
Hook
XRayPlugin:autoLoadCacheand run the full setup once it returns, i.e. oncecharacters/locations/historical_figures/termsare actually populated. Because the wrapper sits on the class table andonReaderReadyhappens after the patch has loaded, this also covers the first book of a session.The init hook is kept for the localization/mount setup (harmless to do early) but now passes
skip_scan = trueso it can no longer poisonentity_xp_matchesbefore the tables exist.Tested
Kindle Colorsoft, KOReader 2026.07.1, X-Ray 26.8.x and 26.9.10-beta3 — underlines now show on the first book after a KOReader start and on every subsequent open, and the sidecar entity cache is loaded instead of rescanned when the signature matches.
🤖 Generated with Claude Code