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

Fixed Cannot read property 'forEach' of undefined #6

Closed
wants to merge 1 commit into from

Conversation

shalkam
Copy link

@shalkam shalkam commented Apr 24, 2017

Fixed this error : -
TypeError: Cannot read property 'forEach' of undefined
I don't know what's causing it but adding this if statement fixed the issue

Fixed this error : -
`TypeError: Cannot read property 'forEach' of undefined`
I don't know what's causing it but adding this if statement fixed the issue
@coveralls
Copy link

coveralls commented Apr 24, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling f9fad6a on shalkam:master into 9fa1c47 on jakepusateri:master.

@jakepusateri
Copy link
Owner

Hi, thanks for the PR. I'd love a test case so I can figure out what caused this as well as prevent regressing it in the future. Would you be able to make a minimal repro for this?

@shalkam
Copy link
Author

shalkam commented Apr 25, 2017

No, problem but until I do so the problem occurred with apollo server side rendering only
I am using a custom network interface for this purpose:

import { createLocalInterface } from 'apollo-local-query';
app.get('*', function(req, res) {
    const context = {};
    const initialState = { user: req.user };
    const client = new ApolloClient({
      ssrMode: true,
      networkInterface: createLocalInterface(graphql, schema, {
        context: { req, acl }
      })
    });
    const component = (
      <ApolloProvider client={client}>
        <StaticRouter location={req.url} context={context}>
          <App {...initialState} isServer={true} />
        </StaticRouter>
      </ApolloProvider>
    );
    getDataFromTree(component)
      .then(() => {
        initialState[client.reduxRootKey] = client.getInitialState();
        const body = renderToString(component);
        const helmet = Helmet.renderStatic();
        if (context.url) {
          res.writeHead(302, {
            Location: context.url
          });
          res.end();
        } else {
          res.send(
            `
            <!DOCTYPE html>
            <html ${helmet.htmlAttributes.toString()}>
              <head>
                <meta charset="UTF-8">
                <script>window.__APP_INITIAL_STATE__ = ${JSON.stringify(initialState)}</script>
                ${helmet.title.toString()}
                ${helmet.meta.toString()}
                ${helmet.link.toString()}
                <link rel="stylesheet" href="/assets/styles.css" />
              </head>

              <body ${helmet.bodyAttributes.toString()}>
                <div id="app">${body}</div>
                <script src="/assets/bundle.js" ></script>
              </body>
            </html>
          `
          );
        }
      })
      .catch(err => {
        console.error(err);
      });
  });

@jakepusateri
Copy link
Owner

Closing due to inactivity. If this still happens or you have a test case that causes the error, comment and I can reopen.

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

Successfully merging this pull request may close these issues.

3 participants