JSX preserve mode spreads an `@unboxed` props record (`{..."x"}` instead of `"x"`)
Maintainers usually reply within 1 day
A pull request for this has already been merged.
Assessment
- Difficulty
- 4/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- javascript, ocaml
- Domain
- compilers
Research direction
Start with jsx_props_of in compiler/ml/translcore.ml and jsx_printable in compiler/core/js_dump.ml, then compare the preserve-mode output with the reproduction and expected output in the issue. Done means both @unboxed record examples preserve the string as the props value instead of spreading it. Pull request #8847 is already open for this issue.
Written by the indexing model from the issue text.
Description
Found by adversarial experiments on semantic analysts.
What is broken
jsx_props_of turns every props expression that is not a Record_regular record literal into Jsx_props_spread:
https://github.com/rescript-lang/rescript/blob/8d51b9ce7/compiler/ml/translcore.ml#L1049-L1096
An @unboxed record literal compiles to its single field's value, which is not an object. jsx_printable does not reject this case:
https://github.com/rescript-lang/rescript/blob/8d51b9ce7/compiler/core/js_dump.ml#L176-L190
Reproduction
@@jsxConfig({version: 4, module_: "MyJsx"})
module MyJsx = {
type element = int
type component<'props> = 'props => element
external component: component<'props> => component<'props> = "%identity"
@module("rt") external jsx: (component<'props>, 'props) => element = "jsx"
@module("rt") external jsxs: (component<'props>, 'props) => element = "jsxs"
external array: array<element> => element = "%identity"
}
@unboxed type props = {title: string}
module C = {@module("lib") external make: MyJsx.component<props> = "C"}
module D = {@val external make: MyJsx.component<props> = "lowerD"}
let el = <C title="x" />
let el2 = <D title="y" />
bsc -nopervasives -bs-jsx 4 -bs-jsx-preserve K12.res at master:
let el = <Lib.C
{..."x"}
/>;
let el2 = Rt.jsx(lowerD, {..."y"});
Expected, as printed by bsc -nopervasives -bs-jsx 4 and by preserve mode at ece8b148:
let el = Rt.jsx(Lib.C, "x");
let el2 = Rt.jsx(lowerD, "y");
Introduced
#8754 (a7721303a).
Impact
The component receives {0: "x"} instead of "x": the generated code is wrong, with no error or warning. The case is rare, because the props type must be an @unboxed record.
- Dominant language
- ReScript
- Stars
- 7.5k
- Forks
- 483
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 120
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rescript-lang/rescript
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
rescript-lang/rescript#8833 · 1 reaction ·
Maintainers usually reply within 1 day
-
rewatch watch on Linux stops watching a source folder when an overlapping recursive source folder is removed from rescript.jsonPossibly taken @cknitt claimed this 3 days ago. Open
Difficulty 4/5 1-2 days Newbie friendliness 35/100
rescript-lang/rescript#8825 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
rescript-lang/rescript#8806 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
rescript-lang/rescript#8798 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 Half a day Newbie friendliness 58/100
rescript-lang/rescript#8757 ·
Maintainers usually reply within 1 day
All issues in rescript-lang/rescript
Similar issues
-
A `--symbolic` entry binding `𝑛3` and `!n3` passes the load check, since `once` compares spellings, and fails mid-run with a `user error`Possibly taken @sherenkov claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
objectionary/phino#1929 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
FuRongJun-1999/dsh-memory#402 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
bug frontend
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
PennyLaneAI/catalyst#3337 ·
Maintainers usually reply within 1 day