Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Fix issues with context and undefined children #317

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 4 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export function walkTree(
// https://github.com/facebook/react/blob/master/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js#L66
if (Component.prototype && Component.prototype.isReactComponent) {
const instance = new Component(props, context);
instance.props = props;
instance.context = context;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need these? I thought new Component did that for us?

Copy link
Author

Choose a reason for hiding this comment

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

These three constructors are valid for react:

constructor() {
super();
}

constructor(props) {
super(props);
}

constructor(props, context) {
super(props, context);
}

But only the last one is covered by new Component(props, context). At least thats what I suppose.


// Override setState to just change the state, not queue up an update.
// (we can't do the default React thing as we aren't mounted "properly"
Expand All @@ -73,12 +75,12 @@ export function walkTree(
child = Component(props, context);
}

walkTree(child, childContext, visitor);
if (child) walkTree(child, childContext, visitor);

} else { // a basic string or dom element, just get children
if (element.props && element.props.children) {
Children.forEach(element.props.children, (child: any) => {
walkTree(child, context, visitor);
if (child) walkTree(child, context, visitor);
});
}
}
Expand Down