rails / tailwindcss-rails

MIT License
1.39k stars 171 forks source link

Avoid stdin read by tailwindcss watch command #349

Closed tompng closed 5 months ago

tompng commented 5 months ago

Description

tailwindcss -w reads stdin, probably to detect stdin close. When using binding.irb or debugger with tailwindcss-rails, some keystrokes are taken by tailwindcss and IRB/Debug can't read from stdin correctly. Keystroke disappears, and sometimes hangs up. To not let tailwindcss watch command read stdin, we should use IO.popen(command, 'r+') instead of system(*command). Workaround for https://github.com/rails/tailwindcss-rails/discussions/346

Reproduction code

watch_command = ['./node_modules/.bin/tailwindcss', '-w']
Thread.new do # same for `fork do`
  system(*watch_command)
  # IO.popen(watch_command, 'r+') do |io|
  #   IO.copy_stream(io, $stdout)
  # end
  puts 'command finished'
end
sleep 1
binding.irb

Side effect

Before this pull request, Ctrl-D will stop rails s. Closing stdin will stop tailwind, then puma will stop with a message Detected tailwind has gone away, stopping Puma... After this change, Ctrl-D won't stop tailwind.

mbhnyc commented 5 months ago

just hit this yesterday, applause!

flavorjones commented 5 months ago

@tompng Thank you for opening this! Will try it out.

flavorjones commented 5 months ago

Shipped in https://github.com/rails/tailwindcss-rails/releases/tag/v2.4.1