penpot/frontend/src/app/plugins.cljs
Andrey Antukh 57b9b8463b
🐛 Keep app booting when SES bootstrap fails (#13085)
* 🐛 Keep app booting when SES bootstrap fails

Wrap repairIntrinsics in a guarded bootstrap so a SES Temporal check failure
no longer aborts bundle evaluation and blanks the whole app. When it fails,
plugins and MCP stay unavailable for that session, a telemetry event reports
the error, and trying to open a plugin shows an environment warning.

Add vitest coverage for both bootstrap paths and a CLJS regression test for
the runtime-unavailable toast.

Closes #12924

AI-assisted-by: hy4-flash-free

* 🐛 Fix CI format check and plugin test entry point

Wrap the long Prettier line in bootstrap.spec.ts so `pnpm run format:check`
passes again in the plugins module, and document that the duplicated SES
options are an intentional contract snapshot.

Switch the runtime-unavailable CLJS test to the public open-plugin! entry
point instead of the private load-plugin! function. The M2 test for
signal-runtime-ready was dropped: loading app.plugins in the Node test
runner needs packaging and DOM shim changes outside this fix.

Closes #12924

AI-assisted-by: hy4-flash-free
2026-11-16 17:52:55 +01:00

71 lines
2.3 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 app.plugins
"RPC for plugins runtime."
(:require
["@penpot/plugins-runtime" :as runtime]
[app.main.data.event :as ev]
[app.main.errors :as errors]
[app.main.features :as features]
[app.main.store :as st]
[app.plugins.api :as api]
[app.plugins.flex :as flex]
[app.plugins.format :as format]
[app.plugins.grid :as grid]
[app.plugins.library :as library]
[app.plugins.public-utils]
[app.plugins.register :as preg]
[app.plugins.ruler-guides :as rg]
[app.plugins.shape :as shape]
[app.util.globals :as ug]
[beicon.v2.core :as rx]
[potok.v2.core :as ptk]))
(defn- runtime-available?
[]
(fn? (unchecked-get ug/global "ɵloadPlugin")))
(defn init-plugins-runtime
[]
(runtime/initPluginsRuntime (fn [plugin-id] (api/create-context plugin-id)))
;; Signal even when the runtime failed to start: MCP initialization waits
;; for this promise and would otherwise hang forever.
(preg/signal-runtime-ready)
(runtime-available?))
(defn- runtime-unavailable-event
[]
(ev/event {::ev/name "plugins-runtime-unavailable"
:message (some-> (runtime/getPluginsRuntimeError) .-message)}))
(defn initialize
[]
(ptk/reify ::initialize
ptk/WatchEvent
(watch [_ _ stream]
(set! errors/is-plugin-error? runtime/isPluginError)
(->> stream
(rx/filter (ptk/type? ::features/initialize))
(rx/observe-on :async)
(rx/filter #(features/active-feature? @st/state "plugins/runtime"))
(rx/take 1)
(rx/map (fn [_]
(when-not (init-plugins-runtime)
(runtime-unavailable-event))))
(rx/filter some?)))))
;; Prevent circular dependency
(set! flex/shape-proxy? shape/shape-proxy?)
(set! grid/shape-proxy? shape/shape-proxy?)
(set! format/shape-proxy shape/shape-proxy)
(set! rg/shape-proxy shape/shape-proxy)
(set! rg/shape-proxy? shape/shape-proxy?)
(set! shape/lib-typography-proxy? library/lib-typography-proxy?)
(set! shape/lib-component-proxy library/lib-component-proxy)