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

styles flickering in dev with tailwind + css modules #12448

Closed
tafelito opened this issue May 3, 2020 · 14 comments · Fixed by #14448
Closed

styles flickering in dev with tailwind + css modules #12448

tafelito opened this issue May 3, 2020 · 14 comments · Fixed by #14448
Assignees
Milestone

Comments

@tafelito
Copy link

tafelito commented May 3, 2020

Bug report

Describe the bug

I'm using tailwindcss with css modules and I notice that the first time the page loads, all my styles are not loaded. Trying to figure it put what was happening, I run the tailwindcss example and added a style from a css module and it happens there too, even when built for prod.

To Reproduce

Run the example from https://github.com/zeit/next.js/tree/canary/examples/with-tailwindcss

Add a index.module.css file with some style

add the styles form the css module in the index.js page

Expected behavior

Without the use of the css modules, all styles are loaded fine the first time, without flickering. Same behavior is expected using css modules

Screenshots

May-03-2020 14-06-19

System information

  • OS: macOS
  • Browser (if applies) [e.g. chrome, safari]
  • Version of Next.js: v9.3.6
  • Version of Node.js: v13.12.0
  • Version of tailwindcss: v1.4.4
@Timer Timer self-assigned this May 4, 2020
@Timer Timer added this to the 9.3.7 milestone May 4, 2020
@Pytal
Copy link

Pytal commented May 7, 2020

I suspect this may have something to do with the automatic code splitting of css modules 🤔

@mzygmunt
Copy link

mzygmunt commented May 8, 2020

Probably related to #10268

@Timer Timer modified the milestones: 9.3.7, 9.4.1, 9.4.2 May 11, 2020
@Timer Timer modified the milestones: 9.4.2, 9.4.3 May 20, 2020
@dani97
Copy link

dani97 commented May 27, 2020

I have used plain css modules for components and styles apply after some ms.

@Adrianjs42
Copy link

Adrianjs42 commented May 27, 2020

I have used plain css modules for components and styles apply after some ms.

According to https://stackoverflow.com/a/42969608/943337 i just added an empty script tag and my problem of a sidebar which was popping up at first load, is now solved.

vercel/next-plugins#455 (comment)

import Document, { Html, Head, Main, NextScript } from 'next/document';
import { GA_TRACKING_ID } from '../utils/anayltics';
class MyDocument extends Document {
  static async getInitialProps(ctx) {
    const initialProps = await Document.getInitialProps(ctx);
    return { ...initialProps };
  }

  render() {
    return (
      <Html lang="de">
        <Head>
        </Head>
        <body>
          <Main />
          <NextScript />
          {/* Empty script tag as chrome bug fix, see https://stackoverflow.com/a/42969608/943337 */}
          <script> </script>
        </body>
      </Html>
    );
  }
}

export default MyDocument;

@Timer Timer modified the milestones: 9.4.3, 9.4.4 May 28, 2020
@dani97
Copy link

dani97 commented May 28, 2020

I have used plain css modules for components and styles apply after some ms.

According to https://stackoverflow.com/a/42969608/943337 i just added an empty script tag and my problem of a sidebar which was popping up at first load, is now solved.

import Document, { Html, Head, Main, NextScript } from 'next/document';
import { GA_TRACKING_ID } from '../utils/anayltics';
class MyDocument extends Document {
  static async getInitialProps(ctx) {
    const initialProps = await Document.getInitialProps(ctx);
    return { ...initialProps };
  }

  render() {
    return (
      <Html lang="de">
        <Head>
        </Head>
        <body>
          <Main />
          <NextScript />
          {/* Empty script tag as chrome bug fix, see https://stackoverflow.com/a/42969608/943337 */}
          <script> </script>
        </body>
      </Html>
    );
  }
}

export default MyDocument;

Thanks @Adrianjs42 the side bar popping in stopped in chrome.

@webdeb
Copy link

webdeb commented May 31, 2020

Also related
#13058

@fadonascimento
Copy link

fadonascimento commented Jun 3, 2020

