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.

createGlobalStyle does not hot reload Gatsby app

See original GitHub issue

System:

  • OS: macOS 10.14.4
  • CPU: (8) x64 Intel® Core™ i7-7700HQ CPU @ 2.80GHz
  • Memory: 404.55 MB / 16.00 GB
  • Shell: 5.3 - /bin/zsh

Binaries:

  • Node: 10.10.0 - /usr/local/bin/node
  • Yarn: 1.15.2 - /usr/local/bin/yarn
  • npm: 6.4.1 - /usr/local/bin/npm

npmPackages:

  • babel-plugin-styled-components: ^1.10.0 => 1.10.0
  • styled-components: ^4.2.0 => 4.2.0

Reproduction

Demo: https://codesandbox.io/s/zny06vk49x

Gatsby default theme were installed. Dependencies are installed following the instructions. No extra options are added: https://www.gatsbyjs.org/docs/styled-components/

Steps to reproduce

Using the Gatsby default starter theme, the new createGlobalStyle API does not work with Gatsby hot reload. Not sure if this is Gatsby specific or something else. Every time I change the css property values inside createGlobalStyle, for example in my codesandbox link, changing the values from red to something else, or the background doesn’t hot reload the Gatsby app, and hence no style changes. The page will only get hot reloaded and new styles will only be applied if I refresh the page, or change props in the React component.

In the codesandbox I also created a <Test /> styled component, confirming changing the CSS properties on a regular styled components is working as expected with hot reloading.

Expected Behavior

Changing CSS properties and values inside createGlobalStyle should hot reload the page just like any other regular styled components

Actual Behavior

Changing CSS properties and values inside createGlobalStyle does not hot reload the page. Styles can only get applied if I refresh the page or changing React component props

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:9
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
BlueAccordscommented, Jun 6, 2019

#2074 seems to be related so linking it here for visibility.

1reaction
bowedcontainer2commented, Feb 4, 2020

Running styled-components@v5.0.0 as released on 01/13/2020 and still having this issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hot reloading components in Gatsby doesn't work
it seems that hot reloading is not working... I've tried to flatten my components to be direct child of components folder and it...
Read more >
Gatsby-styled-components-dark-mode NPM | npm.io
Currently, when changing a theme, the app will recompile but will not hot reload. You have to do a full page-refresh to see...
Read more >
gatsby-styled-components-dark-mode - npm
A Gatsby plugin for toggling dark mode and injecting themes using styled-components. Latest version: 2.0.5, last published: 7 months ago.
Read more >
Starting with Gatsby + Styled Components + Storybook
In this article, I will show you how to use Gatsby with Styled ... defined in Layout.js in App component which is not...
Read more >
A Dark Mode Toggle with React and ThemeProvider
We'll use create-react-app to initiate a new project: ... There is no magic switching between themes yet, so let's implement toggling ...
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