0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-12 10:09:03 -05:00

🐛 Avoid extra render calls on page initialization with wasm render (#5701)

This commit is contained in:
Alejandro 2025-01-29 10:50:27 +01:00 committed by GitHub
parent 979de39768
commit ce67550195
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 13 deletions

View file

@ -133,6 +133,7 @@
frame-hover (mf/use-state nil)
active-frames (mf/use-state #{})
canvas-init? (mf/use-state false)
initialized? (mf/use-state false)
;; REFS
[viewport-ref
@ -293,23 +294,28 @@
(wasm.api/resize-viewbox (:width vport) (:height vport))))
(mf/with-effect [@canvas-init? base-objects]
(when @canvas-init?
(when (and @canvas-init? @initialized?)
(wasm.api/set-objects base-objects)))
(mf/with-effect [@canvas-init? preview-blend]
(when (and @canvas-init? preview-blend)
(wasm.api/request-render "with-effect")))
(mf/with-effect [@canvas-init? vbox]
(when @canvas-init?
(mf/with-effect [@canvas-init? zoom vbox background]
(when (and @canvas-init? (not @initialized?))
(wasm.api/initialize base-objects zoom vbox background)
(reset! initialized? true)))
(mf/with-effect [vbox]
(when (and @canvas-init? initialized?)
(wasm.api/set-view-zoom zoom vbox)))
(mf/with-effect [@canvas-init? vbox]
(when @canvas-init?
(mf/with-effect [vbox]
(when (and @canvas-init? initialized?)
(wasm.api/set-view-box zoom vbox)))
(mf/with-effect [@canvas-init? background]
(when @canvas-init?
(mf/with-effect [background]
(when (and @canvas-init? initialized?)
(wasm.api/set-canvas-background background)))
(hooks/setup-dom-events zoom disable-paste in-viewport? read-only? drawing-tool drawing-path?)

View file

@ -573,6 +573,19 @@
(rx/reduce conj [])
(rx/subs! request-render)))))
(defn set-canvas-background
[background]
(let [rgba (rgba-from-hex background 1)]
(h/call internal-module "_set_canvas_background" rgba)
(request-render "set-canvas-background")))
(defn initialize
[base-objects zoom vbox background]
(let [rgba (rgba-from-hex background 1)]
(h/call internal-module "_set_canvas_background" rgba)
(h/call internal-module "_set_view" zoom (- (:x vbox)) (- (:y vbox)))
(set-objects base-objects)))
(def ^:private canvas-options
#js {:antialias false
:depth true
@ -610,11 +623,6 @@
;; TODO: perform corresponding cleaning
(h/call internal-module "_clean_up"))
(defn set-canvas-background
[background]
(let [rgba (rgba-from-hex background 1)]
(h/call internal-module "_set_canvas_background" rgba)))
(defonce module
(delay
(if (exists? js/dynamicImport)

View file

@ -67,6 +67,5 @@ impl<'a> State<'a> {
pub fn set_background_color(&mut self, color: skia::Color) {
self.render_state.set_background_color(color);
self.render_all(true);
}
}