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

Tailwindcss doesn't rebuild CSS for new files #18552

Open
7 tasks done
bluwy opened this issue Nov 1, 2024 · 1 comment
Open
7 tasks done

Tailwindcss doesn't rebuild CSS for new files #18552

bluwy opened this issue Nov 1, 2024 · 1 comment

Comments

@bluwy
Copy link
Member

bluwy commented Nov 1, 2024

Describe the bug

I don't remember if we've discussed before, but tailwindcss can't seem to track new files due to limitations of this.addWatchFile:

} else if (message.type === 'dir-dependency') {
// https://github.com/postcss/postcss/blob/main/docs/guidelines/plugin.md#3-dependencies
const { dir, glob: globPattern = '**' } = message
const files = globSync(globPattern, {
absolute: true,
cwd: path.resolve(path.dirname(id), dir),
expandDirectories: false,
ignore: ['**/node_modules/**'],
})
for (let i = 0; i < files.length; i++) {
deps.add(files[i])
}

I'm not sure if we want to special case this, or leave it to tailwind's next major to possibly fix things.

Found this from withastro/astro#12255

Related: #15460 (but not exactly the same I think)

Reproduction

https://stackblitz.com/edit/vitejs-vite-nk6bcl?file=index.html&terminal=dev

Steps to reproduce

  • Start dev server
  • Copy the content of index.html and create a new foo.html at the root for example and paste the content in it.
  • Rename text-red-500 in the pasted content to something else new, like text-green-500
  • Open http://localhost:5173/foo and notice that the text is black, not green (for example)

After a full server restart and reload the page, the color is then correctly applied

System Info

n/a

Used Package Manager

npm

Logs

No response

Validations

@sapphi-red
Copy link
Member

We should be able to support this by doing something similar to the vite:import-glob plugin.

hotUpdate({ type, file, modules: oldModules }) {
if (type === 'update') return
const importGlobMap = importGlobMaps.get(this.environment)
if (!importGlobMap) return
const modules: EnvironmentModuleNode[] = []
for (const [id, globMatchers] of importGlobMap) {
if (globMatchers.some((matcher) => matcher(file))) {
const mod = this.environment.moduleGraph.getModuleById(id)
if (mod) modules.push(mod)
}
}
return modules.length > 0 ? [...oldModules, ...modules] : undefined
},

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

2 participants