-
Notifications
You must be signed in to change notification settings - Fork 465
React JSX PPX: Support async components #6398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If I remember correctly, making the JSX ppx support async would not be difficult. Rather, I seem to recall that async await was prevented from being used with React components, and I think it would be simple to unlock that and support it. |
The async function is a clear visual signal to the server component. We can make it even clearer like |
I'm asking because I don't have a deep understanding of RSC. |
Currently, yes, due to the technical limitations Instead, there are experimental APIs called The React team guide people to prefer to use async/await when possible based on syntactic familiarity, so there is room for change in the future. However, it may related to React's experimental memoization compiler, and I suspect it is a feature that compiles async/await into According to:
|
With React server components, async React components are now a thing. Async components in this context means that you, on the server, can use an async function (and via that await in the body) as your component function:
In ReScript it could look like this:
However, this doesn't work today: https://rescript-lang.org/try?version=v11.0.0-beta.4&code=AIJwpghgxgLgdFA9gWwA6IHZgzAUAGzBgAJkIBrMYgXmIgGcBPDKYgCgD8BXesEASQAmAShoA+YgG9cxYoRI8+AEQgwINOgHcIASxIBzIgFVeIFWraKBImcQA8gnQDcJkgEqRYcejBA6M+pam5hBwGBDIYMIAvvYA9I4uuNG4QA
(I believe it doesn't work because we're loosing the async context in the PPX as the
make
function is transformed.)It is possible to use async components today by not using the PPX, and defining your own wrapping identity function for casting the async component into a regular one:
Playground for the above: https://rescript-lang.org/try?version=v11.0.0-beta.4&code=C4TwDgpgBArgzhATgEQIbFVAvFA3gO1QFsIAuKOYRAS3wHMBfAKABsJgo72BVBFdTDlRwQ+AMZQA+vCQBJACbYAfHkIlyAImARKG5kwgAPbYkIsow0WIDCAeyJhb+CPmDkAFAHIwiW2DjKUD721AgAPABKEKhiwAB0EGwkrkoAlIFRMfFi9o7OrmFMUFDevv4ANEwqOBoApNTyLsDUoBpMTES28jBsUACCIuJ2Dk5N2HhFUKCQQWUBOLgyiArklDT0zMVsHESoANbQQoM2uaOu7pbiUO7B-uS3cOlYKriTW+ywfGgY46gA7qgWpweF8BDc5nElgpUm8oGF5NQAG4vTKxOJrWh0dxLb6oOJqCCpBhwgD0CORkwYMP02ygACs4IZxmEBlZhnkxlD5FgNABGDRQElKJhAA
However, this gives up using the PPX, and requires you to manually wrap the make function in that external. And that doesn't feel very ergonomic.
How can we make this work?
I think this is important to support now that Server Components are becoming a thing, and ReScript supports everything else for them.
Interested in your thoughts here. The way I see it, we need at least 2 things:
make
is transformed in the PPXrescript-react
?Cc @mununki @cristianoc . What do you think? Interested in your thoughts of this.
The text was updated successfully, but these errors were encountered: