Skip to content
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

packagekit: Swap out many divs and spans for React.Fragment #9309

Merged
merged 1 commit into from
Oct 2, 2018

Conversation

garrett
Copy link
Member

@garrett garrett commented Jun 5, 2018

No description provided.

@garrett garrett requested a review from martinpitt June 5, 2018 14:29
@garrett
Copy link
Member Author

garrett commented Jun 5, 2018

This isn't working properly at the moment. At least I did get it compiling, however. 🤷‍♂️ Is it due to react-lite? or something else?

@@ -172,9 +172,9 @@ function HeaderBar(props) {
actionButton = <button className="btn btn-default" onClick={props.onRefresh} >{_("Check for Updates")}</button>;
if (props.timeSinceRefresh !== null) {
lastChecked = (
<span style={ {paddingRight: "3ex"} }>
Copy link
Member Author

Choose a reason for hiding this comment

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

There shouldn't be inline CSS. This should be a CSS rule in the stylesheet. (I have it fixed in my mobile changes.)

));

return <div>{paragraphs}</div>;
return <React.Fragment>{paragraphs}</React.Fragment>;
Copy link
Member Author

Choose a reason for hiding this comment

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

Should this just be the following?

return paragraphs;

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think returning a list of elements is actually legitimate and works. I suppose I just didn't know about that yet when I wrote this. In the same vein, if Fragment does not work with react-lite, the other cases could actually use the same trick? I. e. return a (static) array?

Copy link
Contributor

Choose a reason for hiding this comment

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

returning an array, no matter if static or generated, works fine. Just the key prop needs to be set

pkg/packagekit/updates.jsx Outdated Show resolved Hide resolved
@mareklibra
Copy link
Contributor

The React.Fragment is new feature in v16, so will be available after #9263

@mareklibra
Copy link
Contributor

@garrett , to avoid conflicts and make this directly with the Fragment, wouldn't it make sense to stack this on #9263 ?

Btw, returning an array of elements work, as already used on other places as a workaround, but it breaks React component hierarchy since you need to introduce a helper function providing such an array. The function can't be a React component.

@garrett
Copy link
Member Author

garrett commented Jun 6, 2018

@mareklibra: After #9263 is merged, we can go thought and fix things properly (outside of this PR).

I'd suggest we stick to the shorthand, <> and </>, provided it works afterward. (We'd just need a recent enough version of React for it.)

@mareklibra
Copy link
Contributor

We'd just need a recent enough version of React for it.

That's the point, react-lite implements v15 (and not entirely). There's nothing newer between recent react-lite and the #9263 .

Anyway, I'm fine with recent workaround via array of elements. Just seems like a double-work from my POV.

@garrett
Copy link
Member Author

garrett commented Jun 6, 2018

@mareklibra The problem is that if we don't go with a new and official enough version of React, then there's tag soup, with divs and spans all over the place — none of which have any semantic meaning, and some can definitely get in the way of various types of layout too.

Without actual meaning, this makes accessibility much harder to properly implement.

All the div and span nesting increases the DOM node usage, especially when in loops, making the page more complex and slower overall. This is especially noticeable in loadtime, rendertime, memory usage, with CSS, and when using JavaScript (especially JavaScript DOM traversing and manipulation).

@garrett
Copy link
Member Author

garrett commented Jun 6, 2018

(So, yeah, even just for fragments, I'm already sold on switching away from React lite.)

@martinpitt
Copy link
Member

This is now unblocked, React switch landed (PR #9263)

{ cockpit.format(_("Last checked: $0 ago"), moment.duration(props.timeSinceRefresh * 1000).humanize()) }
</span>
</React.Fragment>
Copy link
Member

Choose a reason for hiding this comment

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

This is just a single text element, so I don't think it needs to be a fragment at all. The span was just done for the paddingRight, but that's now gone anyway (and probably never worked because of unsafe-inline CSP)

@garrett garrett force-pushed the react-fragment branch 4 times, most recently from 6dd6165 to a704cc1 Compare September 25, 2018 07:54
@martinpitt martinpitt changed the title WIP: swapped out many divs and spans for React.Fragment packagekit: Swap out many divs and spans for React.Fragment Oct 2, 2018
Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

I dropped the one nnecessary fragment, rebased to current master. I tested this interactively, visually it all looks fine. Thanks!

@garrett
Copy link
Member Author

garrett commented Oct 2, 2018

@martinpitt: Nice! Thanks!

@martinpitt martinpitt merged commit 04116d2 into cockpit-project:master Oct 2, 2018
garrett added a commit to garrett/cockpit that referenced this pull request Oct 17, 2018
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.

3 participants