Skip to content

Commit 3dd8b9c

Browse files
committed
Ensure that setting the width of the zoom dropdown works correctly (PR 14028 follow-up)
We need to wait for UI rendering to start *before* getting the CSS variable values, since otherwise the values will be `NaN`. This is only an issue if the viewer is completely hidden during loading, e.g. in a `display: none` iframe-element.
1 parent 96b125f commit 3dd8b9c

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

web/toolbar.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class Toolbar {
170170

171171
this.eventBus._on("localized", () => {
172172
this._wasLocalized = true;
173-
this._adjustScaleWidth();
173+
this.#adjustScaleWidth();
174174
this._updateUIState(true);
175175
});
176176
}
@@ -237,9 +237,8 @@ class Toolbar {
237237
/**
238238
* Increase the width of the zoom dropdown DOM element if, and only if, it's
239239
* too narrow to fit the *longest* of the localized strings.
240-
* @private
241240
*/
242-
async _adjustScaleWidth() {
241+
async #adjustScaleWidth() {
243242
const { items, l10n } = this;
244243

245244
const predefinedValuesPromise = Promise.all([
@@ -248,6 +247,7 @@ class Toolbar {
248247
l10n.get("page_scale_fit"),
249248
l10n.get("page_scale_width"),
250249
]);
250+
await animationStarted;
251251

252252
const style = getComputedStyle(items.scaleSelect),
253253
scaleSelectContainerWidth = parseInt(
@@ -262,8 +262,6 @@ class Toolbar {
262262
// The temporary canvas is used to measure text length in the DOM.
263263
let canvas = document.createElement("canvas");
264264
let ctx = canvas.getContext("2d", { alpha: false });
265-
266-
await animationStarted;
267265
ctx.font = `${style.fontSize} ${style.fontFamily}`;
268266

269267
let maxWidth = 0;

0 commit comments

Comments
 (0)