fix(pdf): clear text layer before re-render to stop duplicated spans (v0.5.3)

TextLayer appends into the container without clearing it, so any
re-render of the same page doc (zoom settle, spread-scale update)
stacked a second span set at sub-pixel-shifted positions — selection
text reads doubled. Clear the container (stale spans + previous
endOfContent helper) before each TextLayer render.
This commit is contained in:
John O'Keefe committed 2026-10-13 10:37:51 -04:00
1 parent b7597d6159
commit 7796b05582
2 files changed
+7 -1

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "foliate-js",
"version": "0.5.2",
"version": "0.5.3",
"description": "Render e-books in the browser",
"repository": {
"type": "git",
+6
View File
@@ -36,6 +36,12 @@ const render = async (page, doc, zoom) => {
doc.querySelector("#canvas").replaceChildren(doc.adoptNode(canvas));
const container = doc.querySelector(".textLayer");
// TextLayer appends into the container without clearing it, so any
// re-render of the same page doc (zoom settle, spread-scale update)
// stacked a second span set over the old one (sub-pixel shifted —
// selection text read doubled). Clear stale spans and the previous
// endOfContent helper before rendering fresh.
container.replaceChildren();
const textLayer = new pdfjsLib.TextLayer({
textContentSource: await page.streamTextContent(),
container,