Skip to content

Avoid stdin read by tailwindcss watch command#349

Merged
flavorjones merged 1 commit into
rails:mainfrom
tompng:avoid_stdin_read_from_watch_command
Apr 25, 2024
Merged

Avoid stdin read by tailwindcss watch command#349
flavorjones merged 1 commit into
rails:mainfrom
tompng:avoid_stdin_read_from_watch_command

Conversation

@tompng

@tompng tompng commented Apr 24, 2024

Copy link
Copy Markdown
Contributor

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 #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.

…ch command

`tailwindcss -w` reads stdin, probably to detect stdin close.
When using binding.irb or debugger with tailwindcss-rails, some keystrokes are taken by tailwindcss.
To not let tailwindcss watch command read stdin, we should use `IO.popen(command, 'r+')` instead of `system(*command)`.
Workaround for rails#346
@mbhnyc

mbhnyc commented Apr 24, 2024

Copy link
Copy Markdown

just hit this yesterday, applause!

@flavorjones

Copy link
Copy Markdown
Member

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

@flavorjones flavorjones merged commit cfaa58f into rails:main Apr 25, 2024
@flavorjones

Copy link
Copy Markdown
Member

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

Successfully merging this pull request may close these issues.

3 participants