rescript-lang / rescript-compiler

The compiler for ReScript.
https://rescript-lang.org
Other
6.75k stars 449 forks source link

Better NextJS integration #6457

Open ryyppy opened 1 year ago

ryyppy commented 1 year ago

Given we want to be able to provide better integration with existing JS frameworks to provide guided stories, the following blockers for NextJS should be (re-)assessed:

  1. Exotic filenames: Right now, NextJS heavily relies on exotic filenames / duplicated filenames, which requires ReScript users to re-export ReScript components in shim JS files in the pages and app directoy
  2. Shared props for getStaticProps / default export: Previously, one had to fall back to let default = (props) => {} just to be able to share the props between the consuming component and getServerProps etc. ... I think this should be solved with @mununki's new JSX 4, which should be able to provide a custom prop type to a @react.component decorator
  3. Props serialization with undefined props: Previously, serializing props from getServerProps etc. will cause the frontend to break, because foo: undefined is not valid JSON (it gets passed as a string and then JSON.parsed). This should be fixed with optional attributes (e.g. {foo ?: string})
  4. Function level directives ("use server";): As for right now, it is only possible to provide those directives on the module level. We'd need a way to maintain directives on a JS function level

(Please note: The provided list is kept short, details should be refined in linked issues if there's any need to solve a problem)

LukasDeco commented 12 months ago

Not sure if I should make a new issue for this, but since I saw this one I thought it could be a good option for a place. I noticed some weird issues with the Js.Promise2 module. It was causing the app to bomb with a very vague error. The error when logged looks something like this: [Function (anonymous)] as you can see not very descriptive. So I'm not sure what the issue is. I switched to Js.Promise for now but this uses pipe-last of course so it would be nice if we could use Promise2.

jderochervlk commented 9 months ago

Related: https://github.com/rescript-lang/rescript-compiler/issues/5950

cometkim commented 6 months ago

Not sure if I should make a new issue for this, but since I saw this one I thought it could be a good option for a place. I noticed some weird issues with the Js.Promise2 module. It was causing the app to bomb with a very vague error. The error when logged looks something like this: [Function (anonymous)] as you can see not very descriptive. So I'm not sure what the issue is. I switched to Js.Promise for now but this uses pipe-last of course so it would be nice if we could use Promise2.

The next version(v19, already in use) of React treats promises as first-class type (can be used as child element!) So now having your own runtime representation for promises can be problematic.

Note: it is available regardless of using RSC or not, see an example

see also https://github.com/facebook/react/pull/25634