Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
26 changes: 10 additions & 16 deletions src/browser/server/ReactServerRendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,13 @@ var instantiateReactComponent = require('instantiateReactComponent');
var invariant = require('invariant');

/**
* @param {ReactComponent} component
* @param {ReactElement} element
* @return {string} the HTML markup
*/
function renderComponentToString(component) {
function renderComponentToString(element) {
invariant(
ReactElement.isValidElement(component),
'renderComponentToString(): You must pass a valid ReactComponent.'
);

invariant(
!(arguments.length === 2 && typeof arguments[1] === 'function'),
'renderComponentToString(): This function became synchronous and now ' +
'returns the generated markup. Please remove the second parameter.'
ReactElement.isValidElement(element),
'renderComponentToString(): You must pass a valid ReactElement.'
);

var transaction;
Expand All @@ -49,7 +43,7 @@ function renderComponentToString(component) {
transaction = ReactServerRenderingTransaction.getPooled(false);

return transaction.perform(function() {
var componentInstance = instantiateReactComponent(component, null);
var componentInstance = instantiateReactComponent(element, null);
var markup = componentInstance.mountComponent(id, transaction, 0);
return ReactMarkupChecksum.addChecksumToMarkup(markup);
}, null);
Expand All @@ -59,14 +53,14 @@ function renderComponentToString(component) {
}

/**
* @param {ReactComponent} component
* @param {ReactElement} element
* @return {string} the HTML markup, without the extra React ID and checksum
* (for generating static pages)
*/
function renderComponentToStaticMarkup(component) {
function renderComponentToStaticMarkup(element) {
invariant(
ReactElement.isValidElement(component),
'renderComponentToStaticMarkup(): You must pass a valid ReactComponent.'
ReactElement.isValidElement(element),
'renderComponentToStaticMarkup(): You must pass a valid ReactElement.'
);

var transaction;
Expand All @@ -75,7 +69,7 @@ function renderComponentToStaticMarkup(component) {
transaction = ReactServerRenderingTransaction.getPooled(true);

return transaction.perform(function() {
var componentInstance = instantiateReactComponent(component, null);
var componentInstance = instantiateReactComponent(element, null);
return componentInstance.mountComponent(id, transaction, 0);
}, null);
} finally {
Expand Down
18 changes: 2 additions & 16 deletions src/browser/server/__tests__/ReactServerRendering-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,7 @@ describe('ReactServerRendering', function() {
)
).toThrow(
'Invariant Violation: renderComponentToString(): You must pass ' +
'a valid ReactComponent.'
);
});

it('should provide guidance for breaking API changes', function() {
expect(
ReactServerRendering.renderComponentToString.bind(
ReactServerRendering,
<div />,
function(){}
)
).toThrow(
'Invariant Violation: renderComponentToString(): This function ' +
'became synchronous and now returns the generated markup. Please ' +
'remove the second parameter.'
'a valid ReactElement.'
);
});
});
Expand Down Expand Up @@ -373,7 +359,7 @@ describe('ReactServerRendering', function() {
)
).toThrow(
'Invariant Violation: renderComponentToStaticMarkup(): You must pass ' +
'a valid ReactComponent.'
'a valid ReactElement.'
);
});

Expand Down