Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=72e494d939a7b656e438d96ecad65e57
sha512=3c58d8fdab8971434ccaaf0205306e663e232428076f927a49486dc1f6ed71f79f38083bea5de19877eb0c8045e737b852af5682bc3e17690ebc4103a69873cf
Description
Added to opam-repository:
README
Universal Reason Portal
Universal Portal for ssr natively ReasonReact apps.
This project was inspired by server-reason-react to understand how SSR with ReasonReact works and also give the community more material to learn about SSR with ReasonReact.
Table of Contents
Installation
opam install universal-portalUsage
Server
Dream.router([
Dream.get("/", _request => {
let portals: ref(array(UniversalPortal_Shared.Portal.portal)) = ref([||]);
let element =
ReactDOM.renderToString(
UniversalPortal_Server.collectPortals(
<Page scripts=["/static/app.js"]>
<Shared_native_demo.App />
</Page>,
(collectedPortal: UniversalPortal_Shared.Portal.portal) => {
portals := Array.append(portals^, [|collectedPortal|])
}),
);
let html =
UniversalPortal_Server.appendUniversalPortals(element, portals^);
portals := [||];
html |> Dream.html;
}),
Dream.get("/static/**", Dream.static("./static")),
]);Shared
For client dune config add
(libraries universal-portal.shared_js)For native dune config add
(libraries universal-portal.shared_native)Component
Use UniversalPortal_Shared and it will work on both client and native content.
[@react.component]
let make = () => {
<div>
<UniversalPortal_Shared.Portal selector="body">
<div>
{"Hey, I'm a portal, disable JS on your dev tools and check that I'll still here"
|> React.string}
</div>
</UniversalPortal_Shared.Portal>
</div>;
};Cleaning server side portals
You must call the UniversalPortal_Js.useRemoveServerPortals at the main entry point of your app, so it will remove all the server side portals.
Checkout the demo for more details: Demo
UniversalPortal_Js.useRemoveServerPortals();Running the demo
Make sure to initialize the project:
make initThen you can run the demo:
make demoRoadmap
- Improve tests
Dependencies (11)
-
server-reason-react
= "0.2.0" - lambdasoup
-
reason-react
>= "0.14.0" -
reason-react-ppx
>= "0.14.0" - quickjs
- dream
- melange-webapi
- melange
-
reason
>= "3.10.0" -
ocaml
>= "5.0.0" -
dune
>= "3.8"
Dev Dependencies (8)
-
odoc
with-doc -
ocaml-lsp-server
with-test -
melange-jest
with-test -
melange-testing-library
with-test -
ocamlformat
= "0.26.1" & with-test -
fmt
with-test -
alcotest-lwt
with-test -
alcotest
with-test
Optional Dependencies
None
Used by
None
Conflicts
None
Build status
Results of building universal-portal with each compiler on check.ci.ocaml.org, run of against opam-repository 8d8d144. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
| Version | OCaml 4.11 | OCaml 4.14 | OCaml 5.2 | OCaml 5.4 | OCaml 5.5 |
|---|---|---|---|---|---|
| 0.3.0 (this version) | n/a | n/a | good | n/a | n/a |
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure