From 5c768aeca0b8b968b9a1e703d65908d0a323e71d Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Mon, 23 Nov 2026 12:01:10 +0100 Subject: [PATCH] :bug: Skip WASM font checks while the renderer is not live (#13235) Page switches tear down the WebGL canvas before openPage resolves, so font-stored? must not call _is_font_uploaded against a null resource pool. Guard with wasm/live? like the other font FFI helpers, and cover the skip path with a unit test. Closes #13205 --- frontend/src/app/render_wasm/api/fonts.cljs | 22 +++++---- .../render_wasm/fonts_test.cljs | 45 +++++++++++++++++++ frontend/test/frontend_tests/runner.cljs | 2 + 3 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 frontend/test/frontend_tests/render_wasm/fonts_test.cljs diff --git a/frontend/src/app/render_wasm/api/fonts.cljs b/frontend/src/app/render_wasm/api/fonts.cljs index 0575c549bb..af35227da4 100644 --- a/frontend/src/app/render_wasm/api/fonts.cljs +++ b/frontend/src/app/render_wasm/api/fonts.cljs @@ -265,16 +265,20 @@ (dm/str (u/join cf/public-uri "fonts/" asset-id)))) (defn font-stored? + "True when the face is already in the WASM font store. Returns nil/false + while the GL/WASM context is not live (e.g. mid page-switch teardown), so + callers never hit `_is_font_uploaded` against a null resource pool." [font-data emoji?] - (when-let [id-buffer (uuid/get-u32 (:wasm-id font-data))] - (not= 0 (h/call wasm/internal-module "_is_font_uploaded" - (aget id-buffer 0) - (aget id-buffer 1) - (aget id-buffer 2) - (aget id-buffer 3) - (:weight font-data) - (:style font-data) - emoji?)))) + (when (wasm/live?) + (when-let [id-buffer (uuid/get-u32 (:wasm-id font-data))] + (not= 0 (h/call wasm/internal-module "_is_font_uploaded" + (aget id-buffer 0) + (aget id-buffer 1) + (aget id-buffer 2) + (aget id-buffer 3) + (:weight font-data) + (:style font-data) + emoji?))))) (defn font-failed? "Returns true when the face behind `font-key` failed to load, so WASM lays diff --git a/frontend/test/frontend_tests/render_wasm/fonts_test.cljs b/frontend/test/frontend_tests/render_wasm/fonts_test.cljs new file mode 100644 index 0000000000..a84c84997c --- /dev/null +++ b/frontend/test/frontend_tests/render_wasm/fonts_test.cljs @@ -0,0 +1,45 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; Copyright (c) KALEIDOS SUBSIDIARY SL + +(ns frontend-tests.render-wasm.fonts-test + "font-stored? must not call into WASM while the GL context is not live + (page-switch teardown), otherwise `_is_font_uploaded` aborts on a null + resource pool (#13205)." + (:require + [app.common.render-wasm.wasm :as wasm] + [app.common.uuid :as uuid] + [app.render-wasm.api.fonts :as fonts] + [cljs.test :as t :include-macros true])) + +(defn- font-data + [] + {:wasm-id (uuid/next) + :weight 400 + :style 0}) + +(defn- module-with-is-font-uploaded + [on-call] + #js {"_is_font_uploaded" (fn [& args] + (on-call args) + 1)}) + +(t/deftest font-stored-skips-wasm-when-not-live + (let [called? (atom false) + module (module-with-is-font-uploaded + (fn [_] (reset! called? true)))] + (with-redefs [wasm/live? (constantly false) + wasm/internal-module module] + (t/is (nil? (fonts/font-stored? (font-data) false))) + (t/is (false? @called?))))) + +(t/deftest font-stored-queries-wasm-when-live + (let [called? (atom false) + module (module-with-is-font-uploaded + (fn [_] (reset! called? true)))] + (with-redefs [wasm/live? (constantly true) + wasm/internal-module module] + (t/is (true? (fonts/font-stored? (font-data) false))) + (t/is (true? @called?))))) diff --git a/frontend/test/frontend_tests/runner.cljs b/frontend/test/frontend_tests/runner.cljs index 9fd10acc04..465fa50050 100644 --- a/frontend/test/frontend_tests/runner.cljs +++ b/frontend/test/frontend_tests/runner.cljs @@ -117,6 +117,7 @@ [frontend-tests.plugins.value-objects-test] [frontend-tests.plugins.wait-for-save-test] [frontend-tests.render-dimensions-test] + [frontend-tests.render-wasm.fonts-test] [frontend-tests.render-wasm.process-objects-test] [frontend-tests.render-wasm.serialization-test] [frontend-tests.render-wasm.shape-proxy-test] @@ -330,6 +331,7 @@ 'frontend-tests.plugins.utils-test 'frontend-tests.plugins.value-objects-test 'frontend-tests.plugins.wait-for-save-test + 'frontend-tests.render-wasm.fonts-test 'frontend-tests.render-wasm.process-objects-test 'frontend-tests.render-wasm.serialization-test 'frontend-tests.render-wasm.shape-proxy-test