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.

How to inject transition global styles only after other global styles are loaded?

See original GitHub issue

Steps to reproduce

I tried to add transitions to body alongside other body styles (e.g CSS reset styles) using createGlobalStyles:

body {
  transition: all 1s ease;
  font-size: 14px;
  color: grey;
}

(The use case for the transition is I will switch the body color and background using styled-theming, and would like it to elegantly transition between light and dark themes.)

Expected Behavior

I would like the transition animation to only apply after the initial global styles have been applied.

Actual Behavior

The transition applies to the other global body styles added alongside it, causing the page to “jump” on page load as things like font size and color resets have transitions applied on them.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
probablyupcommented, Oct 13, 2018

Put the style behind a class and add the class to body on mount of your app On Sat, Oct 13, 2018 at 2:49 AM Stephen Koo notifications@github.com wrote:

Steps to reproduce

I tried to add transitions to body alongside other body styles (e.g CSS reset styles) using createGlobalStyles:

body { transition: all 1s ease; }

Expected Behavior

I would like the transition animation to only apply after the initial global styles have been applied. Actual Behavior

The transition applies to the other global body styles added alongside it, causing the page to “jump” on page load as things like font size resets have transitions applied on them.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/styled-components/styled-components/issues/2094, or mute the thread https://github.com/notifications/unsubscribe-auth/AAiy1j_X2wrzKS4DkYLMmQUurgFC6gz5ks5ukZsigaJpZM4Xagjf .

0reactions
probablyupcommented, Oct 16, 2018

That only apply after full application mount? Probably not. You’ll need some imperative DOM code somewhere to add a class or other DOM marking to signify the initial render pass is complete.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to apply global styles with CSS modules in a react app?
The first rule should be to include all global styles, assuming it's kept in /styles/ or similar directory. The second rule is to...
Read more >
Component styles - Angular
While Angular's default style encapsulation prevents component styles from affecting other components, global styles affect all components on the page.
Read more >
How to Create Global Styles with Styled Components
Step 1: Create a global styles file​​ The first step is to create a file that contains all your global styles. Inside your...
Read more >
transition - CSS: Cascading Style Sheets - MDN Web Docs
The transition CSS property is a shorthand property for transition-property, ... Global values */ transition: inherit; transition: initial; ...
Read more >
vercel/styled-jsx: Full CSS support for JSX without compromises
Injecting styles upon render; Only injecting a certain component's style once ... To skip scoping entirely, you can make the global-ness of your...
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