diff --git a/frontend/src/app/features/readers/pdf-reader/pdf-reader.component.spec.ts b/frontend/src/app/features/readers/pdf-reader/pdf-reader.component.spec.ts index 36a533be5..003da7cd8 100644 --- a/frontend/src/app/features/readers/pdf-reader/pdf-reader.component.spec.ts +++ b/frontend/src/app/features/readers/pdf-reader/pdf-reader.component.spec.ts @@ -5,7 +5,6 @@ import {PdfReaderComponent} from './pdf-reader.component'; interface PdfReaderHarness { embedPdfIframe: {contentWindow: {postMessage: ReturnType}} | null; embedPdfSaveResolve?: (buffer: ArrayBuffer | null) => void; - cachedPdfBuffer: ArrayBuffer | null; pdfBlobUrl: string | null; authService: {getInternalAccessToken: () => string | null}; cacheStorageService: {delete: ReturnType}; @@ -13,10 +12,6 @@ interface PdfReaderHarness { saveEmbedPdfDocument: () => Promise; } -function bytes(buffer: ArrayBuffer): number[] { - return Array.from(new Uint8Array(buffer)); -} - function makeComponent(savedBuffer: ArrayBuffer): PdfReaderHarness { const component = Object.create(PdfReaderComponent.prototype) as PdfReaderHarness; component.embedPdfIframe = { @@ -26,7 +21,6 @@ function makeComponent(savedBuffer: ArrayBuffer): PdfReaderHarness { }) } }; - component.cachedPdfBuffer = new Uint8Array([9, 9, 9]).buffer; component.pdfBlobUrl = 'blob:old-pdf'; component.authService = {getInternalAccessToken: () => null}; component.cacheStorageService = {delete: vi.fn(() => Promise.resolve(true))}; @@ -76,8 +70,6 @@ describe('PdfReaderComponent save handling', () => { await expect(save).resolves.toBe(true); - expect(bytes(component.cachedPdfBuffer!)).toEqual([4, 5, 6]); - expect(component.cachedPdfBuffer).not.toBe(savedBuffer); expect(revokeObjectUrl).toHaveBeenCalledWith('blob:old-pdf'); expect(createObjectUrl).toHaveBeenCalledTimes(1); expect(component.pdfBlobUrl).toBe('blob:saved-pdf'); diff --git a/frontend/src/app/features/readers/pdf-reader/pdf-reader.component.ts b/frontend/src/app/features/readers/pdf-reader/pdf-reader.component.ts index e32d8fb57..00a092553 100644 --- a/frontend/src/app/features/readers/pdf-reader/pdf-reader.component.ts +++ b/frontend/src/app/features/readers/pdf-reader/pdf-reader.component.ts @@ -124,7 +124,6 @@ export class PdfReaderComponent implements OnInit, OnDestroy { private initTimeout?: ReturnType; private isInitializingBookViewer = false; private pdfFetchAbortController?: AbortController; - private cachedPdfBuffer: ArrayBuffer | null = null; private suppressProgressSave = false; private initialPage = 1; private pendingDocTargetPage: number | null = null; @@ -487,16 +486,6 @@ export class PdfReaderComponent implements OnInit, OnDestroy { this.embedPdfBook.setPanMode(true); } - // Cache the raw PDF bytes so the doc-viewer switch never needs a network request - if (!this.cachedPdfBuffer) { - const blobSrc = this.pdfBlobUrl || (this.bookData.startsWith('blob:') ? this.bookData : null); - if (blobSrc) { - fetch(blobSrc).then(r => r.arrayBuffer()).then(buf => { - this.cachedPdfBuffer = buf; - }).catch(() => { /* caching is best-effort */ }); - } - } - // Initialize bookmark service early so toggleBookmark works before documentOpened$ this.pdfBookmarkService.initialize(this.bookId); @@ -979,24 +968,21 @@ export class PdfReaderComponent implements OnInit, OnDestroy { try { let pdfBuffer: ArrayBuffer; - if (this.cachedPdfBuffer) { - // Use the in-memory cache — completely network-free - pdfBuffer = this.cachedPdfBuffer.slice(0); + const source = this.pdfBlobUrl || this.bookData; + if (source.startsWith('blob:')) { + const res = await fetch(source); + pdfBuffer = await res.arrayBuffer(); } else { - const source = this.pdfBlobUrl || this.bookData; - if (source.startsWith('blob:')) { - const res = await fetch(source); - pdfBuffer = await res.arrayBuffer(); - } else { - const headers: Record = {}; - const token = this.authService.getInternalAccessToken(); - if (token) { - headers['Authorization'] = `Bearer ${token}`; - } - const response = await fetch(source, { headers, credentials: 'include' }); - if (!response.ok) throw new Error(`PDF fetch failed: ${response.status}`); - pdfBuffer = await response.arrayBuffer(); + const headers: Record = {}; + const token = this.authService.getInternalAccessToken(); + if (token) { + headers['Authorization'] = `Bearer ${token}`; } + const response = await fetch(source, {headers, credentials: 'include'}); + if (!response.ok) { + throw new Error(`PDF fetch failed: ${response.status}`); + } + pdfBuffer = await response.arrayBuffer(); } if (this.viewerMode() !== 'document') return; @@ -1159,7 +1145,6 @@ export class PdfReaderComponent implements OnInit, OnDestroy { private updateSavedPdfCache(buffer: ArrayBuffer): void { const savedBuffer = buffer.slice(0); - this.cachedPdfBuffer = savedBuffer; this.revokePdfBlobUrl(); this.pdfBlobUrl = URL.createObjectURL(new Blob([savedBuffer], { type: 'application/pdf' })); } @@ -1317,7 +1302,6 @@ export class PdfReaderComponent implements OnInit, OnDestroy { this.touchCleanup?.(); this.revokePdfBlobUrl(); - this.cachedPdfBuffer = null; if (this.bookData?.startsWith('blob:')) { URL.revokeObjectURL(this.bookData); }