-
Notifications
You must be signed in to change notification settings - Fork 5
Description
The convention based error handling in Remix requires exporting React components with the names CatchBoundary
and ErrorBoundary
. As Rescript requires that all values start with a lowercase letter, we need to do some work to support it.
I was initially thinking we could just use a raw code block:
@react.component
let errorBoundary = () => {}
%%raw(`exports.ErrorBoundary = errorBoundary`)
However, it seems that Remix requires the use of es6 modules and that strategy only works for commonjs modules. With es6 modules, Rescript produces an export {}
block at the bottom of the file and it doesn't seem possible to change that with a workaround like this.
I did some more research and it appears that we can make use of genType
to cover this requirement. This would allow us to annotate the boundary components like so:
@react.component @genType.as("ErrorBoundary")
let errorBoundary = () => {}
This isn't without its baggage though:
- You must use
.bs.js
extensions. This means that the special filesentry.client.js
,entry.server.js
androot.js
would need proxy files to re-export the Rescript generated files. - You must use in-source compilation. Not a biggie, we were doing that anyway.
- The new
.gen.js
files are only produced if there aregenType
annotations in the file. This means the route convention logic would need additional logic to use.gen.js
if they exist then fall back on to.bs.js
files
The first two points only affect the template's bsconfig.json
. Point 3 would require some work in this repo.
Does this seem like the right path forward? Did you have other thoughts about how this might be accomplished?