Merge pull request #4083 from overleaf/bg-avoid-multiple-pdf-renders-on-loading

ignore pdf rendering before loading has completed

GitOrigin-RevId: 3ad435507045decf49c3678abe3bfadd07d0cbca
This commit is contained in:
Jakob Ackermann 2021-05-21 13:32:59 +02:00 committed by Copybot
parent 8f0a0439cd
commit fa914af56c

View file

@ -44,7 +44,9 @@ App.controller(
// prevent race conditions) // prevent race conditions)
const documentTearDown = const documentTearDown =
$scope.document != null ? $scope.document.destroy() : Promise.resolve() $scope.document != null ? $scope.document.destroy() : Promise.resolve()
// Keep track of whether the pdf has loaded (this allows rescale events to
// be ignored until we are ready to render the pdf).
$scope.isLoaded = false
return documentTearDown.then(() => { return documentTearDown.then(() => {
$scope.loadCount = $scope.loadCount != null ? $scope.loadCount + 1 : 1 $scope.loadCount = $scope.loadCount != null ? $scope.loadCount + 1 : 1
// TODO need a proper url manipulation library to add to query string // TODO need a proper url manipulation library to add to query string
@ -108,6 +110,8 @@ App.controller(
] ]
// console.log 'resolved q.all, page size is', result // console.log 'resolved q.all, page size is', result
$scope.$emit('loaded') $scope.$emit('loaded')
// we can now render the document and handle rescale events
$scope.isLoaded = true
return ($scope.numPages = result.numPages) return ($scope.numPages = result.numPages)
}) })
.catch(function (error) { .catch(function (error) {
@ -399,6 +403,9 @@ export default App.directive('pdfViewer', ($q, $timeout, pdfSpinner) => ({
let rescaleTimer = null let rescaleTimer = null
const queueRescale = function (scale) { const queueRescale = function (scale) {
// console.log 'call to queueRescale' // console.log 'call to queueRescale'
if (!scope.isLoaded) {
return // ignore any requests to rescale before the document is loaded
}
if (rescaleTimer != null || layoutTimer != null || elementTimer != null) { if (rescaleTimer != null || layoutTimer != null || elementTimer != null) {
return return
} }