Skip to content

Fix Children.map not flattening result#2287

Merged
marvinhagemeister merged 3 commits into
masterfrom
nested-children
Jan 28, 2020
Merged

Fix Children.map not flattening result#2287
marvinhagemeister merged 3 commits into
masterfrom
nested-children

Conversation

@marvinhagemeister

Copy link
Copy Markdown
Member

Just checked against the implementation in React and they flatten the result of Children.map. We didn't do that which lead to an array of children being passed to isValidElement. Because arrays are not valid children they were filtered out.

Fixes #2286 .

@github-actions

github-actions Bot commented Jan 28, 2020

Copy link
Copy Markdown

Size Change: +58 B (0%)

Total Size: 38.2 kB

Filename Size Change
compat/dist/compat.js 2.96 kB +16 B (0%)
compat/dist/compat.module.js 2.99 kB +21 B (0%)
compat/dist/compat.umd.js 3.01 kB +21 B (0%)
ℹ️ View Unchanged
Filename Size Change
debug/dist/debug.js 3.08 kB 0 B
debug/dist/debug.module.js 3.07 kB 0 B
debug/dist/debug.umd.js 3.14 kB 0 B
devtools/dist/devtools.js 175 B 0 B
devtools/dist/devtools.module.js 185 B 0 B
devtools/dist/devtools.umd.js 252 B 0 B
dist/preact.js 3.69 kB 0 B
dist/preact.min.js 3.69 kB 0 B
dist/preact.module.js 3.71 kB 0 B
dist/preact.umd.js 3.75 kB 0 B
hooks/dist/hooks.js 1.06 kB 0 B
hooks/dist/hooks.module.js 1.08 kB 0 B
hooks/dist/hooks.umd.js 1.12 kB 0 B
test-utils/dist/testUtils.js 390 B 0 B
test-utils/dist/testUtils.module.js 392 B 0 B
test-utils/dist/testUtils.umd.js 469 B 0 B

compressed-size-action

@coveralls

coveralls commented Jan 28, 2020

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.1%) to 99.808% when pulling 8c7149b on nested-children into 427b4ea on master.

@sventschui

sventschui commented Jan 28, 2020

Copy link
Copy Markdown
Member

Could save a byte (and a map-loop) when invoking fn inside the reduce callback or am I missing sth.?

	return toChildArray(children)
 		.reduce((acc, value) => acc.concat(fn(value)), []);

@marvinhagemeister

Copy link
Copy Markdown
Member Author

@sventschui Super awesome, that is a lot better 💯 I had a hunch that the current solution wasn't as optimal as it should be 👍

@marvinhagemeister marvinhagemeister merged commit 62b2d70 into master Jan 28, 2020
@marvinhagemeister marvinhagemeister deleted the nested-children branch January 28, 2020 20:46
porfirioribeiro pushed a commit to porfirioribeiro/preact that referenced this pull request Feb 3, 2020
Fix Children.map not flattening result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The result of a nested React.Children.map is not consistent with React.isValidElement

4 participants