Next-js compilers removing codec exports

Hello, today I fixed a nasty problem I was having in a Rescript generated next-js page by doing this:

Js.log2("props_decode", props_decode);
Js.log2("props_encode", props_encode);
Js.log2("server_props_encode", server_props_encode);

For some reason, the compiler is removing the encoders and decoders that I need to send data between getServerSideProps and the component itself. Why is that? How can I avoid this? If using plain values (booleans, strings, even options) I don’t need the decoder, but as soon as I use more complex types, they are mandatory.
Because next-js just spreads the object response I need to wrap the server response to not “consume” the response values as props. I have it outlined like this:

[@decco]
type props = {
  stuff: Module.someType
  id: string,
};

[@decco]
type server_props = {props};

let getServerSideProps: Next.GetServerSideProps.t = // bla bla function
module Page = {
  [@react.component]
  let make = (~props: Js.Json.t) => {}
}

let default = Page.make;

As I said, if I do not put the console logs to force the compiler keep the encoders I will get a compile error. Does anyone have a better solution to this?

Ok, I think I found a way to resolve it. God dam defaults. By default, next uses their new “state of the art” bundler.
So I just added the following .babelrc to the root of my repo

{
  "presets": [
    [
      "next/babel"
    ]
  ]
}

Guess what? Not as fancy, but works as expected

1 Like