There is a workaround to resolve this problem
Create a custom "_document.js" and add the class "no-fouc" in the Html component
Create a custom "_app.js" and add the following code in the "componentDidMount"

const removeFouc = (foucElement) => {
      foucElement.className = foucElement.className.replace('no-fouc', 'fouc')
    }
 removeFouc(document.documentElement)

Add add this styles in the global styles:

.no-fouc {
  visibility: hidden;
 opacity: 0;
}

.fouc {
 visibility: visible;
 opacity: 1;
}

@Timer Timer modified the milestones: 9.4.5, 9.x.x Jun 9, 2020
@Timer Timer changed the title styles flickering with tailwind + css modules styles flickering in dev with tailwind + css modules Jun 9, 2020
@Timer Timer modified the milestones: 9.x.x, iteration 3 Jun 15, 2020
@kodiakhq kodiakhq bot closed this as completed in #14448 Jun 22, 2020
kodiakhq bot pushed a commit that referenced this issue Jun 22, 2020
We previously used to remove our FOUC helper inside of the style injection to ensure content was shown as fast as possible.

This behavior, however, was problematic for a few reasons:

1. Large JavaScript chunks would take longer than an animation frame to parse, causing FOUC
1. Rendering would sometimes complete before an animation frame, causing improper effects

To fix the latter, we started removing the no FOUC helper **before** rendering, however, we never fixed the former by removing the dead code.

There's not a great way to test this because the FOUC is so fast and flaky, however, this code really shouldn't exist and isn't likely to be re-added (regress).

Also, we already have FOUC tests that occasionally flake, probably due to this.


Fixes #12448
Fixes #13058
Fixes #11195
Fixes #10404
@Timer
Copy link
Member

Timer commented Jun 22, 2020

This should be fixed in next@^9.4.5-canary.15! Please upgrade and let us know.

@Prottoy2938
Copy link
Contributor

Prottoy2938 commented Jun 24, 2020

@Timer , I have installed next@^9.4.5-canary.18. Now the CSS flickering doesn't appear in the development mode, but it stays the same on the production version. The production version still has the bug.

Note that I'm using material-ui + css modules

Heres a version of the app that I've been working on facing this issue: https://cluster-11-lwj6nmcgy.vercel.app/ .

@casperle
Copy link

casperle commented Jul 6, 2020

@Prottoy2938 Same here. I made a comment to this issue #13058 (comment)

@timneutkens
Copy link
Member

@Timer , I have installed next@^9.4.5-canary.18. Now the CSS flickering doesn't appear in the development mode, but it stays the same on the production version. The production version still has the bug.

Note that I'm using material-ui + css modules

Heres a version of the app that I've been working on facing this issue: cluster-11-lwj6nmcgy.vercel.app .

Seems this your case is unrelated to css modules / tailwind and more so related to forgetting to implement pre-rendering of material-ui: #7322 (comment)

@Prottoy2938
Copy link
Contributor

@casperle , In my case the problem was because I was doing server side rendering. I followed this documentation from material-ui and fixed the issue

@talaikis
Copy link

talaikis commented Jul 6, 2020

With v9.4.5-canary.28 not flickering in dev and flickering in production.

rokinsky pushed a commit to rokinsky/next.js that referenced this issue Jul 11, 2020
We previously used to remove our FOUC helper inside of the style injection to ensure content was shown as fast as possible.

This behavior, however, was problematic for a few reasons:

1. Large JavaScript chunks would take longer than an animation frame to parse, causing FOUC
1. Rendering would sometimes complete before an animation frame, causing improper effects

To fix the latter, we started removing the no FOUC helper **before** rendering, however, we never fixed the former by removing the dead code.

There's not a great way to test this because the FOUC is so fast and flaky, however, this code really shouldn't exist and isn't likely to be re-added (regress).

Also, we already have FOUC tests that occasionally flake, probably due to this.


Fixes vercel#12448
Fixes vercel#13058
Fixes vercel#11195
Fixes vercel#10404
@dalisalvador

This comment has been minimized.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.