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

Use single entry point for SSR via browser field #10362

Merged
merged 7 commits into from
Aug 2, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions packages/react-dom/node-stream.js

This file was deleted.

5 changes: 4 additions & 1 deletion packages/react-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@
"README.md",
"index.js",
"server.js",
"node-stream.js",
"test-utils.js",
"unstable-native-dependencies.js",
"cjs/",
"umd/"
],
"browser": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It might be nicer to do this with a more public browser entry point instead of the internal package details (personally I'd prefer not exposing those as separate files at all and just inline them).

With a public entry point it's at least possible to manually require the browser version if you need to. This encourages require to the internal implementation details instead.

"./cjs/react-dom-server-node.development.js": "./cjs/react-dom-server-browser.development.js",
"./cjs/react-dom-server-node.production.min.js": "./cjs/react-dom-server-browser.production.min.js"
},
"browserify": {
"transform": [
"loose-envify"
Expand Down
4 changes: 2 additions & 2 deletions packages/react-dom/server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-dom-server.production.min.js');
module.exports = require('./cjs/react-dom-server-node.production.min.js');
} else {
module.exports = require('./cjs/react-dom-server.development.js');
module.exports = require('./cjs/react-dom-server-node.development.js');
}
14 changes: 7 additions & 7 deletions scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ const bundles = [
moduleName: 'ReactDOMServer',
sourceMap: false,
},
entry: 'src/renderers/dom/ReactDOMServerEntry',
entry: 'src/renderers/dom/ReactDOMServerBrowserEntry',
externals: ['prop-types', 'prop-types/checkPropTypes'],
fbEntry: 'src/renderers/dom/ReactDOMServerEntry',
fbEntry: 'src/renderers/dom/ReactDOMServerBrowserEntry',
hasteName: 'ReactDOMServer',
isRenderer: true,
label: 'dom-server-string',
label: 'dom-server-browser',
manglePropertiesOnProd: false,
name: 'react-dom/server',
name: 'react-dom/server-browser',
paths: [
'src/renderers/dom/**/*.js',
'src/renderers/shared/**/*.js',
Expand All @@ -199,12 +199,12 @@ const bundles = [
moduleName: 'ReactDOMNodeStream',
sourceMap: false,
},
entry: 'src/renderers/dom/ReactDOMNodeStreamEntry',
entry: 'src/renderers/dom/ReactDOMServerNodeEntry',
externals: ['prop-types', 'prop-types/checkPropTypes', 'stream'],
isRenderer: true,
label: 'dom-server-node-stream',
label: 'dom-server-server-node',
manglePropertiesOnProd: false,
name: 'react-dom/node-stream',
name: 'react-dom/server-node',
paths: [
'src/renderers/dom/**/*.js',
'src/renderers/shared/**/*.js',
Expand Down
56 changes: 40 additions & 16 deletions scripts/rollup/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@
"gzip": 6703
},
"react-dom.development.js (UMD_DEV)": {
"size": 639824,
"gzip": 145999
"size": 640604,
"gzip": 146616
},
"react-dom.production.min.js (UMD_PROD)": {
"size": 121920,
"gzip": 38871
"size": 121735,
"gzip": 38859
},
"react-dom.development.js (NODE_DEV)": {
"size": 599220,
"gzip": 136402
"size": 599999,
"gzip": 136960
},
"react-dom.production.min.js (NODE_PROD)": {
"size": 118838,
"gzip": 37788
"size": 118657,
"gzip": 37769
},
"ReactDOMFiber-dev.js (FB_DEV)": {
"size": 595749,
"gzip": 135868
"size": 596499,
"gzip": 136409
},
"ReactDOMFiber-prod.js (FB_PROD)": {
"size": 431003,
"gzip": 96867
"size": 430689,
"gzip": 96928
},
"react-dom-test-utils.development.js (NODE_DEV)": {
"size": 56074,
Expand Down Expand Up @@ -181,12 +181,12 @@
"gzip": 50920
},
"ReactDOMServer-dev.js (FB_DEV)": {
"size": 91224,
"gzip": 23517
"size": 91053,
"gzip": 23562
},
"ReactDOMServer-prod.js (FB_PROD)": {
"size": 55353,
"gzip": 15240
"size": 49472,
"gzip": 13857
},
"react-dom-node-stream.development.js (NODE_DEV)": {
"size": 93872,
Expand Down Expand Up @@ -227,6 +227,30 @@
"ReactDOMUnstableNativeDependencies-prod.js (FB_PROD)": {
"size": 67256,
"gzip": 16011
},
"react-dom-server-browser.development.js (UMD_DEV)": {
"size": 122830,
"gzip": 31052
},
"react-dom-server-browser.production.min.js (UMD_PROD)": {
"size": 21723,
"gzip": 8267
},
"react-dom-server-browser.development.js (NODE_DEV)": {
"size": 91970,
"gzip": 23650
},
"react-dom-server-browser.production.min.js (NODE_PROD)": {
"size": 20124,
"gzip": 7655
},
"react-dom-server-node.development.js (NODE_DEV)": {
"size": 93701,
"gzip": 24143
},
"react-dom-server-node.production.min.js (NODE_PROD)": {
"size": 20958,
"gzip": 7968
}
}
}
14 changes: 0 additions & 14 deletions src/node_modules/react-dom/node-stream.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/node_modules/react-dom/server.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule ReactDOMServerEntry
* @providesModule ReactDOMServerBrowserEntry
*/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could add shims that throw for renderToStream() APIs here. Then it's less mysterious.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes that would be nice.

'use strict';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule ReactDOMNodeStreamEntry
* @providesModule ReactDOMServerNodeEntry
*/

'use strict';

var ReactDOMStringRenderer = require('ReactDOMStringRenderer');
var ReactDOMNodeStreamRenderer = require('ReactDOMNodeStreamRenderer');
var ReactVersion = require('ReactVersion');

require('ReactDOMInjection');

module.exports = {
renderToString: ReactDOMStringRenderer.renderToString,
renderToStaticMarkup: ReactDOMStringRenderer.renderToStaticMarkup,
renderToStream: ReactDOMNodeStreamRenderer.renderToStream,
renderToStaticStream: ReactDOMNodeStreamRenderer.renderToStaticStream,
version: ReactVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ let PropTypes;
let React;
let ReactDOM;
let ReactDOMServer;
let ReactDOMNodeStream;
let ReactTestUtils;

const stream = require('stream');
Expand Down Expand Up @@ -120,7 +119,7 @@ async function renderIntoStream(reactElement, errorCount = 0) {
() =>
new Promise(resolve => {
let writable = new DrainWritable();
ReactDOMNodeStream.renderToStream(reactElement).pipe(writable);
ReactDOMServer.renderToStream(reactElement).pipe(writable);
writable.on('finish', () => resolve(writable.buffer));
}),
errorCount,
Expand Down Expand Up @@ -347,14 +346,6 @@ function resetModules() {
}
require('ReactFeatureFlags').disableNewFiberFeatures = false;
ReactDOMServer = require('react-dom/server');

// Finally, reset modules one more time before importing the stream renderer.
jest.resetModuleRegistry();
if (typeof onAfterResetModules === 'function') {
onAfterResetModules();
}
require('ReactFeatureFlags').disableNewFiberFeatures = false;
ReactDOMNodeStream = require('react-dom/node-stream');
}

describe('ReactDOMServerIntegration', () => {
Expand Down