From 88e55af526990264a3bae3091cab173ecd4458e7 Mon Sep 17 00:00:00 2001 From: CanadaHonk Date: Wed, 8 Nov 2023 23:34:31 +0000 Subject: [PATCH] layout: improve perf of text-align hack --- engine/layout.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/engine/layout.js b/engine/layout.js index 1357d2b..32db03f 100644 --- a/engine/layout.js +++ b/engine/layout.js @@ -997,11 +997,14 @@ export class LayoutNode extends Node { if (this.isInline() && this.css()['text-align'] !== 'left') { // hack: align next time as we cannot compute our own width here if (!this.cache._alignWidth) { - setTimeout(() => { - this.cache._alignWidth = this.totalWidth(); - this.cache._alignWidthParent = this.parent.contentWidth(); - this.invalidateCaches(false, ['_alignWidth', '_alignWidthParent']); - }, 0); + if (this.cache._alignWidth === undefined) { + this.cache._alignWidth = null; + setTimeout(() => { + this.cache._alignWidth = this.totalWidth(); + this.cache._alignWidthParent = this.parent.contentWidth(); + this.invalidateCaches(false, ['_alignWidth', '_alignWidthParent']); + }, 0); + } return this._alignTmp ?? -9999; }