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

Weird atomic CSS class generating issues depending on render mode #390

Closed
AaronBeaudoin opened this issue Jul 28, 2022 · 5 comments
Closed
Labels

Comments

@AaronBeaudoin
Copy link
Contributor

AaronBeaudoin commented Jul 28, 2022

Description

I'm testing out VPS with 2 atomic CSS frameworks: Tailwind CSS, and UnoCSS. Neither of them work 100%. Behavior depends on the rendering mode of the page. Follow the reproduction steps below along with the linked minimal reproduction to see the issues.

Minimal Reproduction

https://github.com/AaronBeaudoin/vps-issue-atomic-css

First, The Setup

npm install postcss autoprefixer tailwindcss unocss

Tailwind CSS Files

// postcss.config.js

module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {}
  }
};
// tailwind.config.js

module.exports = {
  mode: "jit",
  content: [
    "./pages/**/*.{vue,js}",
    "./renderer/_default.page.server.js"
  ]
};
/* pages/index.css */

@tailwind base;
@tailwind components;
@tailwind utilities;

UnoCSS Plugin Config

// vite.config.js

import { defineConfig } from "vite";
import VitePluginUnoCSS from "unocss/vite";

export default defineConfig({
  plugins: [
    ...
    VitePluginUnoCSS({
      presets: [],
      rules: [
        [
          // Lets you do `bg-red`, `bg-blue`, etc...
          /^bg-([a-z]+)$/,
          match => ({ "background-color": match[1] })
        ]
      ]
    })
  ]
});

_default.page

// _default.page.server.js

import "/pages/index.css";
import "uno.css";
...
// _default.page.client.js

import "/pages/index.css";
import "uno.css";
...

I import in both, because I wanted to try and make sure that my issue isn't coming from the stylesheet no being available on one side or the other (server vs client).

The Actual Page

<!-- pages/index.page.vue -->

<template>
  <div class="bg-blue-500">tailwind</div>
  <div class="bg-blue">unocss</div>
</template>

Reproduction Steps

SSR Mode

No issues! Everything works fine. 🎉

SPA Mode

Change index.page.vue to index.page.client.vue and restart the dev server. (Any CSS that was generated so far seems to be cached, so you need to do a full server restart to clear things out.)

Now, first of all, HMR doesn't work in SPA mode, but we already know that from vitejs/vite#9341.

But aside from that, this is what I'm seeing:

  1. On the initial server start, both elements get a blue background color no problem.
  2. Change blue for both elements to red and save. Refresh the page in the browser (since HMR is broken right now).
  3. Only UnoCSS updates properly. Tailwind CSS doesn't seem to be able to update for some reason. The element class updated, but Tailwind CSS doesn't seem to be able to recognize the change and create CSS for the new class.
  4. Restart the dev server. Now both elements have a red background color as expected.

HTML-Only Mode

Change index.page.vue to index.page.server.vue and restart the dev server again.

  1. On the initial server start, both elements get a red background color no problem.
  2. Change red for both elements to green and save.
  3. Only Tailwind CSS updates properly this time. UnoCSS doesn't seem to be able to update for some reason. The element class updated, but UnoCSS doesn't seem to be able to recognize the change and create CSS for the new class.
  4. Refresh the page in the browser. Notice that didn't change anything.
  5. Restart the dev server. Now both elements have a green background color as expected.

Error Stack

No response

@brillout
Copy link
Member

I guess these issues are unrelated to vps?

@AaronBeaudoin
Copy link
Contributor Author

You're probably right. A main goal of mine right now is to figure out how to create minimal reproductions for these sorts of things without VPS so I can totally rule it out.

@brillout
Copy link
Member

Note that even if the presence of vps is causing problems, it still is most likely a problem on their side.

@AaronBeaudoin
Copy link
Contributor Author

Made an issue for UnoCSS: unocss/unocss#1351

Still have yet to make one for Tailwind CSS. I think I might just wait till the client HMR thing is figured out so that issue can be demonstrated in isolation a little bit better.

@brillout
Copy link
Member

I guess we can close this in the meantime.

Let's re-open if it turns out to be a vps problem.

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

No branches or pull requests

2 participants