Skip to content

[v4] flex-col not working on 4.0.2 and 4.0.3 in SSR mode via the vite starter templates #16148

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

Closed
thednp opened this issue Feb 1, 2025 · 12 comments

Comments

@thednp
Copy link

thednp commented Feb 1, 2025

I've successfully updated one of my projects to v4.0 and after updating to 4.0.2 flex-col is no longer working in SSR dev mode.

What version of Tailwind CSS are you using?

4.0.2 and 4.0.3

What build tool (or framework if it abstracts the build tool) are you using?
only vite and the tailwind vite plugin.

What version of Node.js are you using?
using a vanillaJS setup.

What browser are you using?

Chromium

What operating system are you using?

Linux

Reproduction URL
install any vite starter template and drop tailwindcss and vite plugin.

Describe your issue

Again, flex-col isn't working in DEV mode (npm run dev) since 4.0.2, but it does seem to work in 4.0.0 and 4.0.1.

@wongjn
Copy link
Collaborator

wongjn commented Feb 1, 2025

Followed your steps and it seems to be working: https://github.com/wongjn/tailwindcss-issue-16148

Consider providing a project that reproduces the unexpected behavior please.

@thednp
Copy link
Author

thednp commented Feb 1, 2025

@wongjn please open this stackblitz (it doesn't work in stackblitz at all) then

  • download the project (click download icon above the file explorer), and unpack
  • browse to the unpacked folder and run npm install
  • run npm run dev and see the flex-col doesn't apply.

Let me know if you encounter any issue.

@wongjn
Copy link
Collaborator

wongjn commented Feb 1, 2025

I don't see where you've used flex-col anywhere.

@thednp
Copy link
Author

thednp commented Feb 1, 2025

index.html -> line 11 <body class="flex flex-col h-screen">

@wongjn
Copy link
Collaborator

wongjn commented Feb 1, 2025

Sorry, I don't see that my end:

Image

@thednp
Copy link
Author

thednp commented Feb 1, 2025

Ok I think stackblitz won't give you the right code.
Please use this

tailwindcss-issue.zip

@thednp
Copy link
Author

thednp commented Feb 1, 2025

@wongjn let me know if you need anything else.

Please confirm.

@wongjn
Copy link
Collaborator

wongjn commented Feb 1, 2025

Thank you. It seems like Tailwind isn't compiling any class names sourced from the index.html file.

@thednp
Copy link
Author

thednp commented Feb 1, 2025

I suspect it has to do with the vite-plugin, but I'm not sure, the thing is only dev mode seems to fail, and this problem wasn't present with 4.0.0 and 4.0.1.

@wongjn
Copy link
Collaborator

wongjn commented Feb 1, 2025

Seems like it might be a regression from #16052 which introduced this check:

transformIndexHtml(html, { path }) {
// SolidStart emits HTML chunks with an undefined path and the html content of `\`.
if (!path) return
scanFile(path, html, 'html')
},

When debugging, I find that path is an empty string '', thus exiting early and not scanned.

@wongjn
Copy link
Collaborator

wongjn commented Feb 1, 2025

Testing with a "normal" Vite project, I see that in indexHtmlMiddleware, it calls transformIndexHtml() with:

// url = '/index.html'
// html = '<!doctype html>\n…'
// req.originalUrl = '/'
server.transformIndexHtml(url, html, req.originalUrl)

But in your server.js that calls the same transformIndexHtml() in dev mode:

// url = ''
// template = = '<!DOCTYPE html>\n…'
// url = ''
template = await vite.transformIndexHtml(url, template, url)

This then causes the check for a non-empty path to fail in:

transformIndexHtml(html, { path }) {
// SolidStart emits HTML chunks with an undefined path and the html content of `\`.
if (!path) return
scanFile(path, html, 'html')
},

Thus Tailwind does not scan your index.html file. Thus, any unique class names in the index.html are not generated in the output CSS.

As a work-around, you may wish to consider emulating the parameter values to pass to transformIndexHtml() more closely as Vite core's indexHtmlMiddleware, i.e. non-empty values for url and originalUrl.

@thednp
Copy link
Author

thednp commented Feb 1, 2025

Indeed, I've added this,

const url = req.originalUrl.replace(base, "") || "/";
// __________________________________________  ^^^^^

updated to latest tailwind and boom, magic is going on!

THANK YOU!!

@thednp thednp closed this as completed Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants