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

Inconsistent css in dev vs prod #4204

Closed
adi-zz opened this issue Oct 26, 2018 · 26 comments
Closed

Inconsistent css in dev vs prod #4204

adi-zz opened this issue Oct 26, 2018 · 26 comments

Comments

@adi-zz
Copy link

adi-zz commented Oct 26, 2018

Version

v2.2.0

Reproduction link

https://github.com/adi-zz/nuxt-css-dev-vs-prod

Steps to reproduce

  1. git clone https://github.com/adi-zz/nuxt-css-dev-vs-prod
  2. cd nuxt-css-dev-vs-prod
  3. npm i
    1. npm run dev
    2. npm run build && npm run start
  4. open http://localhost:3000/

What is expected ?

The background color of nuxt logo should be blue in both cases 3.1. and 3.2. (or at least red in both cases).

What is actually happening?

Background is blue in dev mode (3.1.), and red in prod mode (3.2.)

Additional comments?

My project was generated using npx create-nuxt-app test (choosing all defaults)

This bug report is available on Nuxt community (#c8047)
@aldarund
Copy link

Reproduced on codesandbox https://codesandbox.io/s/m570wpvv1j

@spnc-omz
Copy link

spnc-omz commented Nov 2, 2018

I'm also seeing this. For the time being I've pinned my version to v2.1.0 of nuxt and it works.

@manniL
Copy link
Member

manniL commented Nov 2, 2018

@spnc-omz Oh, so it worked with 2.1?

@spnc-omz
Copy link

spnc-omz commented Nov 3, 2018

This gets even more weird. I think I had a dependency issue. Everything worked for me after I updated my postcss preset env to ~6.3.0

@AndrewBogdanovTSS
Copy link

@spnc-omz which exact module are you referring to? I only see postcss-env-function in my node_modules folder

@clarkdo clarkdo self-assigned this Nov 12, 2018
@clarkdo
Copy link
Member

clarkdo commented Nov 12, 2018

@adi-zz
A good advice is that do not depend on the insertion order to write styles: vuejs/vue-loader#938 (comment)

It will be correct as your expectation if you add scoped in index.vue:

<style scoped>
.VueToNuxtLogo {
  background-color: blue;
}
</style>

@AndrewBogdanovTSS
Copy link

@clarkdo this is understandable, but sometimes there are use cases when using scoped styles is not an option. e.g. consider a project that was created on top of a vanilla html/css template without any view components to start with, so all those styles are separate scss files bundled in a one big global css chunk that should properly interact with style libraries such as bootstrap that are also connected to the project.

@clarkdo
Copy link
Member

clarkdo commented Nov 12, 2018

@AndrewBogdanovTSS 😸

I understand and I didn't mean that we must use scoped here.

Since the injection of css files is asynchronous, so the order of css files are not guaranteed, the root problem is more related to the way how we should organize css.

My point is that it's not a proper way to prioritize styles depending on the order of selector location in file.

If we want make a selector prior to another, we should use higher priority selector:

// component
<style>
.VueToNuxtLogo {
  background-color: red;
}
</style>

// index.vue
<style>
.index .VueToNuxtLogo {
  background-color: blue;
}
</style>

@AndrewBogdanovTSS
Copy link

@clarkdo yeah, I also understand that, but you know, people been controlling css priority by defining specific order for years and practically getting rid of this habit will mean rewriting thousands of already existing css selectors whereas just switching the file order will fix it in a finger snap (you don't even need to be a Thanos to do that)

@stale
Copy link

stale bot commented Dec 3, 2018

Thanks for your contribution to Nuxt.js!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of nuxt-edge
  2. Comment the steps to reproduce it

Issues that are labeled as 🕐Pending will not be automatically marked as stale.

@stale stale bot added the stale label Dec 3, 2018
@manniL manniL added pending and removed stale labels Dec 3, 2018
@tmorehouse
Copy link

I'm seeing this issue also.

Using the nuxt.config.js css option, I am seeing inconsistent CSS load order, which doesn't follow the order specified. in the CSS array

We are using 3rd party CSS libraries, of which we create an override style sheet, which needs to be loaded last, and sometimes it is being loaded first.

@tmorehouse
Copy link

tmorehouse commented Dec 12, 2018

Need to find a way to guarantee ordering, without resorting to making a master CSS/SCSS file that imports all 3rd party libraries + custom style overrides

@AndrewBogdanovTSS
Copy link

AndrewBogdanovTSS commented Dec 12, 2018

Wasn't this already been fixed? I had similar issue I logged here #4219 (comment)
and now it's respecting an order for me

@AndrewBogdanovTSS
Copy link

@tmorehouse did you try it with Nuxt 2.4.2? Is it working for you?

@tmorehouse
Copy link

@AndrewBogdanovTSS

The issue appears to have been fixed.

@manniL
Copy link
Member

manniL commented Feb 12, 2019

Nice!

@manniL manniL closed this as completed Feb 12, 2019
@eiva
Copy link

eiva commented May 22, 2019

And it happening again for "nuxt": "^2.7.1"
In the inspector window, I see that styles have a different order.
The application was generated using npx create-nuxt-app test with vuetify ui.
And I see that _grid.styl appears after _lists.styl in dev and vice versa in prod.
Could this ticket be reopened? Or I need to create new one?

@clementmas
Copy link

Yes, I'm having the same issue here with inconsistent styling between dev and prod environments.

Here's a link to a reproduction: https://codesandbox.io/s/examplenuxtvuetifycssorder-k4ob0

  • Expected: have card title and text on the same line because of CSS display: inline inside component (which works well in dev environment)
  • Result: card title and text are on 2 different lines because the third-party CSS display: flex appears after (only in prod environment)

I thought it might be an issue with vuetify-loader but they say it's not: vuetifyjs/vuetify-loader#23

Can this issue be reopen?

@fbrbovic
Copy link

fbrbovic commented Aug 1, 2019

I am experiencing the problem too. Also using vuetify-loader

@AndrewBogdanovTSS
Copy link

@manniL please, reopen! extractCSS is so buggy that I actually gave up on it, it was easier to reduce styles by 10 times than to fix all issues that keep happening with this property 🤦‍♂️

@manniL
Copy link
Member

manniL commented Aug 1, 2019

Please see #4219

@mjmnagy
Copy link

mjmnagy commented Feb 24, 2020

Styles are different - not using purgecss or any other plugin accept nuxt defaults

@DengSihan
Copy link

DengSihan commented Mar 2, 2020

this issues happened to the css which used on the classname/id/element add by javascript, when you run npm run prod ,then nuxt will check which classname/id/element were used, and render these css only, different from npm run dev which nuxt will render all the css

add the css in <style></style> can fix this

@mjmnagy
Copy link

mjmnagy commented Mar 2, 2020

i am using a combination of <style scoped> and inline css computed by JS.
No style sheets are imported

@Whiled0S
Copy link

The fix for me is to add ignoreOrder: false to extractCSS config.

build: {
    extractCSS: {
      ignoreOrder: false
    }
}

Hope it will help someone.

@isenewotheo
Copy link

Based on my experience, there are 2 reasons that i know of that makes the css of the built version not consistent with the dev version.

  1. using unscoped style <style> in components
  2. using wrong css (i found out i was using "margin: initial 30px" instead of "margin: 0 30px"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests