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

Twin.macro emotion example flickering when build for production #32

Closed
armspkt opened this issue Feb 6, 2021 · 5 comments
Closed

Twin.macro emotion example flickering when build for production #32

armspkt opened this issue Feb 6, 2021 · 5 comments

Comments

@armspkt
Copy link

armspkt commented Feb 6, 2021

  1. The buggy behavior you’re experiencing and what should be happening instead
    I tried this example https://github.com/ben-rogerson/twin.examples/tree/master/next-emotion
    but when I build & start (for production) then go to localhost:3000 and refresh page the UI seems flickering.
    It does not happen in the development mode.

2564-02-06 15-43-07 2564-02-06 15_43_20

After some debugging seems like calc css function not call on server-side
image
I guess

  1. If you're using styled-components, emotion, goober, or something else
    emotion

  2. A link to a minimal demo showing the bug in action
    fork this repo https://github.com/ben-rogerson/twin.examples/tree/master/next-emotion
    and use yarn build && yarn start

@ben-rogerson ben-rogerson transferred this issue from ben-rogerson/twin.macro Feb 8, 2021
@ben-rogerson
Copy link
Owner

I'll have to look into this futher - perhaps there's something to be learned in this article.

@williamtetlow
Copy link

I found that adding the CacheProvider to _app fixed the issue

import { CacheProvider } from '@emotion/react'
import { cache } from '@emotion/css'
import { GlobalStyles } from '../components/GlobalStyles'

function MyApp({ Component, pageProps }) {
  return (
    <CacheProvider value={cache}>
      <GlobalStyles />
      <Component {...pageProps} />
    </CacheProvider>
  )
}

export default MyApp

@ben-rogerson
Copy link
Owner

@williamtetlow Could you check that your production build is working correctly after adding that? This CacheProvider was originally part of the example until I saw it caused some issues.

@williamtetlow
Copy link

williamtetlow commented Mar 22, 2021

@ben-rogerson so the issue I was seeing was caused by tailwind class using the first-child selector and issue with that selector and emotion SSR.

I can't recreate the issue in example repo but implementation in the example repo _document is wrong and may be causing confusion.

To overcome issue with first-child selector you can use emotion advanced SSR setup to inline critical css in head instead of colocating <style> tags with components in body.

If you don't need to inline CSS in head you shouldn't include custom implementation of CacheProvider in _app and CriticalCSS in _document.

We should either

  1. Update example repo to not have custom implementation in _document
  2. Update it to use CacheProvider in _app
  3. Have two examples - one with custom SSR and one without.

@ben-rogerson
Copy link
Owner

ben-rogerson commented Apr 6, 2021

Hey william, I was wondering which option you would choose here?
Option 2 caused build issues last time it was part of the example.

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

No branches or pull requests

3 participants