Skip to content

Commit 46fa20f

Browse files
TrySoundjquense
authored andcommitted
fix: strip custom prop-types in production (#448)
Minified size with bundled dependencies before 17.53 KB After 16.66 KB
1 parent 200bfc3 commit 46fa20f

File tree

6 files changed

+461
-224
lines changed

6 files changed

+461
-224
lines changed

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
"travis-deploy-once": "travis-deploy-once",
2222
"semantic-release": "semantic-release"
2323
},
24+
"size-limit": [
25+
{
26+
"gzip": false,
27+
"path": "lib/index.js",
28+
"limit": "16.66 KB"
29+
}
30+
],
2431
"repository": {
2532
"type": "git",
2633
"url": "https://github.com/reactjs/react-transition-group.git"
@@ -94,6 +101,7 @@
94101
"semantic-release": "^15.9.16",
95102
"semantic-release-alt-publish-dir": "^2.1.1",
96103
"sinon": "^6.3.4",
104+
"size-limit": "^0.21.1",
97105
"travis-deploy-once": "^5.0.8",
98106
"webpack": "^4.19.1",
99107
"webpack-atoms": "^8.0.0",

src/CSSTransition.js

Lines changed: 98 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -10,105 +10,6 @@ import { classNamesShape } from './utils/PropTypes';
1010
const addClass = (node, classes) => node && classes && classes.split(' ').forEach(c => addOneClass(node, c));
1111
const removeClass = (node, classes) => node && classes && classes.split(' ').forEach(c => removeOneClass(node, c));
1212

13-
const propTypes = {
14-
...Transition.propTypes,
15-
16-
/**
17-
* The animation classNames applied to the component as it enters, exits or has finished the transition.
18-
* A single name can be provided and it will be suffixed for each stage: e.g.
19-
*
20-
* `classNames="fade"` applies `fade-enter`, `fade-enter-active`, `fade-enter-done`,
21-
* `fade-exit`, `fade-exit-active`, `fade-exit-done`, `fade-appear`, and `fade-appear-active`.
22-
* Each individual classNames can also be specified independently like:
23-
*
24-
* ```js
25-
* classNames={{
26-
* appear: 'my-appear',
27-
* appearActive: 'my-active-appear',
28-
* enter: 'my-enter',
29-
* enterActive: 'my-active-enter',
30-
* enterDone: 'my-done-enter',
31-
* exit: 'my-exit',
32-
* exitActive: 'my-active-exit',
33-
* exitDone: 'my-done-exit',
34-
* }}
35-
* ```
36-
*
37-
* If you want to set these classes using CSS Modules:
38-
*
39-
* ```js
40-
* import styles from './styles.css';
41-
* ```
42-
*
43-
* you might want to use camelCase in your CSS file, that way could simply spread
44-
* them instead of listing them one by one:
45-
*
46-
* ```js
47-
* classNames={{ ...styles }}
48-
* ```
49-
*
50-
* @type {string | {
51-
* appear?: string,
52-
* appearActive?: string,
53-
* enter?: string,
54-
* enterActive?: string,
55-
* enterDone?: string,
56-
* exit?: string,
57-
* exitActive?: string,
58-
* exitDone?: string,
59-
* }}
60-
*/
61-
classNames: classNamesShape,
62-
63-
/**
64-
* A `<Transition>` callback fired immediately after the 'enter' or 'appear' class is
65-
* applied.
66-
*
67-
* @type Function(node: HtmlElement, isAppearing: bool)
68-
*/
69-
onEnter: PropTypes.func,
70-
71-
/**
72-
* A `<Transition>` callback fired immediately after the 'enter-active' or
73-
* 'appear-active' class is applied.
74-
*
75-
* @type Function(node: HtmlElement, isAppearing: bool)
76-
*/
77-
onEntering: PropTypes.func,
78-
79-
/**
80-
* A `<Transition>` callback fired immediately after the 'enter' or
81-
* 'appear' classes are **removed** and the `done` class is added to the DOM node.
82-
*
83-
* @type Function(node: HtmlElement, isAppearing: bool)
84-
*/
85-
onEntered: PropTypes.func,
86-
87-
88-
/**
89-
* A `<Transition>` callback fired immediately after the 'exit' class is
90-
* applied.
91-
*
92-
* @type Function(node: HtmlElement)
93-
*/
94-
onExit: PropTypes.func,
95-
96-
/**
97-
* A `<Transition>` callback fired immediately after the 'exit-active' is applied.
98-
*
99-
* @type Function(node: HtmlElement)
100-
*/
101-
onExiting: PropTypes.func,
102-
103-
/**
104-
* A `<Transition>` callback fired immediately after the 'exit' classes
105-
* are **removed** and the `exit-done` class is added to the DOM node.
106-
*
107-
* @type Function(node: HtmlElement)
108-
*/
109-
onExited: PropTypes.func,
110-
};
111-
11213
/**
11314
* A `Transition` component using CSS transitions and animations.
11415
* It's inspired by the excellent [ng-animate](http://www.nganimate.org/) library.
@@ -246,6 +147,103 @@ class CSSTransition extends React.Component {
246147
}
247148
}
248149

249-
CSSTransition.propTypes = propTypes;
150+
CSSTransition.propTypes = {
151+
...Transition.propTypes,
152+
153+
/**
154+
* The animation classNames applied to the component as it enters, exits or has finished the transition.
155+
* A single name can be provided and it will be suffixed for each stage: e.g.
156+
*
157+
* `classNames="fade"` applies `fade-enter`, `fade-enter-active`, `fade-enter-done`,
158+
* `fade-exit`, `fade-exit-active`, `fade-exit-done`, `fade-appear`, and `fade-appear-active`.
159+
* Each individual classNames can also be specified independently like:
160+
*
161+
* ```js
162+
* classNames={{
163+
* appear: 'my-appear',
164+
* appearActive: 'my-active-appear',
165+
* enter: 'my-enter',
166+
* enterActive: 'my-active-enter',
167+
* enterDone: 'my-done-enter',
168+
* exit: 'my-exit',
169+
* exitActive: 'my-active-exit',
170+
* exitDone: 'my-done-exit',
171+
* }}
172+
* ```
173+
*
174+
* If you want to set these classes using CSS Modules:
175+
*
176+
* ```js
177+
* import styles from './styles.css';
178+
* ```
179+
*
180+
* you might want to use camelCase in your CSS file, that way could simply spread
181+
* them instead of listing them one by one:
182+
*
183+
* ```js
184+
* classNames={{ ...styles }}
185+
* ```
186+
*
187+
* @type {string | {
188+
* appear?: string,
189+
* appearActive?: string,
190+
* enter?: string,
191+
* enterActive?: string,
192+
* enterDone?: string,
193+
* exit?: string,
194+
* exitActive?: string,
195+
* exitDone?: string,
196+
* }}
197+
*/
198+
classNames: classNamesShape,
199+
200+
/**
201+
* A `<Transition>` callback fired immediately after the 'enter' or 'appear' class is
202+
* applied.
203+
*
204+
* @type Function(node: HtmlElement, isAppearing: bool)
205+
*/
206+
onEnter: PropTypes.func,
207+
208+
/**
209+
* A `<Transition>` callback fired immediately after the 'enter-active' or
210+
* 'appear-active' class is applied.
211+
*
212+
* @type Function(node: HtmlElement, isAppearing: bool)
213+
*/
214+
onEntering: PropTypes.func,
215+
216+
/**
217+
* A `<Transition>` callback fired immediately after the 'enter' or
218+
* 'appear' classes are **removed** and the `done` class is added to the DOM node.
219+
*
220+
* @type Function(node: HtmlElement, isAppearing: bool)
221+
*/
222+
onEntered: PropTypes.func,
223+
224+
225+
/**
226+
* A `<Transition>` callback fired immediately after the 'exit' class is
227+
* applied.
228+
*
229+
* @type Function(node: HtmlElement)
230+
*/
231+
onExit: PropTypes.func,
232+
233+
/**
234+
* A `<Transition>` callback fired immediately after the 'exit-active' is applied.
235+
*
236+
* @type Function(node: HtmlElement)
237+
*/
238+
onExiting: PropTypes.func,
239+
240+
/**
241+
* A `<Transition>` callback fired immediately after the 'exit' classes
242+
* are **removed** and the `exit-done` class is added to the DOM node.
243+
*
244+
* @type Function(node: HtmlElement)
245+
*/
246+
onExited: PropTypes.func,
247+
};
250248

