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

Stateless Components not working with SSR #297

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

Stateless Components not working with SSR #297

rattrayalex opened this issue Oct 31, 2016 · 4 comments
Assignees

Comments

@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

@rattrayalex
Copy link
Author

This also occurs when <RouterContext /> is not used

@tmeasday
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
Copy link
Author

Awesome, thanks @tmeasday ! Looking forward.

@tmeasday
Copy link
Contributor

Fixed in 0.6.0 (I think?)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants