Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-4774

ZK-4754 follow-up javascript error if pdfviewer detach before content loaded

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • 9.5.1
    • 9.0.0, 9.5.1
    • Components
    • Security Level: Jimmy

      Steps to Reproduce

      same as #ZK-4754

      _loadPdf(src: string) {
      		this._destroyPdf();
      		PDFJS.getDocument(src).promise.then(pdf => {
      			let pageCount = pdf.numPages,
      				pageCountLabel = '' + pageCount;
      			this._pdf = pdf;
      			this._pageCount = pageCount;
      			this._getPage(this._getDisplayedPageNumber(), true);
      			(this.$n('toolbar-page-active') as HTMLInputElement).max = pageCountLabel;
      			this.$n('toolbar-page-total').textContent = pageCountLabel;
      			this._updateToolbar();
      		}, err => {
      			zk.error(err.message);
      			this._destroyPdf();
      			this._cleanContent();
      		});
      	},
      

      Current Result

       

      1 Errors
      Cannot read property 'style' of undefined
      
      zkex.pdfviewer.wpd:652 Uncaught (in promise) TypeError: Cannot set property 'max' of undefined
          at zkex.pdfviewer.wpd:652
      (anonymous) @ zkex.pdfviewer.wpd:652
      Promise.then (async)
      _loadPdf @ zkex.pdfviewer.wpd:652
      bind_ @ zkex.pdfviewer.wpd:652
      bindChildren_ @ zk.wpd:503
      bind_ @ zk.wpd:502
      bind @ zk.wpd:501
      replaceChildHTML_ @ zk.wpd:497
      replaceHTML @ zk.wpd:494
      p @ zk.wpd:571
      r @ zk.wpd:570
      d @ zk.wpd:562
      _zkf @ zk.wpd:563
      (anonymous) @ zkex.pdfviewer.wpd:665
      d @ zk.wpd:562
      _zkf @ zk.wpd:563
      (anonymous) @ zkex.pdfviewer.wpd:665
      

      Expected Result

       No error

      Debug Information

       during:

      _loadPdf(src: string) {
      		this._destroyPdf();
      		PDFJS.getDocument(src).promise.then(pdf => {
      			let pageCount = pdf.numPages,
      				pageCountLabel = '' + pageCount;
      			this._pdf = pdf;
      			this._pageCount = pageCount;
      			this._getPage(this._getDisplayedPageNumber(), true);
      			(this.$n('toolbar-page-active') as HTMLInputElement).max = pageCountLabel;
      			this.$n('toolbar-page-total').textContent = pageCountLabel;
      			this._updateToolbar();
      		}, err => {
      			zk.error(err.message);
      			this._destroyPdf();
      			this._cleanContent();
      		});
      	},
      

      The promise callback can be reached when the component has already been detached.

      this cause this.$n('toolbar-page-active') and this.$n('toolbar-page-total') to return null, cause error.

      Workaround

       

            rudyhuang rudyhuang
            MDuchemin MDuchemin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 4 hours
                4h
                Remaining:
                Remaining Estimate - 4 hours
                4h
                Logged:
                Time Spent - Not Specified
                Not Specified