251249
export default CSSTransition

src/ReplaceTransition.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@ import React from 'react';
33
import { findDOMNode } from 'react-dom'
44
import TransitionGroup from './TransitionGroup';
55

6-
const propTypes = {
7-
in: PropTypes.bool.isRequired,
8-
children(props, propName) {
9-
if (React.Children.count(props[propName]) !== 2)
10-
return new Error(`"${propName}" must be exactly two transition components.`)
11-
12-
return null;
13-
},
14-
};
15-
166
/**
177
* The `<ReplaceTransition>` component is a specialized `Transition` component
188
* that animates between two children.
@@ -78,6 +68,14 @@ class ReplaceTransition extends React.Component {
7868
}
7969
}
8070

81-
ReplaceTransition.propTypes = propTypes;
71+
ReplaceTransition.propTypes = {
72+
in: PropTypes.bool.isRequired,
73+
children(props, propName) {
74+
if (React.Children.count(props[propName]) !== 2)
75+
return new Error(`"${propName}" must be exactly two transition components.`)
76+
77+
return null;
78+
},
79+
};
8280

8381
export default ReplaceTransition;

src/TransitionGroup.js

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,55 +11,6 @@ import {
1111

1212
const values = Object.values || (obj => Object.keys(obj).map(k => obj[k]))
1313

14-
const propTypes = {
15-
/**
16-
* `<TransitionGroup>` renders a `<div>` by default. You can change this
17-
* behavior by providing a `component` prop.
18-
* If you use React v16+ and would like to avoid a wrapping `<div>` element
19-
* you can pass in `component={null}`. This is useful if the wrapping div
20-
* borks your css styles.
21-
*/
22-
component: PropTypes.any,
23-
/**
24-
* A set of `<Transition>` components, that are toggled `in` and out as they
25-
* leave. the `<TransitionGroup>` will inject specific transition props, so
26-
* remember to spread them through if you are wrapping the `<Transition>` as
27-
* with our `<Fade>` example.
28-
*/
29-
children: PropTypes.node,
30-
31-
/**
32-
* A convenience prop that enables or disables appear animations
33-
* for all children. Note that specifying this will override any defaults set
34-
* on individual children Transitions.
35-
*/
36-
appear: PropTypes.bool,
37-
/**
38-
* A convenience prop that enables or disables enter animations
39-
* for all children. Note that specifying this will override any defaults set
40-
* on individual children Transitions.
41-
*/
42-
enter: PropTypes.bool,
43-
/**
44-
* A convenience prop that enables or disables exit animations
45-
* for all children. Note that specifying this will override any defaults set
46-
* on individual children Transitions.
47-
*/
48-
exit: PropTypes.bool,
49-
50-
/**
51-
* You may need to apply reactive updates to a child as it is exiting.
52-
* This is generally done by using `cloneElement` however in the case of an exiting
53-
* child the element has already been removed and not accessible to the consumer.
54-
*
55-
* If you do need to update a child as it leaves you can provide a `childFactory`
56-
* to wrap every child, even the ones that are leaving.
57-
*
58-
* @type Function(child: ReactElement) -> ReactElement
59-
*/
60-
childFactory: PropTypes.func,
61-
}
62-
6314
const defaultProps = {
6415
component: 'div',
6516
childFactory: child => child,
@@ -157,7 +108,55 @@ class TransitionGroup extends React.Component {
157108
}
158109
}
159110

