fix(pdf-server): detached-buffer on range re-request + stale e2e assertion (#561)
* fix(pdf-server): slice bytes before onDataRange to avoid detached buffer PDF.js transfers the ArrayBuffer to its worker via postMessage, detaching it in the main thread. When the same range is re-requested (common on iOS/WKWebView under memory pressure during scroll/zoom/navigate), the cached Uint8Array now wraps a detached buffer and onDataRange throws 'Buffer is already detached'. Fix: pass result.bytes.slice() so the rangeCache entry stays valid. * test(e2e): update pdf-annotations assertion for new display_pdf prompt text The 91880a6d prompt rewrite changed the interact-enabled result text from 'Displaying PDF (viewUUID: ...)' to 'PDF opened. viewUUID: ...'. The e2e test was still asserting the old string.
This commit is contained in:
parent
6723c8ff10
commit
e8a4ea5f89
1 changed files with 7 additions and 3 deletions
|
|
@ -3875,7 +3875,11 @@ async function loadPdfProgressively(urlToLoad: string): Promise<{
|
|||
requestDataRange(begin: number, end: number) {
|
||||
fetchRange(urlToLoad, begin, end)
|
||||
.then((result) => {
|
||||
this.onDataRange(begin, result.bytes);
|
||||
// PDF.js transfers the ArrayBuffer to its worker, detaching it.
|
||||
// Pass a copy so the rangeCache entry stays valid for re-requests
|
||||
// (iOS/WKWebView re-requests ranges under memory pressure and
|
||||
// throws "Buffer is already detached" on the cached original).
|
||||
this.onDataRange(begin, result.bytes.slice());
|
||||
})
|
||||
.catch((err: unknown) => {
|
||||
log.error(`Error fetching range ${begin}-${end}:`, err);
|
||||
|
|
|
|||
Loading…
Reference in a new issue