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

Stateless Components not working with SSR #297

Closed
rattrayalex opened this Issue Oct 31, 2016 · 4 comments

Comments

Projects
None yet
2 participants
@rattrayalex
Copy link

rattrayalex commented Oct 31, 2016

This line: https://github.com/apollostack/react-apollo/blame/master/src/server.ts#L48

throws this error: ComponentClass is not a constructor
with this stack:

TypeError: ComponentClass is not a constructor at getQueriesFromTree (/Users/alex/djcode/another_example_app/frontend/src/server.ts:48:23) at getQueriesFromTree (/Users/alex/djcode/another_example_app/frontend/src/server.ts:67:5) at /Users/alex/djcode/another_example_app/frontend/src/server.ts:73:54 at forEachSingleChild (/Users/alex/djcode/another_example_app/frontend/node_modules/react/lib/ReactChildren.js:52:8) at traverseAllChildrenImpl (/Users/alex/djcode/another_example_app/frontend/node_modules/react/lib/traverseAllChildren.js:69:5) at traverseAllChildren (/Users/alex/djcode/another_example_app/frontend/node_modules/react/lib/traverseAllChildren.js:164:10) at Object.forEachChildren [as forEach] (/Users/alex/djcode/another_example_app/frontend/node_modules/react/lib/ReactChildren.js:72:3) at getQueriesFromTree (/Users/alex/djcode/another_example_app/frontend/src/server.ts:73:14) at getQueriesFromTree (/Users/alex/djcode/another_example_app/frontend/src/server.ts:67:5) at getQueriesFromTree (/Users/alex/djcode/another_example_app/frontend/src/server.ts:67:5)

This occurs only with Stateless Components, which work fine when rendered on the client but break when rendered on the server with react-apollo and react-router.

This is the immediately surrounding code:

  const App = (
    <ApolloProvider client={client} >
      <RouterContext {...renderProps} />
    </ApolloProvider>
  )

  const { markup, initialState } = await renderToStringWithData(App)

When I only have class-based components, everything works. When I have a Stateless component anywhere in my hierarchy, I get the above error.

Version

  • apollo-client@0.5.0
  • react-apollo@0.5.14
  • react@15.3.2
@rattrayalex

This comment has been minimized.

Copy link
Author

rattrayalex commented Oct 31, 2016

This also occurs when <RouterContext /> is not used

@tmeasday

This comment has been minimized.

Copy link
Contributor

tmeasday commented Nov 1, 2016

That's interesting, I'm pretty sure it does work in some cases (for instance GitHunt has some SFCs). In any case, I'm going to refactor this code soon, thanks for reporting it.

@tmeasday tmeasday self-assigned this Nov 1, 2016

@rattrayalex

This comment has been minimized.

Copy link
Author

rattrayalex commented Nov 2, 2016

Awesome, thanks @tmeasday ! Looking forward.

@tmeasday

This comment has been minimized.

Copy link
Contributor

tmeasday commented Nov 14, 2016

Fixed in 0.6.0 (I think?)

@tmeasday tmeasday closed this Nov 14, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment