Alejandro Alonso 5c768aeca0
🐛 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
2026-11-23 12:01:10 +01:00

46 lines
1.6 KiB
Clojure

;; 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?)))))