Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird problem with messageHandler #151

Closed
FAbrahamDev opened this issue Sep 23, 2024 · 2 comments · Fixed by #157
Closed

Weird problem with messageHandler #151

FAbrahamDev opened this issue Sep 23, 2024 · 2 comments · Fixed by #157

Comments

@FAbrahamDev
Copy link

Hello everyone, maybe someone experienced this issue before or has a hint.
I'm not sure if its a bug.

So i'm trying to use this pdf library in combination with @tanstack/vue-virtual to virtualize the pages.
Which works fine so long until it doesn't and I get this error without

When I load the PDF, the PDFDocumentLoadingTask promise resolves but the pdf isn't rendered.
It only happens on some PDFs and i cant pinpoint the difference between these pdf's.

The error that's on the initial load:

{
    "message": "Cannot read properties of null (reading 'getPage')",
    "name": "UnknownErrorException",
    "details": "TypeError: Cannot read properties of null (reading 'getPage')"
}

The error that occurs when scrolling and new VuePDF instances are loaded.

@tato30_vue-pdf.js?v=8f8ba6dc:12182 Uncaught TypeError: Cannot read properties of null (reading 'sendWithPromise')
    at WorkerTransport.getPage (@tato30_vue-pdf.js?v=8f8ba6dc:12182:41)
    at PDFDocumentProxy.getPage (@tato30_vue-pdf.js?v=8f8ba6dc:10978:28)
    at S (@tato30_vue-pdf.js?v=8f8ba6dc:20165:50)
    at Proxy.z (@tato30_vue-pdf.js?v=8f8ba6dc:20208:7)
    at reload (FileViewerNew.vue:90:34)
    at later (FileViewerNew.vue:103:34)

in this code:

getPage(pageNumber) {
        if (!Number.isInteger(pageNumber) || pageNumber <= 0 || pageNumber > this._numPages) {
            return Promise.reject(new Error("Invalid page request."));
        }
        const pageIndex = pageNumber - 1
          , cachedPromise = this.#pagePromises.get(pageIndex);
        if (cachedPromise) {
            return cachedPromise;
        }
        const promise = this.messageHandler.sendWithPromise("GetPage", {
            pageIndex
        }).then( (pageInfo) => {
            if (this.destroyed) {
                throw new Error("Transport destroyed");
            }
            if (pageInfo.refStr) {
                this.#pageRefCache.set(pageInfo.refStr, pageNumber);
            }
            const page = new PDFPageProxy(pageIndex,pageInfo,this,this._params.pdfBug);
            this.#pageCache.set(pageIndex, page);
            return page;
        }
        );
        this.#pagePromises.set(pageIndex, promise);
        return promise;
    }

Where the this.messageHandler is null for some reason.
So it seems that the setupMessageHandler wasn't called, or the worker crashed or i don't know.

If someone could give me some hints how to debug, this would be awesome.

@FAbrahamDev
Copy link
Author

I believe the problem occurs if the virtualizer unmounts a VuePDF component.
Not sure how to fix that.

@TaTo30
Copy link
Owner

TaTo30 commented Oct 18, 2024

Does @tanstack/vue-virtual use v-if to hide the component? Since 1.11.1 setting v-if to false will unmount the component and destroy the worker with it, that is probably the issue here. I will rollback this patch in the next version but if it is possible use v-show instead of v-if

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants