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

Render Component that returns null #195

Merged
merged 1 commit into from
Nov 28, 2016
Merged

Render Component that returns null #195

merged 1 commit into from
Nov 28, 2016

Conversation

sdoomz
Copy link
Contributor

@sdoomz sdoomz commented Nov 17, 2016

Since React 15 has been released no more <noscript> tag needed

@sdoomz sdoomz changed the title Render components that returns null Render Component that returns null Nov 17, 2016
@gajus
Copy link
Owner

gajus commented Nov 17, 2016

This would be a breaking change. Cannot merge this without (a) introducing a peerDependency setting to package.json and releasing a new major.

In the mean time, this does not break anything in React v0.15, therefore it is safe to leave this PR hanging until general adoptoption of the lastest React version.

Thank you

@sdoomz
Copy link
Contributor Author

sdoomz commented Nov 17, 2016

Currently :last-child pseudo-selector doesn't work as expected after applying CSSModules.

Last component wrapped with CSSModules:

<div>
  <button></button>
  <noscript/>
</div>

Last component is a pure react function

<div>
   <button></button>
   <!-- react-empty: 1 -->
</div>

Thank you for your fast reaction

@gajus
Copy link
Owner

gajus commented Nov 17, 2016

This behaviour could be made conditional. I think. Need to think more about the implications.

@ipanasenko
Copy link

ipanasenko commented Nov 17, 2016

What do you think if we check React version and return <noscript> or null correspondingly?

@gajus
Copy link
Owner

gajus commented Nov 17, 2016

What do you think if we check React version and return <noscript> or null correspondingly?

Thats what I am thinking too. I suppose it is reasonable that developer's styling can break in this instance when updating the React version. Albeit, it is confusing since the break is being introduced by react-css-modules.

However, in this case, I think that the pros outweigh the cons.

@sdoomz
Copy link
Contributor Author

sdoomz commented Nov 21, 2016

@gajus what do you think about such kind of fix?

Copy link

@ipanasenko ipanasenko left a comment

Choose a reason for hiding this comment

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

You should also add tests to check different React versions

import React from 'react';

export default function () {
const major = React.version.split('.')[0];

Choose a reason for hiding this comment

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

You really need to calculate it once. And you can check if it's < 15 only once too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'am not fully confident that cache is 100% safe for this case. Someone might want to use different react versions with cssModules, isn't he?

Choose a reason for hiding this comment

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

you are checking version of React that you import yourself, it's not going to change on the fly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are right

@sdoomz sdoomz force-pushed the master branch 2 times, most recently from 1aa8dd6 to eb40c80 Compare November 24, 2016 11:02
@sdoomz
Copy link
Contributor Author

sdoomz commented Nov 28, 2016

@gajus any updates for this PR?

@@ -0,0 +1,22 @@
/* eslint-disable max-nested-callbacks, react/prefer-stateless-function, class-methods-use-this */
Copy link
Owner

Choose a reason for hiding this comment

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

Whats the reason for needing react/prefer-stateless-function, class-methods-use-this ?

const major = React.version.split('.')[0];
const nothing = parseInt(major, 10) < 15 ? React.createElement('noscript') : null;

export default nothing;
Copy link
Owner

Choose a reason for hiding this comment

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

Please reformat this to:

import React from 'react';

export default (reactVersion) => {
  const major = reactVersion.split('.')[0];
  const nothing = parseInt(major, 10) < 15 ? React.createElement('noscript') : null;
};

@@ -39,6 +39,7 @@
"husky": "^0.11.9",
"jsdom": "^9.8.3",
"mocha": "^3.1.2",
"proxyquire": "^1.7.10",
Copy link
Owner

Choose a reason for hiding this comment

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

Remove proxyquire dependency.

@@ -39,7 +39,7 @@ export default (Component: Function, defaultStyles: Object, options: Object): Fu
return linkClass(renderResult, styles, options);
}

return React.createElement('noscript');
return nothing;
Copy link
Owner

Choose a reason for hiding this comment

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

Replace with renderNothing(React.version).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed and squashed

} from 'chai';
import proxyquire from 'proxyquire';

describe('renderNothing', () => {
Copy link
Owner

Choose a reason for hiding this comment

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

Test renderNothing as a function.

@gajus gajus merged commit a9c8de2 into gajus:master Nov 28, 2016
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.

3 participants