Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
- Fix `--create-sourcedirs` generation with for a single project. https://github.com/rescript-lang/rescript/pull/7671
- Fix rewatch not recompiling on changes under windows. https://github.com/rescript-lang/rescript/pull/7690
- Fix locations of regex literals. https://github.com/rescript-lang/rescript/pull/7683
- Fix async React component compilation. https://github.com/rescript-lang/rescript/pull/7704

# 12.0.0-beta.2

Expand Down
5 changes: 1 addition & 4 deletions compiler/syntax/src/jsx_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ let async_component ~async expr =
let open Ast_helper in
Exp.apply
(Exp.ident
{
loc = Location.none;
txt = Ldot (Lident "JsxPPXReactSupport", "asyncComponent");
})
{loc = Location.none; txt = Ldot (Lident "Jsx", "asyncComponent")})
[(Nolabel, expr)]
else expr
2 changes: 2 additions & 0 deletions runtime/Jsx.res
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ type component<'props> = componentLike<'props, element>

/* this function exists to prepare for making `component` abstract */
external component: componentLike<'props, element> => component<'props> = "%identity"

external asyncComponent: promise<element> => element = "%identity"
4 changes: 2 additions & 2 deletions tests/syntax_tests/data/ppx/react/expected/asyncAwait.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module C0 = {
ReactDOM.jsx("div", {children: ?ReactDOM.someElement({React.int(a)})})
}
let make = {
let \"AsyncAwait$C0" = (props: props<_>) => JsxPPXReactSupport.asyncComponent(make(props))
let \"AsyncAwait$C0" = (props: props<_>) => Jsx.asyncComponent(make(props))

\"AsyncAwait$C0"
}
Expand All @@ -26,7 +26,7 @@ module C1 = {
}
}
let make = {
let \"AsyncAwait$C1" = (props: props<_>) => JsxPPXReactSupport.asyncComponent(make(props))
let \"AsyncAwait$C1" = (props: props<_>) => Jsx.asyncComponent(make(props))

\"AsyncAwait$C1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ module V4A5 = {
ReactDOM.jsx("div", {children: ?ReactDOM.someElement({React.int(a)})})
}
let make = {
let \"SharedPropsWithProps$V4A5" = (props: props<_>) =>
JsxPPXReactSupport.asyncComponent(make(props))
let \"SharedPropsWithProps$V4A5" = (props: props<_>) => Jsx.asyncComponent(make(props))
\"SharedPropsWithProps$V4A5"
}
}
Expand All @@ -60,8 +59,7 @@ module V4A6 = {
}
}
let make = {
let \"SharedPropsWithProps$V4A6" = (props: props<_>) =>
JsxPPXReactSupport.asyncComponent(make(props))
let \"SharedPropsWithProps$V4A6" = (props: props<_>) => Jsx.asyncComponent(make(props))
\"SharedPropsWithProps$V4A6"
}
}
Expand Down
41 changes: 41 additions & 0 deletions tests/tests/src/async_jsx.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Generated by ReScript, PLEASE EDIT WITH CARE

import * as JsxRuntime from "react/jsx-runtime";

function getNow() {
return new Promise((res, param) => {
setTimeout(() => res(new Date()), 1000);
});
}

async function make(param) {
let now = await getNow();
return <div>
<p>
{now.toLocaleString()}
</p>
</div>;
}

let Async_jsx$Foo = make;

let Foo = {
make: Async_jsx$Foo
};

function Async_jsx$Bar(props) {
return <div>
<Async_jsx$Foo />
</div>;
}

let Bar = {
make: Async_jsx$Bar
};

export {
getNow,
Foo,
Bar,
}
/* react/jsx-runtime Not a pure module */
30 changes: 30 additions & 0 deletions tests/tests/src/async_jsx.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@@config({
flags: ["-bs-jsx", "4", "-bs-jsx-preserve"],
})

let getNow = () => {
Promise.make((res, _) => {
setTimeout(() => {
res(Date.make())
}, 1000)->ignore
})
}

module Foo = {
@react.component
let make = async () => {
let now = await getNow()
<div>
<p> {React.string(now->Date.toLocaleString)} </p>
</div>
}
}

module Bar = {
@react.component
let make = () => {
<div>
<Foo />
</div>
}
}