Skip to content

Commit ceef058

Browse files
authored
Remove support for React 17 (#99)
* Remove support for React 17
1 parent b0bb5ea commit ceef058

File tree

5 files changed

+27
-60
lines changed

5 files changed

+27
-60
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v4
1616
- name: Setup .NET
17-
uses: actions/setup-dotnet@v1
17+
uses: actions/setup-dotnet@v4
1818
with:
19-
dotnet-version: 6.0.x
19+
dotnet-version: '9.0.x'
2020
- name: Build
2121
run: ./build.fsx

appveyor.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
image: Visual Studio 2022
22

3-
install:
4-
- ps: Install-Product node 17 x64
5-
63
build_script:
74
- cmd: dotnet fsi build.fsx
85

build.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#r "nuget: Fake.Core.Target"
66
#r "nuget: Fake.Core.ReleaseNotes"
77
#r "nuget: Fake.Tools.Git"
8-
8+
#r "nuget: MSBuild.StructuredLogger, 2.2.441"
99

1010
open Fake.Core
1111
open Fake.Core.TargetOperators

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "6.0.100",
3+
"version": "9.0.100",
44
"rollForward": "latestMinor"
55
}
66
}

src/react.fs

Lines changed: 22 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -19,76 +19,46 @@ module Program =
1919
open Browser
2020
open Elmish
2121

22-
// Use the new rendering API in React 18+
23-
let useRootApi = try int ReactBindings.React.version.[ .. 1 ] >= 18 with _ -> false
24-
2522
let withReactBatchedUsing lazyView2With placeholderId (program:Program<_,_,_,_>) =
2623
let setState =
2724
let mutable lastRequest = None
25+
let root = ReactDomClient.createRoot (document.getElementById placeholderId)
2826

29-
if useRootApi then
30-
let root = ReactDomClient.createRoot (document.getElementById placeholderId)
31-
32-
fun model dispatch ->
33-
match lastRequest with
34-
| Some r -> window.cancelAnimationFrame r
35-
| _ -> ()
36-
37-
lastRequest <- Some (window.requestAnimationFrame (fun _ ->
38-
root.render (lazyView2With (fun x y -> obj.ReferenceEquals(x,y)) (Program.view program) model dispatch)))
39-
else
40-
fun model dispatch ->
41-
match lastRequest with
42-
| Some r -> window.cancelAnimationFrame r
43-
| _ -> ()
27+
fun model dispatch ->
28+
match lastRequest with
29+
| Some r -> window.cancelAnimationFrame r
30+
| _ -> ()
4431

45-
lastRequest <- Some (window.requestAnimationFrame (fun _ ->
46-
ReactDom.render(
47-
lazyView2With (fun x y -> obj.ReferenceEquals(x,y)) (Program.view program) model dispatch,
48-
document.getElementById placeholderId
49-
)))
32+
lastRequest <- Some (window.requestAnimationFrame (fun _ ->
33+
root.render (lazyView2With (fun x y -> obj.ReferenceEquals(x,y)) (Program.view program) model dispatch)))
5034

5135
program
5236
|> Program.withSetState setState
5337

5438
let withReactSynchronousUsing lazyView2With placeholderId (program:Elmish.Program<_,_,_,_>) =
5539
let setState =
56-
if useRootApi then
57-
let root = ReactDomClient.createRoot (document.getElementById placeholderId)
40+
let root = ReactDomClient.createRoot (document.getElementById placeholderId)
5841

59-
fun model dispatch ->
60-
root.render (lazyView2With (fun x y -> obj.ReferenceEquals(x,y)) (Program.view program) model dispatch)
61-
else
62-
fun model dispatch ->
63-
ReactDom.render(
64-
lazyView2With (fun x y -> obj.ReferenceEquals(x,y)) (Program.view program) model dispatch,
65-
document.getElementById placeholderId
66-
)
42+
fun model dispatch ->
43+
root.render (lazyView2With (fun x y -> obj.ReferenceEquals(x,y)) (Program.view program) model dispatch)
6744

6845
program
6946
|> Program.withSetState setState
7047

7148
let withReactHydrateUsing lazyView2With placeholderId (program:Elmish.Program<_,_,_,_>) =
7249
let setState =
73-
if useRootApi then
74-
let mutable root = None
75-
76-
fun model dispatch ->
77-
match root with
78-
| None ->
79-
root <-
80-
ReactDomClient.hydrateRoot (
81-
document.getElementById placeholderId,
82-
lazyView2With (fun x y -> obj.ReferenceEquals(x,y)) (Program.view program) model dispatch
83-
) |> Some
84-
| Some root ->
85-
root.render (lazyView2With (fun x y -> obj.ReferenceEquals(x,y)) (Program.view program) model dispatch)
86-
else
87-
fun model dispatch ->
88-
ReactDom.hydrate(
89-
lazyView2With (fun x y -> obj.ReferenceEquals(x,y)) (Program.view program) model dispatch,
90-
document.getElementById placeholderId
91-
)
50+
let mutable root = None
51+
52+
fun model dispatch ->
53+
match root with
54+
| None ->
55+
root <-
56+
ReactDomClient.hydrateRoot (
57+
document.getElementById placeholderId,
58+
lazyView2With (fun x y -> obj.ReferenceEquals(x,y)) (Program.view program) model dispatch
59+
) |> Some
60+
| Some root ->
61+
root.render (lazyView2With (fun x y -> obj.ReferenceEquals(x,y)) (Program.view program) model dispatch)
9262

9363
program
9464
|> Program.withSetState setState

0 commit comments

Comments
 (0)