🐛 Fix viewer wasm position data init (#10805)

This commit is contained in:
Alejandro Alonso 2026-07-23 12:58:20 +02:00 committed by GitHub
parent b6629c0034
commit 8bf411c347
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 5 deletions

View File

@ -222,7 +222,12 @@
(watch [_ state _]
(if (and (features/active-feature? state "render-wasm/v1")
(contains? cf/flags :available-viewer-wasm))
(let [objects (dsh/lookup-page-objects state file-id page-id)
;; Fallback matches the viewer UI when the URL omits page-id.
(let [page-id (or page-id
(-> (dsh/lookup-file-data state file-id)
:pages
first))
objects (dsh/lookup-page-objects state file-id page-id)
shapes
(reduce-kv
@ -233,13 +238,12 @@
[]
objects)
;; Creates a stream from the async callback. This stream will only
;; emit one single value after the objects have finished loading
;; in the wasm memory.
;; Positive size required: OffscreenCanvas(0, 0) crashes
;; `_set_render_options` on some browsers.
set-objects-stream
(rx/create
(fn [subs]
(wasm.api/init-canvas-context (js/OffscreenCanvas. 0 0))
(wasm.api/init-canvas-context (js/OffscreenCanvas. 64 64))
(wasm.api/set-objects-callback shapes #(rx/push! subs :done))
nil))]

View File

@ -2175,6 +2175,9 @@
browser (sr/translate-browser cf/browser)
dpr (get-dpr)
[css-w css-h] (canvas-css-size canvas dpr)
;; Avoid 0×0 Skia/GL surfaces (crashes on some browsers).
css-w (mth/max 1 css-w)
css-h (mth/max 1 css-h)
can-listen? (fn? (.-addEventListener ^js canvas))]
(when-not (nil? context)
(let [handle (.registerContext ^js gl context #js {"majorVersion" 2})]