mirror of
https://github.com/penpot/penpot.git
synced 2026-11-26 21:00:32 +00:00
🐛 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
This commit is contained in:
parent
0498c68b5b
commit
5c768aeca0
@ -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
|
||||
|
||||
45
frontend/test/frontend_tests/render_wasm/fonts_test.cljs
Normal file
45
frontend/test/frontend_tests/render_wasm/fonts_test.cljs
Normal file
@ -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?)))))
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user