tailwindcss: tailwindcss in watch mode doesn't refresh outupt when files are changed using vim
This is based on #7679 - the versions being used are listed there.
I ended up setting up test-case project here: https://github.com/javornikolov/tailwindcss-issue-7679
There is Github Actions CI job which outlines the changes I do to reproduce the issue. However the issue does’t occur when running the automated scripts. It occurs when I manually edit the file using vim editor (doing the same changes).
vim version is 8.2
- The issue is not observed If I copy/paste files from
template/*to src. - The issue is (usually) not observed if I use other text editor -
gedit. Or if I also touch files (usingtouch -m). (Sometimes touch doesn’t help either - that’s more subtle, I am not sure how to consistently reproduce yet.)
Sometimes refresh of output.css happens when I use vim too but it’s quite rare (and is after some modifications of file outside of vim as well).
Steps to reproduce - based on the GithHub repo above:
- start tailwindcss --watch (e.g. via
npx pm2 start ecosystem.config.js) - Modify
src/tailwind.csscopy-pasting the content oftemplates/tailwind.css.2usingvim. - Similarly modify
src/index.html(using index.html.2) - What happens is that in output.css I only have
btn-cool-1but notbtn-cool-2. I uploaded the state of the files to branchtopic/after-change-using-vimin the same github repo. I included somestatoutputs in case that matters.
If I switch the order of modifying tailwind.css and index.html and I edit index.html first - then nor btn-cool-1, nor btn-cool-2 are included
Hypothesys
I suspect that the way vim saves files has specifics which are not yet recognized as changes to source files. Perhaps it can be reproduced outside vim, I am just not fully aware in what exactly way yet. Some insights might be possibly found e.g. here: https://vi.stackexchange.com/questions/25030/vim-not-firing-inotify-events-when-writing-file
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 28 (10 by maintainers)
Hey! Have you tried to set
:set backupcopy=yesas mentioned in your Stack Exchange link? It seems like that should solve your issue.@carderne I merged in another fix. It appears to work for me on Linux. Would you mind giving the insiders build a test?
npm install tailwindcss@insidersAlso having this issue, using any editor (including
sed).Minimal reproduction here: https://github.com/carderne/tailwind-watch-issue
My experience was that
:set backupcopy=noresolved the issue. As with a lot of vim configuration docs aren’t immediately obvious. This option dovetails withset backup/set nobackup.From the vim docs:
I have had a similar problem while developing a Ghost theme with Tailwind, and solved it by tweaking the watchers in my gulpfile.
In my gulpfile, the line that configured the watcher for my Handlebars (HBS) templates looked like this:
This would execute the HBS task when I saved a change to my front end code. However, it did not execute the CSS task, which meant that my CSS file in which I was importing Tailwind was not re-processed properly.
See below:
I solved it by adding the CSS task into the callback of the HBS watcher:
Yes, indeed -
backupcopy=yesseems to resolve the issue which I’ve described. This is the workaround which I am trying now: https://gist.github.com/nepsilon/003dd7cfefc20ce1e894db9c94749755Yet, there is still this the possibility that source files get changed in some way that
tailwindcss --watchdoes not recognize. Which makes me a bit uncertain when is the output css really in sync. I am not sure