160-
TransitionGroup.propTypes = propTypes
111+
TransitionGroup.propTypes = {
112+
/**
113+
* `<TransitionGroup>` renders a `<div>` by default. You can change this
114+
* behavior by providing a `component` prop.
115+
* If you use React v16+ and would like to avoid a wrapping `<div>` element
116+
* you can pass in `component={null}`. This is useful if the wrapping div
117+
* borks your css styles.
118+
*/
119+
component: PropTypes.any,
120+
/**
121+
* A set of `<Transition>` components, that are toggled `in` and out as they
122+
* leave. the `<TransitionGroup>` will inject specific transition props, so
123+
* remember to spread them through if you are wrapping the `<Transition>` as
124+
* with our `<Fade>` example.
125+
*/
126+
children: PropTypes.node,
127+
128+
/**
129+
* A convenience prop that enables or disables appear animations
130+
* for all children. Note that specifying this will override any defaults set
131+
* on individual children Transitions.
132+
*/
133+
appear: PropTypes.bool,
134+
/**
135+
* A convenience prop that enables or disables enter animations
136+
* for all children. Note that specifying this will override any defaults set
137+
* on individual children Transitions.
138+
*/
139+
enter: PropTypes.bool,
140+
/**
141+
* A convenience prop that enables or disables exit animations
142+
* for all children. Note that specifying this will override any defaults set
143+
* on individual children Transitions.
144+
*/
145+
exit: PropTypes.bool,
146+
147+
/**
148+
* You may need to apply reactive updates to a child as it is exiting.
149+
* This is generally done by using `cloneElement` however in the case of an exiting
150+
* child the element has already been removed and not accessible to the consumer.
151+
*
152+
* If you do need to update a child as it leaves you can provide a `childFactory`
153+
* to wrap every child, even the ones that are leaving.
154+
*
155+
* @type Function(child: ReactElement) -> ReactElement
156+
*/
157+
childFactory: PropTypes.func,
158+
}
159+
161160
TransitionGroup.defaultProps = defaultProps
162161

163162
export default polyfill(TransitionGroup)

0 commit comments

Comments
 (0)