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 loaded after initial render in production mode using ant design with less #8826

Closed
clement-faure opened this issue Sep 22, 2019 · 12 comments
Labels
good first issue Easy to fix issues, good for newcomers

Comments

@clement-faure
Copy link

Examples bug report

Describe the bug

When using a complete copy of with-ant-design-less sample, styles are loaded after an initial page render when nextjs is built to production

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to https://github.com/zeit/next.js/tree/canary/examples/with-ant-design-less
  2. Clone the repository
  3. Install dependencies and build in production mode
  4. Start in production mode

Expected behavior

Styles should be loaded before initial render

Screenshots

65225171-edd33d80-dac4-11e9-84d2-9d5f0fb7903d

System information

  • OS: macOS
  • Browser (if applies) chrome
  • Version of Next.js: latest

Additional context

I tried to deploy using my nextjs app using now and same issue is happening.

@timneutkens timneutkens added good first issue Easy to fix issues, good for newcomers help wanted labels Sep 23, 2019
@clement-faure
Copy link
Author

https://spectrum.chat/next-js/general/with-ant-design-less-style-flash-on-load~521fe7f8-1ba7-4da0-bf6e-6a81921ae9a5

Overriding _app.js is a way to fix it !

@carlosbaraza
Copy link

carlosbaraza commented Sep 24, 2019

Not sure this would help, but I import Antd in the following way, without messing up with the webpack config:

styles/antd.less:

@import "../../node_modules/antd/dist/antd.less";
@import "./antd-variables.less";

next.config.js:

const withPlugins = require("next-compose-plugins");
const less = require("@zeit/next-less");

module.exports = withPlugins([
  [less, { lessLoaderOptions: { javascriptEnabled: true } }]
]);

_app.js:

import "../styles/antd/antd.less";

...

This seems to work just fine.

@clement-faure
Copy link
Author

https://spectrum.chat/next-js/general/with-ant-design-less-style-flash-on-load~521fe7f8-1ba7-4da0-bf6e-6a81921ae9a5

Overriding _app.js is a way to fix it !

No really working... For exemple, when i'm using Drawer from ant design, transition isn't working.

@LBC100
Copy link

LBC100 commented Oct 8, 2019

I am experiencing the same problem. Request a solution. help me

@LBC100
Copy link

LBC100 commented Oct 9, 2019

不确定这是否有帮助,但我可以通过以下方式导入Antd,而不会弄乱webpack配置:

styles/antd.less

@import "../../node_modules/antd/dist/antd.less";
@import "./antd-variables.less";

next.config.js

const  withPlugins  =  require(“ next-compose-plugins ”);
const  less  =  require(“ @ zeit / next-less ”);

模块。出口 =  withPlugins([
  [less,{lessLoaderOptions  {javascriptEnabled  true }}]
];

_app.js

导入  ../styles/antd/antd.less  ;

...

这似乎工作正常。

My latest experiment, doesn't work

@LBC100
Copy link

LBC100 commented Oct 15, 2019

Examples bug report

Describe the bug

When using a complete copy of with-ant-design-less sample, styles are loaded after an initial page render when nextjs is built to production

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to https://github.com/zeit/next.js/tree/canary/examples/with-ant-design-less
  2. Clone the repository
  3. Install dependencies and build in production mode
  4. Start in production mode

Expected behavior

Styles should be loaded before initial render

Screenshots

65225171-edd33d80-dac4-11e9-84d2-9d5f0fb7903d

System information

  • OS: macOS
  • Browser (if applies) chrome
  • Version of Next.js: latest

Additional context

I tried to deploy using my nextjs app using now and same issue is happening.

Has your problem been solved?

@clement-faure
Copy link
Author

clement-faure commented Oct 15, 2019

I manage to find a temporary solution by not putting style element in Next.Js Head. I don't know why, but when putting style element in Head, it is working at initial render but when navigation between page using Link (from next/link), style element is happened again in the tree.

    return (
        <Layout className="custom-layout">
            {/* Fixes flash of unstyled content for first load, not in NextJs because causing issue */}
            <style
                id='holderStyle'
                dangerouslySetInnerHTML={{
                    __html: `
          *, *::before, *::after {
            transition: none!important;
          }
        `
                }}
            />
            {/* Enf fixing flash unstyled content */}
            <Head>
                {/* SEO */}
             ....
            </Head>
            <Component {...pageProps} />
        </Layout>
    );
}

And before exporting my class

if (typeof window !== "undefined") { window.onload = () => { document.getElementById("holderStyle").remove(); }; }

@MihaiWill
Copy link

@cfaure004 is the solution still working for you? I tried but, the Antd still loads with a flash....

@clement-faure
Copy link
Author

@cfaure004 is the solution still working for you? I tried but, the Antd still loads with a flash....

Yes it's working well using my previous comment !

@Timer
Copy link
Member

Timer commented Jan 21, 2020

Duplicate of #9830

@Timer Timer marked this as a duplicate of #9830 Jan 21, 2020
@Timer Timer closed this as completed Jan 21, 2020
@faizullah11

This comment has been minimized.

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

No branches or pull requests

8 participants