diff --git a/frontend/src/app/main.cljs b/frontend/src/app/main.cljs index c317c8555f..a02499065f 100644 --- a/frontend/src/app/main.cljs +++ b/frontend/src/app/main.cljs @@ -16,6 +16,7 @@ [app.main.data.profile :as dp] [app.main.data.websocket :as ws] [app.main.errors] + [app.main.features :as feat] [app.main.rasterizer :as thr] [app.main.store :as st] [app.main.ui :as ui] @@ -87,7 +88,12 @@ (rx/map deref) (rx/filter dp/is-authenticated?) (rx/take 1) - (rx/map #(ws/initialize))))))) + (rx/map #(ws/initialize))))) + + ptk/EffectEvent + (effect [_ state _] + (when-not (feat/active-feature? state "render-wasm/v1") + (thr/init!))))) (defn ^:export init [options] @@ -97,7 +103,7 @@ (mw/init!) (i18n/init) (cur/init-styles) - (thr/init!) + (init-ui) (st/emit! (plugins/initialize) (initialize))) diff --git a/frontend/src/app/main/data/workspace/pages.cljs b/frontend/src/app/main/data/workspace/pages.cljs index 5b91d10864..5865cb969d 100644 --- a/frontend/src/app/main/data/workspace/pages.cljs +++ b/frontend/src/app/main/data/workspace/pages.cljs @@ -105,9 +105,15 @@ (if (dsh/lookup-page state file-id page-id) (rx/concat (rx/of (initialize-page* file-id page-id) - (fdf/fix-deleted-fonts-for-page file-id page-id) - (dwth/watch-state-changes file-id page-id) - (dwl/watch-component-changes)) + (fdf/fix-deleted-fonts-for-page file-id page-id)) + + ;; Disable thumbnail generation in wasm renderer + (if (features/active-feature? state "render-wasm/v1") + (rx/empty) + (rx/of (dwth/watch-state-changes file-id page-id))) + + (rx/of (dwl/watch-component-changes)) + (let [profile (:profile state) props (get profile :props)] (when (not (:workspace-visited props)) diff --git a/frontend/src/app/main/data/workspace/thumbnails.cljs b/frontend/src/app/main/data/workspace/thumbnails.cljs index a8ff8fedf9..5edab10c27 100644 --- a/frontend/src/app/main/data/workspace/thumbnails.cljs +++ b/frontend/src/app/main/data/workspace/thumbnails.cljs @@ -191,59 +191,63 @@ [page-id [event [old-data new-data]]] (let [changes (:changes event) - lookup-data-objects - (fn [data page-id] - (dm/get-in data [:pages-index page-id :objects])) + ;; cache for the get-frame-ids function + frame-id-cache (atom {})] + (letfn [(lookup-data-objects [data page-id] + (dm/get-in data [:pages-index page-id :objects])) - extract-ids - (fn [{:keys [page-id type] :as change}] - (case type - :add-obj [[page-id (:id change)]] - :mod-obj [[page-id (:id change)]] - :del-obj [[page-id (:id change)]] - :mov-objects (->> (:shapes change) (map #(vector page-id %))) - [])) + (extract-ids [{:keys [page-id type] :as change}] + (case type + :add-obj [[page-id (:id change)]] + :mod-obj [[page-id (:id change)]] + :del-obj [[page-id (:id change)]] + :mov-objects (->> (:shapes change) (map #(vector page-id %))) + [])) - get-frame-ids - (fn get-frame-ids [id] - (let [old-objects (lookup-data-objects old-data page-id) - new-objects (lookup-data-objects new-data page-id) + (get-frame-ids [id] + (let [old-objects (lookup-data-objects old-data page-id) + new-objects (lookup-data-objects new-data page-id) - new-shape (get new-objects id) - old-shape (get old-objects id) + new-shape (get new-objects id) + old-shape (get old-objects id) - old-frame-id (if (cfh/frame-shape? old-shape) id (:frame-id old-shape)) - new-frame-id (if (cfh/frame-shape? new-shape) id (:frame-id new-shape)) + old-frame-id (if (cfh/frame-shape? old-shape) id (:frame-id old-shape)) + new-frame-id (if (cfh/frame-shape? new-shape) id (:frame-id new-shape)) - root-frame-old? (cfh/root-frame? old-objects old-frame-id) - root-frame-new? (cfh/root-frame? new-objects new-frame-id) - instance-root? (ctc/instance-root? new-shape)] + root-frame-old? (cfh/root-frame? old-objects old-frame-id) + root-frame-new? (cfh/root-frame? new-objects new-frame-id) + instance-root? (ctc/instance-root? new-shape)] - (cond-> #{} - root-frame-old? - (conj ["frame" old-frame-id]) + (cond-> #{} + root-frame-old? + (conj ["frame" old-frame-id]) - root-frame-new? - (conj ["frame" new-frame-id]) + root-frame-new? + (conj ["frame" new-frame-id]) - instance-root? - (conj ["component" id]) + instance-root? + (conj ["component" id]) - (and (uuid? (:frame-id old-shape)) - (not= uuid/zero (:frame-id old-shape))) - (into (get-frame-ids (:frame-id old-shape))) + (and (uuid? (:frame-id old-shape)) + (not= uuid/zero (:frame-id old-shape))) + (into (get-frame-ids (:frame-id old-shape))) - (and (uuid? (:frame-id new-shape)) - (not= uuid/zero (:frame-id new-shape))) - (into (get-frame-ids (:frame-id new-shape))))))] + (and (uuid? (:frame-id new-shape)) + (not= uuid/zero (:frame-id new-shape))) + (into (get-frame-ids (:frame-id new-shape)))))) - (into #{} - (comp (mapcat extract-ids) - (filter (fn [[page-id']] (= page-id page-id'))) - (map (fn [[_ id]] id)) - (mapcat get-frame-ids)) - changes))) + (get-frame-ids-cached [id] + (or (get @frame-id-cache id) + (let [result (get-frame-ids id)] + (swap! frame-id-cache assoc id result) + result)))] + (into #{} + (comp (mapcat extract-ids) + (filter (fn [[page-id']] (= page-id page-id'))) + (map (fn [[_ id]] id)) + (mapcat get-frame-ids-cached)) + changes)))) (defn watch-state-changes "Watch the state for changes inside frames. If a change is detected will force a rendering diff --git a/frontend/src/app/main/rasterizer.cljs b/frontend/src/app/main/rasterizer.cljs index 6fcb4dc8a8..3c03bede59 100644 --- a/frontend/src/app/main/rasterizer.cljs +++ b/frontend/src/app/main/rasterizer.cljs @@ -108,6 +108,7 @@ "Initializes the rasterizer." [] (let [iframe (dom/create-element "iframe")] + (dom/set-attribute! iframe "id" "rasterizer") (dom/set-attribute! iframe "src" origin) (dom/set-attribute! iframe "hidden" true) (.addEventListener js/window "message" on-message)