|
| 1 | +## June 2 ([discuss](https://github.com/reactjs/core-notes/pull/18)) |
| 2 | + |
| 3 | +### Attendees |
| 4 | + |
| 5 | +* [Ben](https://twitter.com/soprano) (React) |
| 6 | +* [Jim](http://github.com/jimfb) (React) |
| 7 | +* [Keyan](https://twitter.com/keyanzhang) (React, intern) |
| 8 | +* [Paul](https://twitter.com/zpao) (React) |
| 9 | +* [Sebastian](https://twitter.com/sebmarkbage) (React) |
| 10 | +* [Shayne](https://github.com/shayne) (React Native) |
| 11 | +* [Tom](https://twitter.com/tomocchino) (React) |
| 12 | + |
| 13 | +### Getting Rid of `PureRenderMixin` |
| 14 | + |
| 15 | +* This is one of the most commonly used mixins. |
| 16 | +* We need to have a good story around applying it to classes and SFCs (**stateless functional components**). |
| 17 | +* Let’s consider a few alternatives. |
| 18 | + |
| 19 | +#### Proposal 1: `PureComponent` and heuristics for SFCs |
| 20 | + |
| 21 | +* Create `React.PureComponent` base class (kinda like a class with `PureRenderMixin`). |
| 22 | +* Make SFCs “inherit” their purity from the closest class-based parent. |
| 23 | +* This works because if the class above is pure, SFC wouldn’t re-render anyway. |
| 24 | +* Implemented in [#6914](https://github.com/facebook/react/pull/6914) with some additional explanation [here](https://github.com/facebook/react/pull/6914#issuecomment-222364942). |
| 25 | + |
| 26 | +##### Concerns |
| 27 | + |
| 28 | +* Any heuristics based model will probably not work in 100% of cases, and could cause confusion. |
| 29 | +* If you pass children through, you don’t know anything about them, including whether they use mutation. |
| 30 | + |
| 31 | +##### Potential Mitigations |
| 32 | + |
| 33 | +* Warn if a `PureComponent` takes in a child element (or child element which changes). |
| 34 | +* In dev mode, do dry-run reconciliation past all `shouldComponentUpdate`s and warn if `shouldComponentUpdate` lied to React. |
| 35 | + |
| 36 | +#### Proposal 2: SFCs Always Shallowly Compare Props |
| 37 | + |
| 38 | +* Effectively a `PureRenderMixin` on every SFC. |
| 39 | + |
| 40 | +##### Concerns |
| 41 | + |
| 42 | +* Means that component authors generally can’t / shouldn’t use SFCs because `PureRenderMixin` shouldn’t be used with components that take children. |
| 43 | +* Intuitively, people expect SFCs to behave like functions. The bailout would be surprising, and there isn’t a particularly good way of discovering why the function isn’t behaving like a normal JavaScript function. |
| 44 | +* Performance. It’s not clear that adding `PureRenderMixin` to every SFC would actually improve overall performance (because it means extra reads/compares, retaining objects longer and into subsequent GC generations, etc). |
| 45 | + |
| 46 | +#### Proposal 3: `createPureElement` |
| 47 | + |
| 48 | +* Provide some flag on components at the calling side to denote that they should be pure. |
| 49 | +* This would tell React to effectively “use `PureRenderMixin`” on that particular instance, *not all instances*. |
| 50 | +* Many syntax possibilities: `pure={true}`, or `<*Component />`, `React.createPureElement()`, etc. |
| 51 | + |
| 52 | +### ES Class Progress |
| 53 | + |
| 54 | +* [Ben](https://twitter.com/soprano) is leading the effort to port Facebook codebase to ES classes. |
| 55 | +* We plan to enable property initializer syntax internally, and codemod all methods except lifecycles to it. |
| 56 | + |
| 57 | +------------ |
| 58 | + |
| 59 | +Please feel free to discuss these notes in the [corresponding pull request](https://github.com/reactjs/core-notes/pull/18). |
0 commit comments