From f2e7eee00ed60560fbd895da1b26db732194736d Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 26 May 2024 18:28:26 +0200 Subject: [PATCH] Don't register a pending `TextLayer` until `render` is invoked (PR 18104 follow-up) After the re-factoring in PR 18104 there's now a *theoretical* risk that a pending `TextLayer` is never removed, which we can avoid by not registering it until `render` is invoked. Note that this doesn't affect the viewer or tests, but if a third-party user calls `new TextLayer(...)` without a following call of either the `render`- or `cancel`-method we'd block global clean-up without this patch. --- src/display/text_layer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/display/text_layer.js b/src/display/text_layer.js index 1c0d247779131..1ff8ac26b5e6e 100644 --- a/src/display/text_layer.js +++ b/src/display/text_layer.js @@ -122,7 +122,6 @@ class TextLayer { setLayerDimensions(container, viewport); - TextLayer.#pendingTextLayers.add(this); // Always clean-up the temporary canvas once rendering is no longer pending. this.#capability.promise .catch(() => { @@ -167,6 +166,7 @@ class TextLayer { }, this.#capability.reject); }; this.#reader = this.#textContentSource.getReader(); + TextLayer.#pendingTextLayers.add(this); pump(); return this.#capability.promise; @@ -423,6 +423,7 @@ class TextLayer { return; } this.#ascentCache.clear(); + for (const { canvas } of this.#canvasContexts.values()) { canvas.remove(); }