question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implementing with-graphql-react example alongside createGlobalstyle from styled-components causes conflicts

See original GitHub issue

Hello,

Just today I found this behavior and would like to start a discussion in order to get to the bottom of it, because really, I’m not sure how to fix it.

This is the error:

(node:22363) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'children' of undefined
    at GlobalStyleComponent.render (/Users/Felipe/Local_Projects/wagglio-gitlab/monorepo/node_modules/styled-components/dist/styled-co
mponents.cjs.js:2376:93)
    at recurse (/Users/Felipe/Local_Projects/wagglio-gitlab/monorepo/node_modules/graphql-react/lib/preload.js:104:35)
    at /Users/Felipe/Local_Projects/wagglio-gitlab/monorepo/node_modules/graphql-react/lib/preload.js:40:20
    at Array.forEach (<anonymous>)
    at recurse (/Users/Felipe/Local_Projects/wagglio-gitlab/monorepo/node_modules/graphql-react/lib/preload.js:39:19)
    at recurse (/Users/Felipe/Local_Projects/wagglio-gitlab/monorepo/node_modules/graphql-react/lib/preload.js:112:11)
    at recurse (/Users/Felipe/Local_Projects/wagglio-gitlab/monorepo/node_modules/graphql-react/lib/preload.js:104:18)
    at recurse (/Users/Felipe/Local_Projects/wagglio-gitlab/monorepo/node_modules/graphql-react/lib/preload.js:104:18)
    at recursePreload (/Users/Felipe/Local_Projects/wagglio-gitlab/monorepo/node_modules/graphql-react/lib/preload.js:116:7)
    at /Users/Felipe/Local_Projects/wagglio-gitlab/monorepo/node_modules/graphql-react/lib/preload.js:120:5
    at new Promise (<anonymous>)
    at preload (/Users/Felipe/Local_Projects/wagglio-gitlab/monorepo/node_modules/graphql-react/lib/preload.js:14:10)
    at /Users/Felipe/Local_Projects/wagglio-gitlab/monorepo/node_modules/next-graphql-react/lib/index.js:77:38
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:22363) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:22363) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

It seems like a conflict between preload and createGlobalStyles (from styled-components). This is the implementation of global styles, it goes according to their docs:

import { normalize } from 'styled-normalize'
import { createGlobalStyle } from 'styled-components'

import { scales } from './variables'

export const WGlobalStyles = createGlobalStyle`
  ${normalize}
  html {
  font-size: ${scales.baseFont}px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;

  }
  *, *:before, *:after {
    -webkit-box-sizing: inherit;
    -moz-box-sizing: inherit;
    box-sizing: inherit;
  }
`

It’s simply the implementation of base font sizes and resets from styled-normalize and just a bit of my own.

This is the _app.js implementation on the side of Next.js. Comes directly from the example with-graphql-react and trying to implement the global styles :

import 'cross-fetch/polyfill'
import {Provider} from 'graphql-react'
import {withGraphQL} from 'next-graphql-react'
import App, { Container } from 'next/app'

import { WGlobalStyles } from '@wagglio/components'

class WagglioMainApp extends App {
    render() {
    const { Component, pageProps, graphql } = this.props
    return (
      <Container>
        <Provider value={graphql}>
          <WGlobalStyles />
          <Component {...pageProps} />
        </Provider>
      </Container>
    )
  }
}

export default withGraphQL(WagglioMainApp)

Everything works whenever I comment out <WGlobalStyles />. Not sure how to pin point the unhandled promise in this case.

If there’s any other info I can provide in order to help solve this, please let me know.

Cheers

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jaydensericcommented, Jan 14, 2019

graphql-react@6.0.1 and next-graphql-react@1.0.2 have been published, fixing all these issues 🙏

1reaction
fev4commented, Jan 14, 2019

This looks awesome. Thank you @jaydenseric !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Styled Components - Gatsby
Styles are tightly coupled with their components. This makes it much easier to know how to edit a component's CSS as there's never...
Read more >
React/Node.js App Using TypeScript, GraphQL, Sequelize ...
React /Node.js App Using TypeScript, GraphQL, Sequelize and Styled Components | Code With Me! Watch later. Share. Copy link.
Read more >
A Simple Blog with GraphQL, Apollo, React Router & styled ...
A GraphQL implementation has a single endpoint — commonly /graphql ... The majority of my experience styling React components can mostly be ...
Read more >
Globally Style the Gatsby Default Starter with ... - Scott Spence
To start I'll make a new Gatsby project using npx: ... Configure gatsby-plugin-styled-components and createGlobalStyle.
Read more >
Building a Static Gatsby-based Website with TypeScript
Gatsby leverages React, JSX, CSS-in-JS, GraphQL and many other modern approaches to ... npm install --save \ gatsby-plugin-styled-components ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found