Skip to content

Conversation

ockham
Copy link
Contributor

@ockham ockham commented Oct 24, 2017

That addon contains the createFragment function, which does the following: given an object of components, e.g.

    children = createFragment({
      left: props.leftChildren,
      right: props.rightChildren
    });

It adds the object keys as React keys to the components, and spits out an array consisting of these components. So I think its main use case is around working with arrays of components, which in turn is mostly relevant for ordering of sets of somewhat dynamically generated components, see https://reactjs.org/docs/create-fragment.html.

The fix is to add keys directly to those components. Easy example: https://github.com/Automattic/wp-calypso/pull/19105/files#diff-0e2c0c04cc568a7b0c3c3cb7c66b01c9

However, this can be tricky in some cases -- e.g. when we iterate over a list of inputs and want to produce a list of components, but there are more than just one component per input. Wrap in a div you say? <script /> tags in <head /> I say.

To test: Check the relevant occurrences -- they should still work.

Pages: Trash/Delete button in popover menu:

image

Editor Drawer: Categories

image

Editor Drawer: Taxonomies (example: Portfolio CPT with 'project' specific taxonomies)

image

Media Modal: Dimensions ('5184 ✕ 3456' in the example screenshot)

image

Media Library: Notices

Try e.g. uploading a video file to a site that doesn't have a plan that includes VideoPress.

image

lib/embed-frame-markup/index.jsx

This is the trickiest to test. It's used by TinyMCE to display embeds. Try embedding something...

@matticbot
Copy link
Contributor

@ockham ockham self-assigned this Oct 24, 2017
@ockham ockham requested review from jsnmoon and samouri October 24, 2017 13:12
@ockham ockham added Framework [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] In Progress labels Oct 24, 2017
@ockham ockham requested review from jsnajdr, sirreal and aduth October 24, 2017 14:00
} )
) }
{ map( scripts, ( { extra, src }, key ) => {
return [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case we're mapping to create a nested array, e.g. [ [ <script /> ] ] . I think effectively there is no difference, specifically for how we're using it for rendering to string here, but in normal React renders I've observed to have abysmal performance characteristics (e.g. WordPress/gutenberg#3008 (comment)).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I guess I could use flatMap instead...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

30f9189

@ockham ockham force-pushed the remove/react-addons-create-fragment branch from 30f9189 to e9b212b Compare October 25, 2017 10:07
@samouri samouri mentioned this pull request Oct 25, 2017
10 tasks
Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs shrinkwrap update?

separator: <MenuSeparator />,
item: (
return (
<div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any advantage to adding a wrapping div over returning an array and specifying keys for each element? Seems like it could be nice to avoid an unnecessary DOM element.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, fair enough. I was trying to avoid arrays altogether, but I guess there's no harm in keeping them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f015806

@ockham ockham force-pushed the remove/react-addons-create-fragment branch from f015806 to 122cba4 Compare October 26, 2017 19:26
@ockham
Copy link
Contributor Author

ockham commented Oct 26, 2017

Needs shrinkwrap update?

D'oh, thanks. Amended the Framework: Remove react-addons-create-fragment commit to include it.

@aduth
Copy link
Member

aduth commented Oct 26, 2017

Amended the Framework: Remove react-addons-create-fragment commit to include it.

Still seeing react-addons-create-fragment in shrinkwrap on my end.

@@ -35,19 +34,17 @@ class EditorMediaModalDetailFileInfo extends React.Component {
break;

case 'dimensions':
value = createFragment( {
width: (
value = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be array too. Not a big deal, but potential for styling or performance implications (by DOM node count) with wrappers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will that work with the ' ✕ ' string? Oh well, I'll try and find out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will that work with the ' ✕ ' string? Oh well, I'll try and find out.

I believe it handles strings fine without the key.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, still shows up fine, and no console warnings. 34f16c7

@ockham ockham force-pushed the remove/react-addons-create-fragment branch from 122cba4 to b30700e Compare October 26, 2017 19:43
@ockham
Copy link
Contributor Author

ockham commented Oct 26, 2017

Still seeing react-addons-create-fragment in shrinkwrap on my end.

Could be another dependency's fault.

@aduth
Copy link
Member

aduth commented Oct 26, 2017

Not sure why, but I'm seeing the trash button in Page list menu not extending to occupy the full width of the popover, and not seeing the same in production:

image

@ockham
Copy link
Contributor Author

ockham commented Oct 26, 2017

Hmm. Looks fine here (I switched to English to be sure):

image

What about that little 'Private' indicator in your popover menu? Is that supposed to be there? Cause my screenshot was also taken on a private site, and I don't see anything like that...

@ockham
Copy link
Contributor Author

ockham commented Oct 26, 2017

Oh, so that's a private page 🤦‍♂️

Anyway:

image

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was running a stale version of the branch. All good now 👍

@aduth aduth added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Oct 26, 2017
@ockham
Copy link
Contributor Author

ockham commented Oct 26, 2017

Thanks a lot for reviewing @aduth!

@sirreal
Copy link
Member

sirreal commented Oct 27, 2017

❤️ nicely done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants