Skip to content

Commit 77b1bfb

Browse files
authored
Revert support for "custom children" in uppercase components (#891)
* add breaking test * revert * update changes
1 parent 7f45d11 commit 77b1bfb

File tree

4 files changed

+68
-23
lines changed

4 files changed

+68
-23
lines changed

CHANGES.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# Unreleased
22

3-
* BREAKING, ppx: Allow passing an array of custom children to a component
4-
without having to wrap in array literal ([@jchavarri in #748](https://github.com/reasonml/reason-react/pull/823))
5-
63
# 0.15.0
74

85
* Add `isValidElement` (@r17x in

ppx/reason_react_ppx.ml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,7 @@ let jsxExprAndChildren ~component_type ~loc ~ctxt mapper ~keyProps children =
487487
children *)
488488
( Builder.pexp_ident ~loc { loc; txt = Ldot (ident, "jsxs") },
489489
None,
490-
Some
491-
(match component_type with
492-
| Uppercase -> children
493-
| Lowercase -> Binding.React.array ~loc children) )
490+
Some (Binding.React.array ~loc children))
494491
| None, (label, key) :: _ ->
495492
( Builder.pexp_ident ~loc { loc; txt = Ldot (ident, "jsxKeyed") },
496493
Some (label, key),

ppx/test/upper.t/run.t

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
let upper_children_single = foo =>
55
React.jsx(Upper.make, Upper.makeProps(~children=foo, ()));
66
let upper_children_multiple = (foo, bar) =>
7-
React.jsxs(Upper.make, Upper.makeProps(~children=[|foo, bar|], ()));
7+
React.jsxs(
8+
Upper.make,
9+
Upper.makeProps(~children=React.array([|foo, bar|]), ()),
10+
);
811
let upper_children =
912
React.jsx(
1013
Page.make,

test/React__test.re

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@ module DummyComponentThatMapsChildren = {
1616
[@react.component]
1717
let make = (~children, ()) => {
1818
<div>
19-
{children
20-
->React.array
21-
->React.Children.mapWithIndex((element, index) => {
22-
React.cloneElement(
23-
element,
24-
{
25-
"key": string_of_int(index),
26-
"role": Int.to_string(index),
27-
},
28-
)
29-
})}
19+
{children->React.Children.mapWithIndex((element, index) => {
20+
React.cloneElement(
21+
element,
22+
{
23+
"key": string_of_int(index),
24+
"role": Int.to_string(index),
25+
},
26+
)
27+
})}
3028
</div>;
3129
};
3230
};
@@ -170,9 +168,11 @@ describe("React", () => {
170168
let container =
171169
ReactTestingLibrary.render(
172170
<DummyComponentThatMapsChildren>
173-
<div> 1->React.int </div>
174-
<div> 2->React.int </div>
175-
<div> 3->React.int </div>
171+
{React.array([|
172+
<div> 1->React.int </div>,
173+
<div> 2->React.int </div>,
174+
<div> 3->React.int </div>,
175+
|])}
176176
</DummyComponentThatMapsChildren>,
177177
);
178178

@@ -461,7 +461,7 @@ describe("React", () => {
461461

462462
let container =
463463
ReactTestingLibrary.render(
464-
<Test> {Test.name: "foo"} {name: "bar"} </Test>,
464+
<Test> {[|{Test.name: "foo"}, {name: "bar"}|]} </Test>,
465465
);
466466

467467
let foo = getByRole("foo", container);
@@ -470,4 +470,52 @@ describe("React", () => {
470470
let bar = getByRole("bar", container);
471471
expect(bar->innerHTML)->toBe("bar");
472472
});
473+
474+
test("Can render components with multiple children", () => {
475+
module MyComponent = {
476+
[@react.component]
477+
let make = (~children) => {
478+
<section role="container"> children </section>;
479+
};
480+
};
481+
482+
let container =
483+
ReactTestingLibrary.render(
484+
<MyComponent>
485+
<div role="child1"> {React.string("child1")} </div>
486+
<div role="child2"> {React.string("child2")} </div>
487+
</MyComponent>,
488+
);
489+
490+
let section = getByRole("container", container);
491+
expect(section->tagName->Js.String.toLowerCase)->toBe("section");
492+
493+
let child1 = getByRole("child1", container);
494+
expect(child1->innerHTML)->toBe("child1");
495+
496+
let child2 = getByRole("child2", container);
497+
expect(child2->innerHTML)->toBe("child2");
498+
});
499+
500+
test("Can render components with a single child", () => {
501+
module MyComponent = {
502+
[@react.component]
503+
let make = (~children) => {
504+
<section role="container"> children </section>;
505+
};
506+
};
507+
508+
let container =
509+
ReactTestingLibrary.render(
510+
<MyComponent>
511+
<div role="child"> {React.string("child")} </div>
512+
</MyComponent>,
513+
);
514+
515+
let section = getByRole("container", container);
516+
expect(section->tagName->Js.String.toLowerCase)->toBe("section");
517+
518+
let child = getByRole("child", container);
519+
expect(child->innerHTML)->toBe("child");
520+
});
473521
});

0 commit comments

Comments
 (0)