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

remove className usage checker & suppression prop #2563

Merged
merged 3 commits into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ _The format is based on [Keep a Changelog](http://keepachangelog.com/) and this

## Unreleased

- Remove className usage checker dev utility due to excessive false-positive noise in certain runtime environments like next.js and the related warning suppression prop (see [#2563](https://github.com/styled-components/styled-components/issues/2563)).

- Attach displayName to forwardRef function as described in React docs (see [#2508](https://github.com/styled-components/styled-components/issues/2508)).

- Compatibility with react-native-web 0.11 (see [#2453](https://github.com/styled-components/styled-components/issues/2453)).

- Add stack trace to .attrs warning (see [#2486](https://github.com/styled-components/styled-components/issues/2486)).

## [v4.2.0] - 2019-03-23

- Reduced GC pressure when using component selector styles. (see [#2424](https://github.com/styled-components/styled-components/issues/2424)).
Expand Down
14 changes: 4 additions & 10 deletions packages/styled-components/src/models/StyledComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ import StyleSheet from './StyleSheet';
import { ThemeConsumer, type Theme } from './ThemeProvider';
import { StyleSheetConsumer } from './StyleSheetManager';
import { EMPTY_ARRAY, EMPTY_OBJECT } from '../utils/empties';
import classNameUsageCheckInjector from '../utils/classNameUsageCheckInjector';

import type { Attrs, RuleSet, Target } from '../types';
import { IS_BROWSER } from '../constants';

const identifiers = {};

Expand Down Expand Up @@ -74,7 +72,7 @@ class StyledComponent extends Component<*> {
// eslint-disable-next-line no-console
console.warn(
`Functions as object-form attrs({}) keys are now deprecated and will be removed in a future version of styled-components. Switch to the new attrs(props => ({})) syntax instead for easier and more powerful composition. The attrs key in question is "${key}" on component "${displayName}".`,
`\n ${(new Error()).stack}`
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 a reason why it was this way, maybe browser compat? Is this safe to change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

idk, prettier removed it so I assume a safe transform

`\n ${new Error().stack}`
)
);

Expand All @@ -89,10 +87,6 @@ class StyledComponent extends Component<*> {
)
);
}

if (process.env.NODE_ENV !== 'production' && IS_BROWSER) {
classNameUsageCheckInjector(this);
}
}

render() {
Expand Down Expand Up @@ -146,9 +140,9 @@ class StyledComponent extends Component<*> {
this.warnInnerRef(displayName);
}

if (key === 'forwardedComponent' || key === 'as' || key === 'suppressClassNameWarning')
{continue;}
else if (key === 'forwardedRef') propsForElement.ref = computedProps[key];
if (key === 'forwardedComponent' || key === 'as') {
continue;
} else if (key === 'forwardedRef') propsForElement.ref = computedProps[key];
else if (!isTargetTag || validAttr(key)) {
// Don't pass through non HTML tags through to HTML elements
propsForElement[key] = computedProps[key];
Expand Down
50 changes: 0 additions & 50 deletions packages/styled-components/src/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,6 @@ describe('basic', () => {
expect(wrapper.testRef.current).toBe(innerComponent);
});

it('should not pass the suppressClassNameWarning to the wrapped child', () => {
const OuterComponent = styled(InnerComponent)``;

class Wrapper extends Component<*, *> {
render() {
return <OuterComponent suppressClassNameWarning />
}
}

const wrapper = TestRenderer.create(<Wrapper />);
expect(wrapper.root.findByType(InnerComponent).props.suppressClassNameWarning).toBeUndefined();
});

it('should respect the order of StyledComponent creation for CSS ordering', () => {
const FirstComponent = styled.div`
color: red;
Expand Down Expand Up @@ -358,42 +345,5 @@ describe('basic', () => {
TestRenderer.create(<Comp innerRef={ref} />);
expect(console.warn).not.toHaveBeenCalled();
});

it('warns when a wrapped React component does not consume className', () => {
const Inner = () => <div />;
const Comp = styled(Inner)`
color: red;
`;

renderIntoDocument(
<div>
<Comp />
</div>
);

expect(console.warn.mock.calls[0][0]).toMatchInlineSnapshot(
`"It looks like you've wrapped styled() around your React component (Inner), but the className prop is not being passed down to a child. No styles will be rendered unless className is composed within your React component."`
);
});

it('does not warn if the className is consumed by a deeper child', () => {
const Inner = ({ className }) => (
<div>
<span className={className} />
</div>
);

const Comp = styled(Inner)`
color: red;
`;

renderIntoDocument(
<div>
<Comp />
</div>
);

expect(console.warn).not.toHaveBeenCalled();
});
});
});

This file was deleted.

This file was deleted.