Commit 6d3b203d authored by Stan Hu's avatar Stan Hu Committed by Lukas Eipert

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
parent dbe3b984
...@@ -40,6 +40,8 @@ export default { ...@@ -40,6 +40,8 @@ export default {
.then(() => this.$emit('pdflabload')) .then(() => this.$emit('pdflabload'))
.catch(error => this.$emit('pdflaberror', error)) .catch(error => this.$emit('pdflaberror', error))
.then(() => { .then(() => {
// Trigger a Vue update: https://vuejs.org/v2/guide/list.html#Caveats
this.pages.splice(this.pages.length);
this.loading = false; this.loading = false;
}); });
}, },
...@@ -47,7 +49,11 @@ export default { ...@@ -47,7 +49,11 @@ export default {
const pagePromises = []; const pagePromises = [];
this.loading = true; this.loading = true;
for (let num = 1; num <= pdf.numPages; num += 1) { 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); return Promise.all(pagePromises);
}, },
......
---
title: Fix pdf.js rendering pages in the wrong order
merge_request: 31222
author:
type: fixed
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment