unocss: [Bug Report] Latest update broke styling for flexbox properties in Nuxt3

UnoCSS version

0.58.7

Describe the bug

Upon updating Unocss to v0.58.7 in my Nuxt3 portfolio this morning, I notice a number of styles simply no longer work. Notably flexbox properties (and sometimes borders). This does not seem to have an effect on live production.

Here is a pic of a section in my portfolio in dev mode vs live - the styles have not changed at all between these two images. It seems that this issue only happens on the initial load of the page, although it can sometimes revert back to this state when I save changes on a file or component:

*These images are showing that flex, items-center, and justify-between not being applied to these elements. Again, styles have not been changed or edited in any way. Only the unocss version has changed.

Screenshot 2024-03-27 at 9 19 09 AM Screenshot 2024-03-27 at 9 22 07 AM

Reproduction

I can’t seem to reproduce this in a Stackblitz as it seems to be local environment issue… But here is the gist of what I have in my project, which always seems to be unstyled upon page load:

https://stackblitz.com/edit/nuxt-starter-xy4uvj?file=package.json,unocss.config.ts,app.vue,nuxt.config.ts

System Info

Nuxt v3.11.1 Node v18.18.2

Validations

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (4 by maintainers)

Most upvoted comments

@Simon-He95 The issue is that this is extremely difficult to reproduce. It also seems to not happen within new Nuxt projects, even when I have the same config as my older projects. I have tried with two new repos to reproduce the issue locally and simply cannot do it (despite spending hours on the issue this past weekend). Perhaps I need to remove my node modules folder or uninstall/reinstall uno on my older projects?

Agreed @owl1n. This definitely seems like a potential @apply issue, although I am still somewhat unsure of the core cause…

At its core, it seems that some css styles are simply not applied when using @apply. However, it seems to be infrequent and mainly occurs on flexbox type styles. I will need help from any other Nuxt users to find the issue here, although I will keep at it during this week. Even another video that can screen-record the styles not being applied may help.

@Simon-He95 I will try to find a way to create an online repo

A bit more digging. I tested the following in my SvelteKit project. Issue arises when multiple @apply are defined. For the following example, @apply shadow-lg style appears to be ignored in the final result.

<div class="test">Test</div>

<style lang="postcss">
  .test {
    @apply shadow-lg;  /* This line of style is not applied by @unocss/transformer-directives 0.58.7 or later */
    @apply rounded-md bg-slate-300 shadow-amber-500;
  }
</style>

Issue can be resolved by combine style utilities into a single @apply. (Or by removing the simicolonOffset logic mentioned before)

<style lang="postcss">
  .test {
    @apply shadow-lg rounded-md bg-slate-300 shadow-amber-500;
  }
</style>

However, such outcome doesn’t seem to be reproduced on UnoCSS Playground. https://unocss.dev/play/?version=0.58.7&html=DwEwlgbgBAxgNgQwM5ILwCIAuBTJn0B8AKrpsAPTgQFA&config=PTAEFMGcBsEsDsAuBaAJrSBDARtcz5wAPFOQ0eAe2QCcpEbYBjRcVZWAWwAdKbFIAKC69%2BoAN6DQoVOABmCcAGFK8BQHMANFNANM8SHL6dwNACKw6LWADco26dzqRwiAIKIGsbAFdEsOQBPB1AnKFcAVSpBAF9QORpKTlAAch8qJkhIFMFBYlFEGXlMH2hC2QVCFTVYdQAKSUdnV0gALlAAbR0m8MQoyjqAShCel3dPRl9-IKGQgF0QvQMjGhMaNs7u3Rp9Q2NTCyt-O0hZnTnYwcEgA&css=HQFwpgziAEDeBQ1oAECGAHdAbAntCAFqgCYD2A7gLRYDmA3IihtngE6kCuAdsWMZQFti0AEY1KELKnCUAzAAZ5%2BImSqoBIsK0oBWRQwC%2BQA&options=N4IgLgTghgdgzgMwPYQLYGECucxIwZXxAC4EoAbOAUwBpxp5k0AJMVcksyqgXyA So far the issue is only visible in an actual SvelteKit+Vite project.

nice job,I will try to fix it

A bit more digging. I tested the following in my SvelteKit project. Issue arises when multiple @apply are defined. For the following example, @apply shadow-lg style appears to be ignored in the final result.

<div class="test">Test</div>

<style lang="postcss">
  .test {
    @apply shadow-lg;  /* This line of style is not applied by @unocss/transformer-directives 0.58.7 or later */
    @apply rounded-md bg-slate-300 shadow-amber-500;
  }
</style>

Issue can be resolved by combine style utilities into a single @apply. (Or by removing the simicolonOffset logic mentioned before)

<style lang="postcss">
  .test {
    @apply shadow-lg rounded-md bg-slate-300 shadow-amber-500;
  }
</style>

However, such outcome doesn’t seem to be reproduced on UnoCSS Playground. https://unocss.dev/play/?version=0.58.7&html=DwEwlgbgBAxgNgQwM5ILwCIAuBTJn0B8AKrpsAPTgQFA&config=PTAEFMGcBsEsDsAuBaAJrSBDARtcz5wAPFOQ0eAe2QCcpEbYBjRcVZWAWwAdKbFIAKC69%2BoAN6DQoVOABmCcAGFK8BQHMANFNANM8SHL6dwNACKw6LWADco26dzqRwiAIKIGsbAFdEsOQBPB1AnKFcAVSpBAF9QORpKTlAAch8qJkhIFMFBYlFEGXlMH2hC2QVCFTVYdQAKSUdnV0gALlAAbR0m8MQoyjqAShCel3dPRl9-IKGQgF0QvQMjGhMaNs7u3Rp9Q2NTCyt-O0hZnTnYwcEgA&css=HQFwpgziAEDeBQ1oAECGAHdAbAntCAFqgCYD2A7gLRYDmA3IihtngE6kCuAdsWMZQFti0AEY1KELKnCUAzAAZ5%2BImSqoBIsK0oBWRQwC%2BQA&options=N4IgLgTghgdgzgMwPYQLYGECucxIwZXxAC4EoAbOAUwBpxp5k0AJMVcksyqgXyA So far the issue is only visible in an actual SvelteKit+Vite project.

Can confirm. I ended up switching to tailwind because this is a prevalent issue in Unocss with Nuxt. Maybe check out @microdou post above @Simon-He95?

I will temporarily close this issue first, and you are welcome to open it at any time when a reproducible demo is provided.

With last version of nuxt its actual to me too. Some apply rules like width and height + flex rules sometimes not transform to css. Or it can work in development but not in production.