Skip to content

Commit 5ee6546

Browse files
committed
Test against React 18 also
1 parent 1e5786c commit 5ee6546

File tree

5 files changed

+106
-30
lines changed

5 files changed

+106
-30
lines changed

.github/workflows/clojure.yml

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,33 @@ jobs:
88
strategy:
99
matrix:
1010
env:
11-
# React 19 is not available as UMD module
12-
# - browser-cljsjs
13-
# - browser-cljsjs-prod
11+
- browser-cljsjs
12+
- browser-cljsjs-prod
1413
- browser-npm
1514
- browser-npm-prod
1615
- bundle
1716
- bundle-adv
18-
# - node-cljsjs
17+
- node-cljsjs
1918
- node-npm
2019
- shadow-cljs-prod
20+
react:
21+
- 18
22+
- 19
23+
exclude:
24+
# React 19 is not available as UMD module
25+
- react: 19
26+
env: browser-cljsjs
27+
- react: 19
28+
env: browser-cljsjs-prod
29+
- react: 19
30+
env: node-cljsjs
2131

22-
name: Test ${{ matrix.env }}
32+
name: Test ${{ matrix.env }} on React ${{ matrix.react }}
2333

2434
runs-on: ubuntu-latest
2535
env:
2636
ENV: ${{ matrix.env }}
37+
REACT_VERSION: ${{ matrix.react }}
2738

2839
steps:
2940
- uses: actions/checkout@v4
@@ -38,10 +49,7 @@ jobs:
3849
lein: 2.9.10
3950
cli: latest
4051
- name: Setup Node.js
41-
uses: actions/setup-node@v4
42-
with:
43-
node-version: lts/hydrogen
44-
cache: 'npm'
52+
uses: actions/setup-node@v6
4553

4654
# setup-java cache only looks at pom.xml for the key
4755
- name: Cache m2
@@ -55,6 +63,11 @@ jobs:
5563
- name: Install node deps
5664
run: npm ci
5765

66+
# Note, react 18 doesn't get cached? Or might even mess up node cache
67+
- name: Setup React
68+
if: ${{ matrix.react == 18 }}
69+
70+
5871
- name: Run tests
5972
run: ./test-environments/${{ matrix.env }}/test.sh
6073

@@ -81,10 +94,7 @@ jobs:
8194
lein: 2.9.8
8295
cli: latest
8396
- name: Setup Node.js
84-
uses: actions/setup-node@v4
85-
with:
86-
node-version: lts/hydrogen
87-
cache: 'npm'
97+
uses: actions/setup-node@v6
8898

8999
# setup-java cache only looks at pom.xml for the key
90100
- name: Cache m2

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
{
22
"name": "@reagent-project/reagent",
33
"private": true,
4-
"dependencies": {},
54
"scripts": {
65
"start": "lein figwheel client-npm"
76
},
7+
"packageManager": "npm@^11",
8+
"engines": {
9+
"node": "24",
10+
"npm": "11"
11+
},
812
"devDependencies": {
913
"@cljs-oss/module-deps": "1.1.1",
1014
"karma": "6.4.4",
@@ -16,11 +20,11 @@
1620
"karma-sourcemap-loader": "0.4.0",
1721
"karma-webpack": "5.0.1",
1822
"md5-file": "5.0.0",
19-
"shadow-cljs": "3.2.1",
20-
"webpack": "5.102.0",
21-
"webpack-cli": "6.0.1",
2223
"prop-types": "15.8.1",
2324
"react": "19.2.0",
24-
"react-dom": "19.2.0"
25+
"react-dom": "19.2.0",
26+
"shadow-cljs": "3.2.1",
27+
"webpack": "5.102.0",
28+
"webpack-cli": "6.0.1"
2529
}
2630
}

test/reagenttest/testreagent.cljs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
[react :as react]
88
[reagent.core :as r]
99
[reagent.debug :as debug :refer [dev?]]
10-
[reagent.dom :as rdom]
1110
[reagent.dom.client :as rdomc]
1211
[reagent.dom.server :as server]
1312
[reagent.impl.component :as comp]
@@ -1474,7 +1473,7 @@
14741473
(is (= "counting 012" (.-innerText div)))
14751474

14761475
(when (dev?)
1477-
(is (string/blank? (string/join "\n" (reverse (:error @debug/warnings)))))))
1476+
(is (string/blank? (string/join "\n" (reverse (remove #(string/starts-with? % "Warning: ReactDOM.render is no longer supported in React 18.") (:error @debug/warnings))))))))
14781477

14791478
(testing "after unmount ratom watches are cleaned"
14801479
(is (= {} (.-watches ^clj numbers)))
@@ -1511,7 +1510,7 @@
15111510
(is (= "counting 01" (.-innerText div)))
15121511

15131512
(when (dev?)
1514-
(is (string/blank? (string/join "\n" (reverse (:error @debug/warnings)))))))
1513+
(is (string/blank? (string/join "\n" (reverse (remove #(string/starts-with? % "Warning: ReactDOM.render is no longer supported in React 18.") (:error @debug/warnings))))))))
15151514

15161515
(testing "after unmount ratom watches are cleaned"
15171516
(is (= {} (.-watches ^clj numbers)))

test/reagenttest/utils.cljs

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
(ns reagenttest.utils
22
(:require-macros reagenttest.utils)
3-
(:require [promesa.core :as p]
3+
(:require ["react" :as react]
4+
[promesa.core :as p]
45
[reagent.core :as r]
56
[reagent.debug :as debug]
6-
[reagent.dom.server :as server]
77
[reagent.dom.client :as rdomc]
8-
[reagent.impl.template :as tmpl]))
8+
[reagent.dom.server :as server]
9+
[reagent.impl.template :as tmpl]
10+
[reagent.dom :as rdom]))
911

10-
;; Should be only set for tests....
11-
;; (set! (.-IS_REACT_ACT_ENVIRONMENT js/window) true)
12+
(def OLD-REACT (<= (js/parseInt react/version) 18))
1213

1314
(when-not (.-wrapped (.-error js/console))
1415
(let [original-console-error (.-error js/console)]
1516
(set! (.-error js/console)
1617
(fn [& [first-arg :as args]]
1718
(cond
19+
(and OLD-REACT (string? first-arg) (.startsWith first-arg "Warning: ReactDOM.render is no longer supported in React 18."))
20+
nil
21+
1822
(and (string? first-arg) (.startsWith first-arg "Warning: The current testing environment is not configured to support"))
1923
nil
2024

@@ -113,27 +117,73 @@
113117
(catch :default e
114118
(reject e))))))
115119

116-
(defn with-render*
120+
(def ^:dynamic *render-error* nil)
121+
122+
(defn old-with-render*
117123
"Run initial render and wait for the component to be mounted on the dom and then run
118124
given function to check the results. If the function
119125
also returns a Promise or thenable, this function
120126
waits until that is resolved, before unmounting the
121127
root and resolving the Promise this function returns."
122128
([comp f]
123-
(with-render* comp *test-compiler* f))
129+
(old-with-render* comp *test-compiler* f))
124130
([comp options f]
125131
(let [div (.createElement js/document "div")
126132
first-render (p/deferred)
127133
callback (fn []
128134
(p/resolve! first-render))
129135
compiler (:compiler options)
130-
strict? (:strict? options)
131136
restore-error-handlers (when (:capture-errors options)
132137
(init-capture))
133-
root (rdomc/create-root div)
134138
;; Magic setup to make exception from render available to the
135139
;; with-render body.
136140
render-error (atom nil)]
141+
(try
142+
(if compiler
143+
(rdom/render comp div {:compiler compiler
144+
:callback callback})
145+
(rdom/render comp div callback))
146+
(catch :default e
147+
(reset! render-error e)
148+
nil))
149+
(-> (act* (fn [] first-render))
150+
;; The callback is called even if render throws an error,
151+
;; so this is always resolved.
152+
(p/then (fn []
153+
(p/do
154+
(set! *render-error* @render-error)
155+
(f div)
156+
(set! *render-error* nil))))
157+
;; If f throws more errors, just ignore them?
158+
;; Not sure if this makes sense.
159+
(p/catch (fn [] nil))
160+
(p/then (fn []
161+
(rdom/unmount-component-at-node div)
162+
;; Need to wait for reagent tick after unmount
163+
;; for the ratom watches to be removed?
164+
(let [ratoms-cleaned (p/deferred)]
165+
(r/next-tick (fn []
166+
(p/resolve! ratoms-cleaned)))
167+
ratoms-cleaned)))
168+
(p/finally (fn []
169+
(when restore-error-handlers
170+
(restore-error-handlers))))))))
171+
172+
(defn new-with-render*
173+
"Run initial render and wait for the component to be mounted on the dom and then run
174+
given function to check the results. If the function
175+
also returns a Promise or thenable, this function
176+
waits until that is resolved, before unmounting the
177+
root and resolving the Promise this function returns."
178+
([comp f]
179+
(new-with-render* comp *test-compiler* f))
180+
([comp options f]
181+
(let [div (.createElement js/document "div")
182+
compiler (:compiler options)
183+
strict? (:strict? options)
184+
restore-error-handlers (when (:capture-errors options)
185+
(init-capture))
186+
root (rdomc/create-root div)]
137187
(-> (act* (fn []
138188
(rdomc/render root comp compiler strict?)))
139189
;; The callback is called even if render throws an error,
@@ -151,3 +201,5 @@
151201
(p/finally (fn []
152202
(when restore-error-handlers
153203
(restore-error-handlers))))))))
204+
205+
(def with-render* (if OLD-REACT old-with-render* new-with-render*))

0 commit comments

Comments
 (0)