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.

Div using only bg-gradient class doesn't get its style applied on prod

See original GitHub issue
  1. Problem: Hey, so I just came across something strange, more details below.
  2. Environment: Forked the Next.Js + Emotion example.
  3. Link: https://codesandbox.io/s/silly-davinci-qbgj4?file=/pages/index.js:129-185

The style of a div using only gradient background class worked fine on dev, but not on prod. And when adding another class (text-white here), then it works:

  • Working on dev, working on prod: <div tw="bg-gradient-to-b from-red-500 to-gray-400">
  • Working on dev, not working on prod <div tw="bg-gradient-to-b from-red-500 to-gray-400 text-white">

If you want to try, go the the sandbox link above. I found a way to test on dev and on prod, by changing the dev command in the package.json. When you first launch, the dev command will be set on next dev. If you want to see the issue, change the dev command to next build && next start:

  • Ex 1: next dev image

  • Ex 2: next build && next start image

Does anyone have any idea why?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Dramloccommented, Dec 15, 2020

Hey @ben-rogerson,

The default emotion approach fixes this issue but after testing it on a larger example, I had some problems with it. Utilities like space-* and divide-* use the CSS sibling combinator (e.g.: :not([hidden])~:not([hidden])) and can cause layout shifts with this approach.

While testing this, I also found that some issues still remain with the advanced approach. Emotion seems to sometime create invalid CSS when serializing the style with stylis (see https://github.com/thysultan/stylis.js/issues/250). This issue can happen when the last declaration of a style is a CSS variable.

For example, in this snippet:

<span tw="ring-inset" />
<div tw="p-4" />

The ring-inset utility will be applied but the next CSS declaration (p-4) will be skipped by the browser.

In practice, this can cause a FOUC but it’s less frequent and less noticeable than the layout shifts of the default approach. I think you can keep the twin starter as it is and wait for the bug fix on stylis.

1reaction
Dramloccommented, Dec 14, 2020

Hi,

You can find more information on this topic in the emotion docs: https://emotion.sh/docs/ssr.

I would suggest using the default approach if your project does not require the advanced approach. It provides better performance (with response streaming) and is easier to maintain. Also, most of its limitations can be worked around.

In the first approach, @emotion/react will create the CacheProvider under the hood and use it in every Emotion component, so it should have no impact on your application.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Linear gradient not working with div - Stack Overflow
The linear-gradient attribute is not working. I want the trapezoid as shadow i.e its color should eventually fade away. Can anyone please help ......
Read more >
CSS Gradients - CSS-Tricks
Gradients are background-image​​ While declaring the a solid color uses background-color property in CSS, gradients use background-image . This ...
Read more >
Content Configuration - Tailwind CSS
Configuring source paths. Tailwind CSS works by scanning all of your HTML, JavaScript components, and any other template files for class names, ...
Read more >
Advanced effects with CSS background blend modes
The background property is where we can use CSS gradients. Functions like linear-gradient() , radial-gradient() , and the ...
Read more >
How To Add Border Images and Gradient Borders with Pure ...
You'll notice that there's still needs to be a regular border applied to the element because the border image replaces the regular border...
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