rescript-react icon indicating copy to clipboard operation
rescript-react copied to clipboard

Props overwritten when they have the same prefix followed by underscores

Open nireno opened this issue 4 years ago • 2 comments

This rescript component:

@react.component
let make = (
  ~foo__one,
  ~foo__two,
) => {
  <div>
    {foo__one->React.string}
    {foo__two->React.string}
  </div>
}

Generates this javascript function:

function Playground(Props) {
  var foo__one = Props.foo;
  var foo__two = Props.foo;
  return React.createElement("div", undefined, foo__one, foo__two);
}

Notice that foo__one and foo__two are both assigned the value of Props.foo. The result is that the value passed for ~foo__one get's rendered twice and ~foo_two is ignored.

It would be helpful if this at least generated a warning.

nireno avatar Apr 11 '21 14:04 nireno

++ @rickyvetter is this for the JSX ppx?

cristianoc avatar Apr 27 '21 04:04 cristianoc

Hmm. this is interesting. Definitely an interaction issue between the compiler mangling rules and the PPX. I think the PPX can force it to be avoided if we account for this in our naming convention and do something like this.

rickyvetter avatar Jan 22 '22 00:01 rickyvetter

@mattdamon108 Is this still an issue with JSX 4?

cknitt avatar Sep 26 '22 15:09 cknitt

Yes, this issue is gone with v4

function Underscore(props) {
  return React.createElement("div", undefined, props.foo__one, props.foo__two);
}

mununki avatar Sep 27 '22 09:09 mununki

@mattdamon108 Ok, then I would suggest to close this issue as fixed in v4 (unless you would like to spend time on fixing this in the v3 PPX).

cknitt avatar Sep 27 '22 09:09 cknitt