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

Add support for React.pure in ReactDOMServer #13855

Merged
merged 2 commits into from Oct 20, 2018

Conversation

@alexmckenley
Copy link
Member

@alexmckenley alexmckenley commented Oct 15, 2018

Add support for REACT_PURE_TYPE in ReactDOMServer + tests

@@ -0,0 +1,112 @@
/**

This comment has been minimized.

@gaearon

gaearon Oct 15, 2018
Member

There's a lot of setup cost for initializing these test modules. Can we put this together with some other tests since there's only a few of test cases here?

@@ -945,7 +946,8 @@ class ReactDOMServerRenderer {
}
if (typeof elementType === 'object' && elementType !== null) {
switch (elementType.$$typeof) {
case REACT_FORWARD_REF_TYPE: {
case REACT_FORWARD_REF_TYPE:
case REACT_PURE_TYPE: {
const element: ReactElement = ((nextChild: any): ReactElement);
const nextChildren = toArray(
elementType.render(element.props, element.ref),

This comment has been minimized.

@sebmarkbage

sebmarkbage Oct 15, 2018
Member

This is not correct. It is passing the element.ref second argument. It shouldn't get the second argument in the pure case.

This comment has been minimized.

This comment has been minimized.

@sebmarkbage

sebmarkbage Oct 15, 2018
Member

I didn't see that one. I'm not sure I approve. Let me think about it.

Copy link
Member

@sebmarkbage sebmarkbage left a comment

It would be better to copy/paste the branch so that you can specialize it for the pure use case. In this case, avoid passing the second argument.

@sizebot
Copy link

@sizebot sizebot commented Oct 15, 2018

Details of bundled changes.

Comparing: 15b11d2...28f5c3b

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom-server.browser.development.js +0.6% +0.3% 107.63 KB 108.24 KB 28.54 KB 28.61 KB UMD_DEV
react-dom-server.browser.production.min.js 🔺+1.0% 🔺+0.5% 15.75 KB 15.91 KB 6.02 KB 6.05 KB UMD_PROD
react-dom-server.browser.development.js +0.6% +0.3% 103.76 KB 104.37 KB 27.54 KB 27.63 KB NODE_DEV
react-dom-server.browser.production.min.js 🔺+1.0% 🔺+0.5% 15.65 KB 15.8 KB 6.01 KB 6.04 KB NODE_PROD
react-dom-server.node.development.js +0.6% +0.3% 105.68 KB 106.29 KB 28.1 KB 28.18 KB NODE_DEV
react-dom-server.node.production.min.js 🔺+0.9% 🔺+0.5% 16.46 KB 16.61 KB 6.31 KB 6.34 KB NODE_PROD
ReactDOMServer-dev.js +0.6% +0.3% 103.29 KB 103.93 KB 26.83 KB 26.92 KB FB_WWW_DEV
ReactDOMServer-prod.js 🔺+1.5% 🔺+0.6% 34.48 KB 35 KB 8.3 KB 8.36 KB FB_WWW_PROD

scheduler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
scheduler.development.js n/a n/a 0 B 19.17 KB 0 B 5.74 KB UMD_DEV
scheduler.production.min.js n/a n/a 0 B 3.16 KB 0 B 1.53 KB UMD_PROD

Generated by 🚫 dangerJS

@alexmckenley alexmckenley force-pushed the alexmckenley:ReactDOMServerPure branch from 69ffbb8 to bb472ec Oct 16, 2018
@alexmckenley
Copy link
Member Author

@alexmckenley alexmckenley commented Oct 16, 2018

Moved the tests and branched the REACT_PURE_TYPE logic. I'm still passing the forward ref stuff for now to keep the behavior in sync with ReactDOM (#13855). Let me know if you want to change this behavior.

@gaearon
Copy link
Member

@gaearon gaearon commented Oct 16, 2018

Yeah we're going to revert that and change so that:

  • pure gets one argument
  • It should be possible to render pure(forwardRef()) (but not the other way around)

@acdlite has details

@alexmckenley alexmckenley force-pushed the alexmckenley:ReactDOMServerPure branch from bb472ec to 3cf899e Oct 18, 2018
@alexmckenley
Copy link
Member Author

@alexmckenley alexmckenley commented Oct 18, 2018

Updated my diff so pure works with both functions and forwardRef elements. The tests should pass once pure and react Fiber are updated to respect this new logic.

@sebmarkbage sebmarkbage force-pushed the alexmckenley:ReactDOMServerPure branch from 3cf899e to 345556e Oct 20, 2018
@sebmarkbage
Copy link
Member

@sebmarkbage sebmarkbage commented Oct 20, 2018

I updated on top of #13903. This now uses a slow path to implement pure in a fully recursive form. This is unfortunate but that's the easiest given the structure of the partial renderer. It doesn't make it easy to make recursive custom types.

But we're rewriting this whole engine soon anyway.

alexmckenley and others added 2 commits Oct 15, 2018
This is very slow but meh. We're rewriting this whole thing anyway.
@sebmarkbage sebmarkbage force-pushed the alexmckenley:ReactDOMServerPure branch from 345556e to 28f5c3b Oct 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants
You can’t perform that action at this time.