-
Notifications
You must be signed in to change notification settings - Fork 2k
Framework: Remove react-addons-create-fragment #19105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
} ) | ||
) } | ||
{ map( scripts, ( { extra, src }, key ) => { | ||
return [ |
There was a problem hiding this comment.
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)).
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
30f9189
30f9189
to
e9b212b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs shrinkwrap update?
client/my-sites/pages/page/index.js
Outdated
separator: <MenuSeparator />, | ||
item: ( | ||
return ( | ||
<div> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f015806
f015806
to
122cba4
Compare
D'oh, thanks. Amended the |
Still seeing |
@@ -35,19 +34,17 @@ class EditorMediaModalDetailFileInfo extends React.Component { | |||
break; | |||
|
|||
case 'dimensions': | |||
value = createFragment( { | |||
width: ( | |||
value = ( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
122cba4
to
b30700e
Compare
Could be another dependency's fault. |
There was a problem hiding this 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 👍
Thanks a lot for reviewing @aduth! |
❤️ nicely done! |
That addon contains the
createFragment
function, which does the following: given an object of components, e.g.It adds the object keys as React
key
s 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
key
s directly to those components. Easy example: https://github.com/Automattic/wp-calypso/pull/19105/files#diff-0e2c0c04cc568a7b0c3c3cb7c66b01c9However, 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:
Editor Drawer: Categories
Editor Drawer: Taxonomies (example: Portfolio CPT with 'project' specific taxonomies)
Media Modal: Dimensions ('5184 ✕ 3456' in the example screenshot)
Media Library: Notices
Try e.g. uploading a video file to a site that doesn't have a plan that includes VideoPress.
lib/embed-frame-markup/index.jsx
This is the trickiest to test. It's used by TinyMCE to display embeds. Try embedding something...