ml-in-barcelona / server-reason-react

Server render Reason React components with OCaml natively
https://ml-in-barcelona.github.io/server-reason-react/local/server-reason-react/index.html
MIT License
128 stars 8 forks source link

browser_only: don't convert to runtime errors on identifiers or function application #138

Closed jchavarri closed 2 months ago

jchavarri commented 3 months ago

I had a case where I used browser_only in some event handler using a curried function, e.g.:

onKeyDown=[%browser_only
  onKeyDown(~foo)
]

This code converted to plain Runtime.fail_impossible_action_in_ssr, crashing the server application at runtime.

This PR removes some of the cases where browser_only can be used:

so this extension can only be used to convert function definitions.

Users can still use switch%platform for identifiers and function applications, which prevents running on footguns like the one mentioned above.