Skip to content

Commit 48a7864

Browse files
committed
Render main styesheet with reagent, not dom interop
Fixes #410
1 parent e91ea89 commit 48a7864

File tree

6 files changed

+22
-18
lines changed

6 files changed

+22
-18
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Change Log
22
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/).
33

4+
## 1.9.7 (2024-02-02)
5+
6+
#### Fixed
7+
8+
- Pop-out window no longer crashes. See #410.
9+
410
## 1.9.6 (2024-02-02)
511

612
#### Fixed

src/day8/re_frame_10x.cljs

+9-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
[day8.re-frame-10x.components.re-com :as rc]
1515
[day8.re-frame-10x.navigation.views :as container]
1616
[day8.re-frame-10x.panels.settings.subs :as settings.subs]
17-
[day8.re-frame-10x.panels.settings.events :as settings.events]))
17+
[day8.re-frame-10x.panels.settings.events :as settings.events])
18+
(:require-macros [day8.re-frame-10x.components.re-com :refer [inline-resource]]))
1819

1920
(goog-define debug? false)
2021

@@ -128,15 +129,17 @@
128129
(defn ^:export handle-keys! [handle-keys?]
129130
(rf/dispatch [::settings.events/handle-keys? handle-keys?]))
130131

131-
(defn create-shadow-root [css-str]
132-
(tools.shadow-dom/shadow-root js/document "--re-frame-10x--" css-str))
132+
(defn create-shadow-root []
133+
(tools.shadow-dom/shadow-root js/document "--re-frame-10x--"))
133134

134135
(defn create-style-container [shadow-root]
135136
[spade.react/with-style-container
136137
(spade.dom/create-container shadow-root)
137-
[devtools-outer
138-
{:panel-type :inline
139-
:debug? debug?}]])
138+
[:<>
139+
[:style (inline-resource "day8/re_frame_10x/style.css")]
140+
[devtools-outer
141+
{:panel-type :inline
142+
:debug? debug?}]]])
140143

141144
(defn patch!
142145
"Sets up any initial state that needs to be there for tracing. Does not enable tracing."

src/day8/re_frame_10x/navigation/views.cljs

+3-1
Original file line numberDiff line numberDiff line change
@@ -434,5 +434,7 @@
434434
:component-will-unmount unmount
435435
:reagent-render (fn []
436436
[spade.react/with-style-container spade-container
437-
[devtools-inner {:panel-type :popup}]])})]
437+
[:<>
438+
[:style (inline-resource "day8/re_frame_10x/style.css")]
439+
[devtools-inner {:panel-type :popup}]]])})]
438440
shadow-root)))

src/day8/re_frame_10x/preload/react_17.cljs

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
[day8.re-frame-10x :as re-frame-10x]
1010
[day8.re-frame-10x.inlined-deps.reagent.v1v2v0.reagent.dom :as rdom]
1111
[day8.re-frame-10x.inlined-deps.re-frame.v1v3v0.re-frame.core :as rf]
12-
[day8.re-frame-10x.events :as events])
13-
(:require-macros [day8.re-frame-10x.components.re-com :refer [inline-resource]]))
12+
[day8.re-frame-10x.events :as events]))
1413

1514
(let [react-major-version (first (str/split react/version #"\."))]
1615
(when-not (= "17" react-major-version)
@@ -26,7 +25,7 @@
2625

2726
(rf/clear-subscription-cache!)
2827

29-
(def shadow-root (re-frame-10x/create-shadow-root (inline-resource "day8/re_frame_10x/style.css")))
28+
(def shadow-root (re-frame-10x/create-shadow-root))
3029

3130
(rdom/render (re-frame-10x/create-style-container shadow-root)
3231
shadow-root)

src/day8/re_frame_10x/preload/react_18.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
(rf/clear-subscription-cache!)
2222

23-
(def shadow-root (re-frame-10x/create-shadow-root (inline-resource "day8/re_frame_10x/style.css")))
23+
(def shadow-root (re-frame-10x/create-shadow-root))
2424

2525
(rdc/render (rdc/create-root shadow-root)
2626
(re-frame-10x/create-style-container shadow-root))

src/day8/re_frame_10x/tools/shadow_dom.cljs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
(ns day8.re-frame-10x.tools.shadow-dom)
22

3-
(defn attach-stylesheet [shadow-root css-str]
4-
(let [stylesheet (js/CSSStyleSheet.)
5-
_ (.replaceSync stylesheet css-str)]
6-
(set! (.-adoptedStyleSheets shadow-root) (js/Array. stylesheet))))
7-
83
(defn shadow-root
94
"Creates a new div element with the id attached to the js-document <body>,
105
attaches a shadow DOM tree and returns a reference to its ShadowRoot."
11-
[js-document id css-str]
6+
[js-document id]
127
(let [container (.getElementById js-document id)]
138
(if container
149
(.-shadowRoot container)
1510
(let [body (.-body js-document)
1611
container (.createElement js-document "div")
1712
shadow-root (.attachShadow container #js {:mode "open"})]
18-
(attach-stylesheet shadow-root css-str)
1913
(.setAttribute container "id" id)
2014
(.appendChild body container)
2115
(js/window.focus container)

0 commit comments

Comments
 (0)