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

Fix invariant parity for SSR #10333

Merged
merged 1 commit into from Jul 31, 2017
Merged

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Jul 31, 2017

There's a few different things here that was a bit difficult to untangle.
The goals were:

  • Make sure common invariants give the same messages with client and server render.
  • Throw in the same cases. Not throwing in SSR but throwing on the client makes warnings very confusing.
  • Turn "new features" on for the DOM integration fixture since we're only working on new SSR now.
  • Make sure we have tests for top level rendering (strings, numbers, arrays).

I'll add more inline comments for specific changes.

@@ -45,7 +45,7 @@ function renderToStream(element) {
if (disableNewFiberFeatures) {
invariant(
React.isValidElement(element),
'renderToStream(): You must pass a valid ReactElement.',
'renderToStream(): Invalid component element.',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed these for consistency with ReactDOM.render message. I'm not sure if it mattered in all cases (e.g. these ones are behind a flag that's now false in integration suite) but I changed them all for consistency.

let clientNode = firstClientNode;

// Make sure all top level nodes match up
while (serverNode || clientNode) {
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 used to only check the first one.

// text node, but otherwise works.
// TODO: we can remove this branch if we add explicit hydration opt-in.
// https://github.com/facebook/react/issues/10189
expect(serverNode.nodeValue).toBe(clientNode.nodeValue);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Special case because shouldReuseContent() bails out. Happy to change this to use hydration API per conversation with @sebmarkbage, but I'd like to do this as followup.

@@ -227,21 +251,28 @@ function itClientRenders(desc, testFn) {
});
}

function itThrows(desc, testFn) {
function itThrows(desc, testFn, partialMessage) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Adding this to every error. Helped uncover cases where we crashed instead of throwing something useful.

@@ -298,6 +330,7 @@ function resetModules() {
// TODO: can we express this test with only public API?
ExecutionEnvironment = require('ExecutionEnvironment');

require('ReactFeatureFlags').disableNewFiberFeatures = false;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

New features are now enabled for all fixtures in this file. We don't ship "no new features" SSR builds anymore.

@@ -361,7 +381,25 @@ describe('ReactDOMServerIntegration', () => {
});

if (ReactDOMFeatureFlags.useFiber) {
itRenders('a array type children as a child', async render => {
itRenders('a string', async render => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added tests for top level string and number, and renamed array tests.

@@ -1401,26 +1429,81 @@ describe('ReactDOMServerIntegration', () => {
});

describe('components that throw errors', function() {
itThrowsWhenRendering('a string component', async render => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is now valid.


itThrowsWhenRendering('a number component', async render => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is now valid too.

@gaearon gaearon merged commit 1454f9c into facebook:master Jul 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants