Error evaluating recursive modules (ReScript 11.0.0-rc.9)

Hi everyone,

I tried updating my codebase from 10.1.4 to 11.0.0-rc.9, but I’ve run into an issue recursive components:

Cannot safely evaluate the definition of the recursively-defined module X

Here is a reproduction.

These are the package versions I use:

  • rescript: “11.0.0-rc.9”
  • @rescript/core: “0.6.0”
  • @rescript/react: “0.12.0-alpha.2”

I also created an issue in rescript-compiler repo here.

1 Like

Note that this is blocking me from migrating in two separate codebases. :frowning:

Could you give a more concrete example of what you’re trying to do? Maybe there’s some workaround.

I can’t provide the exact example I have in my codebase due to the NDA. We are building a generic no-code platform, where recursive component are of great help. Right now, we have 7-8 examples in the codebase, but they are all essentially like the one I provided in the playground reproduction.
In one of the cases we have a “Table of Content” recursive component.

Are recursive components supported in the new v11, as well as recursive modules?

they are all essentially like the one I provided in the playground reproduction

A small correction, in playground reproduction I have an infinite loop, but none of our examples in codebase can produce an infinite loop.

Our examples are more like this:

module type RecursiveComponentType = {
  type rec data ={
    name: string,
    children: option<array<data>>
  };
  type props = {
    data: array<data>
  };
  let make: React.component<props>
}

module rec RecursiveComponent:RecursiveComponentType = {
  type rec data = {
    name: string,
    children: option<array<data>>
  };

  type props = {
    data: array<data>
  }

  let make: React.component<props> = ({data}) => {
    <div style={{ paddingLeft: "20px" }}>
      {data->Belt.Array.map(parent => {
        <div key={parent.name}>
          <span>{parent.name->React.string}</span>
          // Base Condition and Rendering recursive component from inside itself
          <div>
            {parent.children->Option.map(children => <RecursiveComponent data={children} />)->Option.getOr(React.null)}
          </div>
        </div>
      })->React.array}
    </div>
  }
}

Here is the new playground reproduction with the above code.

2 Likes

I didn’t test it, but the make function can be recursive.

Playground

1 Like

Yes, that is one of the workarounds we could use. However, it is not the same because make, on its own, isn’t a React component (nested call doesn’t end up as JsxRuntime.jsxs call in js output) which brings some benefits.

Fix here, will be in the first v11.x release: Fix issue with recursive modules and uncurried. by cristianoc · Pull Request #6575 · rescript-lang/rescript-compiler · GitHub

6 Likes

11.0.1 is now out with this fix.

4 Likes