Fix pdf.js rendering pages in the wrong order

There was an implicit assumption that the pages returned from the
Promise of `pdf.getPage(num)` would return in order, but no such
guarantee exists. To handle this, we explicitly set which array index
based on the page number and then trigger a Vue update via `splice`.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/64467
This commit is contained in:
Stan Hu 2019-07-28 08:06:59 -07:00 committed by Lukas Eipert
parent dbe3b9848b
commit 6d3b203dd8
No known key found for this signature in database
GPG Key ID: 148BEA37CB35B2AC
2 changed files with 12 additions and 1 deletions

View File

@ -40,6 +40,8 @@ export default {
.then(() => this.$emit('pdflabload'))
.catch(error => this.$emit('pdflaberror', error))
.then(() => {
// Trigger a Vue update: https://vuejs.org/v2/guide/list.html#Caveats
this.pages.splice(this.pages.length);
this.loading = false;
});
},
@ -47,7 +49,11 @@ export default {
const pagePromises = [];
this.loading = true;
for (let num = 1; num <= pdf.numPages; num += 1) {
pagePromises.push(pdf.getPage(num).then(p => this.pages.push(p)));
pagePromises.push(
pdf.getPage(num).then(p => {
this.pages[p.pageIndex] = p;
}),
);
}
return Promise.all(pagePromises);
},

View File

@ -0,0 +1,5 @@
---
title: Fix pdf.js rendering pages in the wrong order
merge_request: 31222
author:
type: fixed