Skip to content

Commit 3f3b4f8

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/navigation
* origin/main: Specify model values at React (#309) feat: allow async in client props (#315) chore: add context to turn_element_into_payload revert: client_value to push revert: Fiber abstraction of render_element revert: remove push on async component revert: remove debug info changes chore: add better naming to root_data_payload feat: change serialize for to_chunk Improve CI (#313) feat: improve debugging due to new fiber/model contextg Add environtmnet for srr Client component's can't be functions refact: improve the Fiber and Model stream context fix: align Suspense with reason-react (#311) fix: adjust doc link on tests Fix broken link to browser_ppx
2 parents dc21a72 + cc50f18 commit 3f3b4f8

File tree

20 files changed

+639
-561
lines changed

20 files changed

+639
-561
lines changed

.github/workflows/ci.yml

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ on:
99
- main
1010

1111
env:
12-
OPAM_VERSION: 2.3.0
1312
DUNE_PROFILE: release
1413
OCAMLRUNPARAM: b
1514

@@ -44,19 +43,14 @@ jobs:
4443
steps:
4544
- uses: actions/checkout@v4
4645

47-
- name: Install openssl
48-
if: matrix.os == 'macos-latest'
49-
run: |
50-
pkg-config --modversion openssl
51-
5246
- name: Load npm cache
5347
id: npm-cache
5448
uses: actions/cache/restore@v4
5549
with:
5650
path: |
5751
demo/node_modules
5852
demo/client/node_modules
59-
key: npm-${{ matrix.os }}-${{ hashFiles('demo/package.json') }}-${{ hashFiles('demo/client/package.json') }}
53+
key: v1.0.0-npm-${{ matrix.os }}-${{ hashFiles('demo/package.json') }}-${{ hashFiles('demo/client/package.json') }}
6054

6155
- name: Load opam cache
6256
id: opam-cache
@@ -67,10 +61,10 @@ jobs:
6761
~/.opam
6862
_opam
6963
.opam-path
70-
key: opam-${{ matrix.os }}-${{ matrix.ocaml-compiler }}-${{ hashFiles('**.opam') }}
64+
key: v1.0.0-opam-${{ matrix.os }}-${{ matrix.ocaml-compiler }}-${{ hashFiles('**.opam') }}
7165

7266
- name: Use OCaml ${{ matrix.ocaml-compiler }}
73-
uses: ocaml/setup-ocaml@v3.2.5
67+
uses: ocaml/setup-ocaml@v3.4.5
7468
if: steps.opam-cache.outputs.cache-hit != 'true'
7569
with:
7670
ocaml-compiler: ${{ matrix.ocaml-compiler }}
@@ -134,19 +128,18 @@ jobs:
134128
run: make test
135129

136130
- name: Generate docs
137-
if: github.ref == 'refs/heads/main' && matrix.ocaml-compiler == '5.2.0'
131+
if: github.ref == 'refs/heads/main' && matrix.os == 'ubuntu-latest' && matrix.ocaml-compiler == '5.2.0'
138132
run: |
139133
opam install -y odoc-driver
140134
make docs
141135
142-
- name: Publish docs
143-
uses: crazy-max/ghaction-github-pages@v1
144-
if: github.ref == 'refs/heads/main' && matrix.ocaml-compiler == '5.2.0'
136+
- name: Upload docs artifact
137+
if: github.ref == 'refs/heads/main' && matrix.os == 'ubuntu-latest' && matrix.ocaml-compiler == '5.2.0'
138+
uses: actions/upload-artifact@v4
145139
with:
146-
target_branch: gh-pages
147-
build_dir: _html
148-
env:
149-
GITHUB_TOKEN: ${{ github.token }}
140+
name: documentation
141+
path: _html
142+
retention-days: 1
150143

151144
- name: Run benchmarks
152145
run: make bench
@@ -157,7 +150,7 @@ jobs:
157150
path: |
158151
demo/node_modules
159152
demo/client/node_modules
160-
key: npm-${{ matrix.os }}-${{ hashFiles('demo/package.json') }}-${{ hashFiles('demo/client/package.json') }}
153+
key: v1.0.0-npm-${{ matrix.os }}-${{ hashFiles('demo/package.json') }}-${{ hashFiles('demo/client/package.json') }}
161154

162155
- name: Save opam cache
163156
uses: actions/cache/save@v4
@@ -168,4 +161,36 @@ jobs:
168161
~/.opam
169162
_opam
170163
.opam-path
171-
key: opam-${{ matrix.os }}-${{ matrix.ocaml-compiler }}-${{ hashFiles('**.opam') }}
164+
key: v1.0.0-opam-${{ matrix.os }}-${{ matrix.ocaml-compiler }}-${{ hashFiles('**.opam') }}
165+
166+
publish-docs:
167+
name: Publish documentation
168+
needs: build
169+
if: github.ref == 'refs/heads/main'
170+
runs-on: ubuntu-latest
171+
172+
environment:
173+
name: github-pages
174+
url: https://ml-in-barcelona.github.io/server-reason-react
175+
176+
permissions:
177+
contents: write
178+
pages: write
179+
id-token: write
180+
181+
steps:
182+
- uses: actions/checkout@v4
183+
184+
- name: Download docs artifact
185+
uses: actions/download-artifact@v4
186+
with:
187+
name: documentation
188+
path: _html
189+
190+
- name: Publish to GitHub Pages
191+
uses: crazy-max/ghaction-github-pages@v1
192+
with:
193+
target_branch: gh-pages
194+
build_dir: _html
195+
env:
196+
GITHUB_TOKEN: ${{ github.token }}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ The [documentation site](https://ml-in-barcelona.github.io/server-reason-react/s
5656

5757
The `demo` folder contains a bunch of demos under a server to showcases the usages of `server-reason-react`. Check the [README](demo/README.md) for how to setup and run it.
5858

59-
## Want to contribute to the future?
59+
## Want to contribute?
6060

61-
[Follow me](https://x.com/davesnx) or [message me](https://x.com/davesnx)
61+
[DM me](https://x.com/davesnx)

demo/server/DreamRSC.re

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ let createFromRequest =
165165
) => {
166166
switch (Dream.header(request, "Accept")) {
167167
| Some(accept) when is_react_component_header(accept) =>
168-
stream_model(~location=Dream.target(request), element)
168+
stream_model(
169+
~location=Dream.target(request),
170+
React.Model.Element(element),
171+
)
169172
| _ =>
170173
stream_html(
171174
~skipRoot=disableSSR,

documentation/universal-code.mld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ module ServerReasonReact = {
7474
| Fragment(array(element));
7575

7676
// createElement is a function that returns a React.element
77-
let createElement = name => React.Element(string);
77+
let createElement = name => React.Model.Element(string);
7878
};
7979
};
8080
]}

packages/melange.ppx/ppx.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ let mel_raw_found_in_native_message ~loc payload =
569569
Printf.sprintf
570570
"[server-reason-react.melange_ppx] There's a [%%mel.raw \"%s\"] expression in native, which should only happen \
571571
in JavaScript. You need to conditionally run it via let%%browser_only or switch%%platform. More info at \
572-
https://ml-in-barcelona.github.io/server-reason-react/local/server-reason-react/browser_only.html"
572+
https://ml-in-barcelona.github.io/server-reason-react/server-reason-react/browser_ppx.html"
573573
payload
574574
in
575575
Builder.pexp_constant ~loc (Pconst_string (msg, loc, None))
@@ -580,7 +580,7 @@ let mel_module_found_in_native_message ~loc =
580580
"[server-reason-react.melange_ppx] There's an external with [%%mel.module \"...\"] in native, which should only \
581581
happen in JavaScript. You need to conditionally run it, either by not including it on native or via \
582582
let%%browser_only/switch%%platform. More info at \
583-
https://ml-in-barcelona.github.io/server-reason-react/local/server-reason-react/browser_only.html"
583+
https://ml-in-barcelona.github.io/server-reason-react/server-reason-react/browser_ppx.html"
584584
in
585585
Builder.pexp_constant ~loc (Pconst_string (msg, loc, None))
586586

@@ -589,7 +589,7 @@ let external_found_in_native_message ~loc =
589589
Printf.sprintf
590590
"[server-reason-react.melange_ppx] There's an external in native, which should only happen in JavaScript. You \
591591
need to conditionally run it, either by not including it on native or via let%%browser_only/switch%%platform. \
592-
More info at https://ml-in-barcelona.github.io/server-reason-react/local/server-reason-react/browser_only.html"
592+
More info at https://ml-in-barcelona.github.io/server-reason-react/server-reason-react/browser_ppx.html"
593593
in
594594
Builder.pexp_constant ~loc (Pconst_string (msg, loc, None))
595595

packages/melange.ppx/tests/external.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mel.as attribute
1212
"[server-reason-react.melange_ppx] There's an external in native, which should \
1313
only happen in JavaScript. You need to conditionally run it, either by not \
1414
including it on native or via let%browser_only/switch%platform. More info at \
15-
https://ml-in-barcelona.github.io/server-reason-react/local/server-reason-react/browser_only.html"]
15+
https://ml-in-barcelona.github.io/server-reason-react/server-reason-react/browser_ppx.html"]
1616

1717
$ echo "module Runtime = struct" > main.ml
1818
$ cat $INSIDE_DUNE/packages/runtime/Runtime.ml >> main.ml
@@ -26,5 +26,5 @@ mel.as attribute
2626
should only happen in JavaScript. You need to conditionally run it,
2727
either by not including it on native or via
2828
let%browser_only/switch%platform. More info at
29-
https://ml-in-barcelona.github.io/server-reason-react/local/server-reason-react/browser_only.html
29+
https://ml-in-barcelona.github.io/server-reason-react/server-reason-react/browser_ppx.html
3030
[2]

packages/melange.ppx/tests/mel_module.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Single type (invalid OCaml, but valid in Melange)
6868
\"...\"] in native, which should only happen in JavaScript. You need to \
6969
conditionally run it, either by not including it on native or via \
7070
let%browser_only/switch%platform. More info at \
71-
https://ml-in-barcelona.github.io/server-reason-react/local/server-reason-react/browser_only.html"]
71+
https://ml-in-barcelona.github.io/server-reason-react/server-reason-react/browser_ppx.html"]
7272

7373
$ echo "module Runtime = struct" > main.ml
7474
$ cat $INSIDE_DUNE/packages/runtime/Runtime.ml >> main.ml
@@ -82,7 +82,7 @@ Single type (invalid OCaml, but valid in Melange)
8282
[%mel.module "..."] in native, which should only happen in JavaScript.
8383
You need to conditionally run it, either by not including it on native
8484
or via let%browser_only/switch%platform. More info at
85-
https://ml-in-barcelona.github.io/server-reason-react/local/server-reason-react/browser_only.html
85+
https://ml-in-barcelona.github.io/server-reason-react/server-reason-react/browser_ppx.html
8686
[2]
8787

8888
Assets with file not found

packages/melange.ppx/tests/mel_raw.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mel.raw as a value
1010
{ return element.ownerDocument; } \"] expression in native, which should \
1111
only happen in JavaScript. You need to conditionally run it via \
1212
let%browser_only or switch%platform. More info at \
13-
https://ml-in-barcelona.github.io/server-reason-react/local/server-reason-react/browser_only.html"]
13+
https://ml-in-barcelona.github.io/server-reason-react/server-reason-react/browser_ppx.html"]
1414

1515
mel.raw as an unary function
1616

@@ -24,7 +24,7 @@ mel.raw as an unary function
2424
{ return element.ownerDocument; } \"] expression in native, which should \
2525
only happen in JavaScript. You need to conditionally run it via \
2626
let%browser_only or switch%platform. More info at \
27-
https://ml-in-barcelona.github.io/server-reason-react/local/server-reason-react/browser_only.html"]
27+
https://ml-in-barcelona.github.io/server-reason-react/server-reason-react/browser_ppx.html"]
2828

2929
mel.raw as an binary function
3030

@@ -44,7 +44,7 @@ mel.raw as an binary function
4444
} \"] expression in native, which should only happen in JavaScript. You \
4545
need to conditionally run it via let%browser_only or switch%platform. More \
4646
info at \
47-
https://ml-in-barcelona.github.io/server-reason-react/local/server-reason-react/browser_only.html"]
47+
https://ml-in-barcelona.github.io/server-reason-react/server-reason-react/browser_ppx.html"]
4848

4949
mel.raw with type
5050

@@ -60,7 +60,7 @@ mel.raw with type
6060
"[server-reason-react.melange_ppx] There's a [%mel.raw \"window\"] \
6161
expression in native, which should only happen in JavaScript. You need to \
6262
conditionally run it via let%browser_only or switch%platform. More info at \
63-
https://ml-in-barcelona.github.io/server-reason-react/local/server-reason-react/browser_only.html"]
63+
https://ml-in-barcelona.github.io/server-reason-react/server-reason-react/browser_ppx.html"]
6464

6565
$ echo "module Runtime = struct" > main.ml
6666
$ cat $INSIDE_DUNE/packages/runtime/Runtime.ml >> main.ml
@@ -74,7 +74,7 @@ mel.raw with type
7474
expression in native, which should only happen in JavaScript. You need
7575
to conditionally run it via let%browser_only or switch%platform. More
7676
info at
77-
https://ml-in-barcelona.github.io/server-reason-react/local/server-reason-react/browser_only.html
77+
https://ml-in-barcelona.github.io/server-reason-react/server-reason-react/browser_ppx.html
7878
[2]
7979

8080
mel.raw as a value
@@ -89,4 +89,4 @@ mel.raw as a value
8989
console.log(\"running in JS\"); \"] expression in native, which should only \
9090
happen in JavaScript. You need to conditionally run it via let%browser_only \
9191
or switch%platform. More info at \
92-
https://ml-in-barcelona.github.io/server-reason-react/local/server-reason-react/browser_only.html"]
92+
https://ml-in-barcelona.github.io/server-reason-react/server-reason-react/browser_ppx.html"]

packages/react/src/React.ml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,22 @@ end
374374

375375
type error = { message : string; stack : Yojson.Basic.t; env : string; digest : string }
376376

377+
module Model = struct
378+
type 'element t =
379+
| Function : 'server_function Runtime.server_function -> 'element t
380+
| List : 'element t list -> 'element t
381+
| Assoc : (string * 'element t) list -> 'element t
382+
| Json : Yojson.Basic.t -> 'element t
383+
| Error : error -> 'element t
384+
| Element : 'element -> 'element t
385+
| Promise : 'a Js.Promise.t * ('a -> Yojson.Basic.t) -> 'element t
386+
end
387+
377388
type element =
378389
| Lower_case_element of lower_case_element
379390
| Upper_case_component of string * (unit -> element)
380391
| Async_component of string * (unit -> element Lwt.t)
381-
| Client_component of { props : client_props; client : unit -> element; import_module : string; import_name : string }
392+
| Client_component of { props : client_props; client : element; import_module : string; import_name : string }
382393
| List of element list
383394
| Array of element array
384395
| Text of string
@@ -390,15 +401,8 @@ type element =
390401
| Suspense of { key : string option; children : element; fallback : element }
391402

392403
and lower_case_element = { key : string option; tag : string; attributes : JSX.prop list; children : element list }
393-
and client_props = (string * client_value) list
394-
395-
and client_value =
396-
(* TODO: Do we need to add more types here? *)
397-
| Function : 'f Runtime.server_function -> client_value
398-
| Json : Yojson.Basic.t -> client_value
399-
| Error : error -> client_value
400-
| Element : element -> client_value
401-
| Promise : 'a Js.Promise.t * ('a -> Yojson.Basic.t) -> client_value
404+
and client_props = (string * element Model.t) list
405+
and model_value = element Model.t
402406

403407
exception Invalid_children of string
404408

@@ -519,7 +523,7 @@ let createContext (initial_value : 'a) : 'a Context.t =
519523
module Suspense = struct
520524
let or_react_null = function None -> null | Some x -> x
521525

522-
let make ?(key = None) ?fallback ?children () =
526+
let make ?key ?fallback ?children () =
523527
Suspense { key; fallback = or_react_null fallback; children = or_react_null children }
524528
end
525529

packages/react/src/React.mli

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -557,11 +557,22 @@ end
557557

558558
type error = { message : string; stack : Yojson.Basic.t; env : string; digest : string }
559559

560+
module Model : sig
561+
type 'element t =
562+
| Function : 'server_function Runtime.server_function -> 'element t
563+
| List : 'element t list -> 'element t
564+
| Assoc : (string * 'element t) list -> 'element t
565+
| Json : Yojson.Basic.t -> 'element t
566+
| Error : error -> 'element t
567+
| Element : 'element -> 'element t
568+
| Promise : 'a Js.Promise.t * ('a -> Yojson.Basic.t) -> 'element t
569+
end
570+
560571
type element =
561572
| Lower_case_element of lower_case_element
562573
| Upper_case_component of string * (unit -> element)
563574
| Async_component of string * (unit -> element Lwt.t)
564-
| Client_component of { props : client_props; client : unit -> element; import_module : string; import_name : string }
575+
| Client_component of { props : client_props; client : element; import_module : string; import_name : string }
565576
| List of element list
566577
| Array of element array
567578
| Text of string
@@ -573,14 +584,8 @@ type element =
573584
| Suspense of { key : string option; children : element; fallback : element }
574585

575586
and lower_case_element = { key : string option; tag : string; attributes : JSX.prop list; children : element list }
576-
and client_props = (string * client_value) list
577-
578-
and client_value =
579-
| Function : 'server_function Runtime.server_function -> client_value
580-
| Json : Yojson.Basic.t -> client_value
581-
| Error : error -> client_value
582-
| Element : element -> client_value
583-
| Promise : 'a Js.Promise.t * ('a -> Yojson.Basic.t) -> client_value
587+
and client_props = (string * element Model.t) list
588+
and model_value = element Model.t
584589

585590
exception Invalid_children of string
586591

@@ -610,7 +615,7 @@ end
610615
val createContext : 'a -> 'a Context.t
611616

612617
module Suspense : sig
613-
val make : ?key:string option -> ?fallback:element -> ?children:element -> unit -> element
618+
val make : ?key:string -> ?fallback:element -> ?children:element -> unit -> element
614619
end
615620

616621
type any_promise = Any_promise : 'a Lwt.t -> any_promise

0 commit comments

Comments
 (0)