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

Clearer ssr error message 11902 #11966

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,32 @@ describe('ReactDOMServerIntegration', () => {
'or you might have mixed up default and named imports.'
: ''),
);

itThrowsWhenRendering(
'null',
async render => {
spyOnDev(console, 'error');
const NullComponent = null;
await render(<NullComponent />);
},
'Element type is invalid: expected a string (for built-in components) or a class/function ' +
'(for composite components) but got: null.',
);

itThrowsWhenRendering(
'undefined',
async render => {
spyOnDev(console, 'error');
const UndefinedComponent = undefined;
await render(<UndefinedComponent />);
},
'Element type is invalid: expected a string (for built-in components) or a class/function ' +
'(for composite components) but got: undefined.' +
(__DEV__
? " You likely forgot to export your component from the file it's defined in, " +
'or you might have mixed up default and named imports.'
: ''),
);
});
});
});
2 changes: 1 addition & 1 deletion packages/react-dom/src/server/ReactPartialRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ class ReactDOMServerRenderer {

let info = '';
if (__DEV__) {
const owner = elementType._owner;
const owner = elementType && elementType._owner;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm wait. I don't see how this could work. Owner is defined on the element. Not on the elementType.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In other words you want nextElement._owner here. We know nextElement exists because we already read type from it.

if (
elementType === undefined ||
(typeof elementType === 'object' &&
Expand Down