Skip to content

Commit 42cd608

Browse files
authored
Merge pull request #1068 from japgolly/topic/react18
React 18 support
2 parents f7f1496 + 5297fae commit 42cd608

File tree

228 files changed

+9103
-3060
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

228 files changed

+9103
-3060
lines changed

.envrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
use flake
2+
layout node
3+
eval "$shellHook"

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
include:
1414
- java: 14
1515
scala: 2
16-
- java: 8
16+
- java: 11
1717
scala: 3
1818
name: Scala v${{ matrix.scala }} / Java v${{ matrix.java }}
1919
steps:

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
metals.sbt
1818
node_modules/
1919
target
20-
.direnv/
20+
.direnv/

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Includes a router, testing utils, performance utils, more.
2020
- [Modules](doc/MODULES.md)
2121
- [VDOM](doc/VDOM.md)
2222
- [Hooks](doc/HOOKS.md)
23+
- [Hooks via builder](doc/HOOKS_BUILDER.md)
2324
- [Refs](doc/REFS.md)
2425
- [IDE support](doc/IDE.md)
2526
- [The `Callback` class](doc/CALLBACK.md)
@@ -71,7 +72,7 @@ Includes a router, testing utils, performance utils, more.
7172
* [scastie](https://github.com/scalacenter/scastie) - An interactive playground for Scala [https://scastie.scala-lang.org](https://scastie.scala-lang.org)
7273

7374
##### Requirements:
74-
* React ≥ 17
75+
* React ≥ 18
7576
* Scala ≥ 2.13
7677
* Scala.JS ≥ 1.10
7778

bin/update_react_version

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
#!/bin/bash
2-
cd "$(dirname "$0")/../library" || exit 1
2+
cd "$(dirname "$0")/.." || exit 1
33

44
[ $# -ne 1 ] && echo "Usage: $0 <version>" && exit 1
55
ver="$1"
66

77
perl -pi -e 's/(?<![a-zA-Z0-9_-])[1-3]\d\.\d+\.\d+(?![a-zA-Z0-9_-])/'"$ver"'/g' \
8-
{doc,project}/*.* build.sbt *.md gh-pages/*.html \
8+
*.md \
9+
doc/*.md \
10+
library/build.sbt \
11+
library/ghpages/html/*.html \
12+
library/project/*.* \
913
&& git diff -U0
1014

doc/CONFIG.md

Lines changed: 17 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
* [`.component.names.all`](#componentnamesall)
77
* [`.component.names.implicit`](#componentnamesimplicit)
88
* [`.config.class` *(Scala 3 only)*](#configclass-scala-3-only)
9-
* [`.test.warnings.react`](#testwarningsreact)
109
* Runtime Settings *(development-mode only)*
1110
* [Usage](#runtime-settings-usage)
1211
* [`Reusability.disableGloballyInDev()`](#reusabilitydisablegloballyindev)
13-
* [`ReusabilityOverlay.overrideGloballyInDev()`](#reusabilityoverlayoverridegloballyindev)
12+
* ~~[`ReusabilityOverlay.overrideGloballyInDev()`](#reusabilityoverlayoverridegloballyindev)~~
1413
* [Custom `ReusabilityOverride`](#custom-reusabilityoverride)
1514

1615

@@ -26,6 +25,16 @@ If this is important to you or your organisation, feel free to reach out and spo
2625

2726
# Compile-Time Settings: Usage
2827

28+
First add this to your sbt:
29+
30+
```scala
31+
scalacOptions ++= // Required since sbt 1.6.0
32+
sys.props.iterator
33+
.filter(_._1.contains("japgolly"))
34+
.map(x => s"-D${x._1}=${x._2}")
35+
.toSeq
36+
```
37+
2938
Currently, you have to specify compile-time settings to `sbt` directly when you start it.
3039

3140
Examples:
@@ -161,60 +170,6 @@ object CustomConfig extends ScalaJsReactConfig.Defaults {
161170
}
162171
```
163172

164-
165-
# `.test.warnings.react`
166-
167-
When using `ReactTestUtils`, this setting can be used to catch React warnings and turn them into exceptions.
168-
169-
### Usage:
170-
171-
```
172-
sbt -Djapgolly.scalajs.react.test.warnings.react=warn|fatal
173-
```
174-
175-
| Setting | Outcome |
176-
| -- | -- |
177-
| `warn` (default) | Print warnings and move on |
178-
| `fatal` | Throw warnings as exceptions |
179-
180-
### Example:
181-
182-
```
183-
sbt -Djapgolly.scalajs.react.test.warnings.react=fatal
184-
```
185-
186-
```scala
187-
package com.example
188-
189-
import japgolly.scalajs.react._
190-
import japgolly.scalajs.react.test._
191-
import japgolly.scalajs.react.vdom.html_<^._
192-
import utest._
193-
194-
object ExampleTest extends TestSuite {
195-
196-
override def tests = Tests {
197-
"example" - {
198-
val comp = ScalaFnComponent[Int](i => <.p(<.td(s"i = $i")))
199-
ReactTestUtils.withRenderedIntoBody(comp(123)).withParent { m =>
200-
val html = m.outerHTML
201-
assert(html == "<p><td>i = 123</td></p>")
202-
}
203-
}
204-
}
205-
}
206-
```
207-
208-
Running the above test will fail with this error message:
209-
210-
```
211-
scala.scalajs.js.JavaScriptException: Warning: validateDOMNesting(...): <td> cannot appear as a child of <p>.
212-
at td
213-
at p
214-
at $c_sjs_js_Any$.fromFunction1__F1__sjs_js_Function1
215-
```
216-
217-
218173
# Runtime Settings: Usage
219174

220175
Runtime settings are designed for use in development-mode only (`fastOptJS`).
@@ -241,7 +196,8 @@ object Main {
241196

242197
// Start app
243198
val container = dom.document.getElementById("root")
244-
MyApp().renderIntoDOM(container)
199+
val root = ReactDOMClient.createRoot(container)
200+
root.render(MyApp())
245201
}
246202
}
247203
```
@@ -255,6 +211,8 @@ This globally disables `Reusability.shouldComponentUpdate` so that it doesn't no
255211

256212
# `ReusabilityOverlay.overrideGloballyInDev()`
257213

214+
**[ReusabilityOverlay has been deprecated in v3 with no replacement — use React's Profiler instead]**
215+
258216
*Note: Runtime settings only affect development-mode (`fastOptJS`) and must be applied before any components are created.*
259217

260218
This makes calls to `Reusability.shouldComponentUpdate` also display a little UI overlay for you to inspect/debug
@@ -293,7 +251,8 @@ object Main {
293251

294252
// Start app
295253
val container = dom.document.getElementById("root")
296-
MyApp().renderIntoDOM(container)
254+
val root = ReactDOMClient.createRoot(container)
255+
root.render(MyApp())
297256
}
298257
}
299258
```

doc/CONTEXT.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ object Content {
7272
private val component = ScalaComponent
7373
.builder[Unit]("content")
7474
.initialState(State())
75-
.renderBackend[Backend]
75+
.backend(new Backend(_))
76+
.renderS(_.backend.render(_))
7677
.componentDidMount($ $.backend.refresh($.state))
7778
.build
7879

@@ -89,7 +90,7 @@ some point calls a page, which wants to display the username. A few things to no
8990
```scala
9091
object AboutPage {
9192
case class State()
92-
class Backend($ : BackendScope[_, State]) {
93+
class Backend($ : BackendScope[Unit, State]) {
9394
def render(S: State): VdomElement =
9495
MyGlobalState.ctx.consume { myGlobalState =>
9596
<.div(s"Hi there${myGlobalState.user.fold("!")(u => s" ${u.username}!")}")
@@ -98,13 +99,14 @@ object AboutPage {
9899
private val component = ScalaComponent
99100
.builder[Unit]("AboutPage")
100101
.initialState(State())
101-
.renderBackend[Backend]
102+
.backend(new Backend(_))
103+
.renderS(_.backend.render(_))
102104
.build
103105

104106
def apply(): Unmounted[Unit, State, Backend] = component()
105107
}
106108
```
107109

108110
One additional note: Other parts of the documentation suggest that your router should always be your top level component. While in general that is true,
109-
I though that moving the provider to a higher level component delineated the responsibilities better, you are welcome to collapse them into a single
110-
component.
111+
I though that moving the provider to a higher level component delineated the responsibilities better, you are welcome to collapse them into a single
112+
component.

0 commit comments

Comments
 (0)