@samitouri / QOS-React-2 / commits / 8faca765e1

Update ReactServerRendering for the modern world

* ReactComponents aren't really the thing we need, ReactElements are * Remove the deprecation notice that we've had in there for a long time Test Plan: build, jest

Paul O’Shannessy committed Oct 7, 2014 at 19:00 UTC 8faca765e137037a8d0e708ad7165bf8ac6a5c94
2 files changed +12 -32
src/browser/server/ReactServerRendering.js
+10 -16
@@ -28,19 +28,13 @@ var instantiateReactComponent = require('instantiateReactComponent');
28 var invariant = require('invariant');
29
30 /**
31 - * @param {ReactComponent} component
31 + * @param {ReactElement} element
32 * @return {string} the HTML markup
33 */
34 -function renderComponentToString(component) {
34 +function renderComponentToString(element) {
35 invariant(
36 - ReactElement.isValidElement(component),
37 - 'renderComponentToString(): You must pass a valid ReactComponent.'
38 - );
39 -
40 - invariant(
41 - !(arguments.length === 2 && typeof arguments[1] === 'function'),
42 - 'renderComponentToString(): This function became synchronous and now ' +
43 - 'returns the generated markup. Please remove the second parameter.'
36 + ReactElement.isValidElement(element),
37 + 'renderComponentToString(): You must pass a valid ReactElement.'
38 );
39
40 var transaction;
@@ -49,7 +43,7 @@ function renderComponentToString(component) {
43 transaction = ReactServerRenderingTransaction.getPooled(false);
44
45 return transaction.perform(function() {
52 - var componentInstance = instantiateReactComponent(component, null);
46 + var componentInstance = instantiateReactComponent(element, null);
47 var markup = componentInstance.mountComponent(id, transaction, 0);
48 return ReactMarkupChecksum.addChecksumToMarkup(markup);
49 }, null);
@@ -59,14 +53,14 @@ function renderComponentToString(component) {
53 }
54
55 /**
62 - * @param {ReactComponent} component
56 + * @param {ReactElement} element
57 * @return {string} the HTML markup, without the extra React ID and checksum
58 * (for generating static pages)
59 */
66 -function renderComponentToStaticMarkup(component) {
60 +function renderComponentToStaticMarkup(element) {
61 invariant(
68 - ReactElement.isValidElement(component),
69 - 'renderComponentToStaticMarkup(): You must pass a valid ReactComponent.'
62 + ReactElement.isValidElement(element),
63 + 'renderComponentToStaticMarkup(): You must pass a valid ReactElement.'
64 );
65
66 var transaction;
@@ -75,7 +69,7 @@ function renderComponentToStaticMarkup(component) {
69 transaction = ReactServerRenderingTransaction.getPooled(true);
70
71 return transaction.perform(function() {
78 - var componentInstance = instantiateReactComponent(component, null);
72 + var componentInstance = instantiateReactComponent(element, null);
73 return componentInstance.mountComponent(id, transaction, 0);
74 }, null);
75 } finally {
src/browser/server/__tests__/ReactServerRendering-test.js
+2 -16
@@ -247,21 +247,7 @@ describe('ReactServerRendering', function() {
247 )
248 ).toThrow(
249 'Invariant Violation: renderComponentToString(): You must pass ' +
250 - 'a valid ReactComponent.'
251 - );
252 - });
253 -
254 - it('should provide guidance for breaking API changes', function() {
255 - expect(
256 - ReactServerRendering.renderComponentToString.bind(
257 - ReactServerRendering,
258 - <div />,
259 - function(){}
260 - )
261 - ).toThrow(
262 - 'Invariant Violation: renderComponentToString(): This function ' +
263 - 'became synchronous and now returns the generated markup. Please ' +
264 - 'remove the second parameter.'
250 + 'a valid ReactElement.'
251 );
252 });
253 });
@@ -373,7 +359,7 @@ describe('ReactServerRendering', function() {
359 )
360 ).toThrow(
361 'Invariant Violation: renderComponentToStaticMarkup(): You must pass ' +
376 - 'a valid ReactComponent.'
362 + 'a valid ReactElement.'
363 );
364 });
365