railsjazz / rails_live_reload

Live Reload for your Rails app. The easiest way to increase your productivity.
https://www.railsjazz.com/
MIT License
318 stars 8 forks source link

Add WebSocket mode #14

Closed manastyretskyi closed 2 years ago

manastyretskyi commented 2 years ago

I think this should solve #12.

igorkasyanchuk commented 2 years ago

@saiqulhaq @Gee-Bee we need your help, can you try this branch if it works for you without any problems. For me by default I had issue with compiling openssl on mac, so we need to double-check this. Thank you

Gee-Bee commented 2 years ago

Have been using this branch since yesterday. I've seen a few times 'Unable to find RailsLiveReload options' message in a browser console, after which I had to reload the page manually. It was random and I cannot reproduce it though. I was mainly working with React component loaded by the Stimulus controller. I'll report back if it reappears. Other than that it works great.

Comparing to the master branch:

manastyretskyi commented 2 years ago

Thanks for the feedback, I will take a look and try to improve options passing. Unfortunately some people ran into some troubles with gem installation because of faye-websocket dependency eventmachine, so I guess I will have to rewrite this a little.

Gee-Bee commented 2 years ago

Oh, I see. I installed it in docker container from an official ruby image based on Debian Linux without a problem. Indeed, I can see eventmachine has open issues regarding installing it on macOS, because they removed openssl headers from the system.

czepesch commented 2 years ago

I think this should solve #12.

Hi, I installed gem using this branch and can confirm that everything works fine. I'll keep testing and if the problem occurs again, I'll notify you. Thanks!

manastyretskyi commented 2 years ago

Hi guys, would appreciate some help with testing this 😄 I rewrote it to drop eventmachine dependency, now we have small copy (literally 😅) of action cable websocket implementation, it depends on nio4r just as puma does, so I think this should work basically for anyone.

czepesch commented 2 years ago

I pulled latest commit. Yes, it works perfectly so far, can't see any problems.

czepesch commented 2 years ago

khm.. it was okay few hours straight, but looks like the issue somehow returned :(

p.s. I don't know if this could be helpful or not, before this gem I was using this method to achieve live reloading in Rails: https://www.colby.so/posts/live-reloading-with-esbuild-and-rails it has no such problem with slow loading, but obviously takes more time to setup than just using gem.

manastyretskyi commented 2 years ago

Hi @czepesch, In general we are doing the same thing. To be honest I not sure why such thing would happen again with websocket mode, previously the problem with slow loading occurred because sometimes when you made a request to the server it was queued to the same process where long poling request was opened. But now this uses websockets and thread is available for other requests as soon as connection is established, our implementation is same as actioncable so it should be working fine. I would appreciate if you made a sample repo where this reproduces and/or take a video of this issue.

igorkasyanchuk commented 2 years ago

@czepesch curious how long it takes to compile your CSS? And what is the average time of reloading the page?

for me now an issue that when I change ERB(with tailwind) esbuild compiles CSS longer than pages is rendering.

czepesch commented 2 years ago

video: https://drive.google.com/file/d/1n-0M9MrD3AXhu-c76FyAEhfl_0zJ2qCB/view sample app: https://github.com/r-rails/plants, now I'm on plants_index_page branch. When I change tailwind styles on page or adding\changing html elements - page refreshes fast. When I manually click on links - it can take from few seconds to tens of seconds.

manastyretskyi commented 2 years ago

You are using the old version, please update to 0.2.0 and try again.

image
igorkasyanchuk commented 2 years ago

and one more Interesting finding

"build:css": "tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify"

try to remove --minify, this is what helped me.

In addition, you can change if you are using non-default contig (to websocket)

RailsLiveReload.configure do |config|
  # config.url     = "/rails/live/reload"
  # Available modes are: :websocket (default), :long_polling and :polling
  config.mode = :websocket
czepesch commented 2 years ago

You are using the old version, please update to 0.2.0 and try again. image

oh my god.. I made changes in Gemfile (removed git: this branch) but forgot bundle update

and one more Interesting finding

"build:css": "tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify"

try to remove --minify, this is what helped me.

In addition, you can change if you are using non-default contig (to websocket)

RailsLiveReload.configure do |config|
  # config.url     = "/rails/live/reload"
  # Available modes are: :websocket (default), :long_polling and :polling
  config.mode = :websocket

Okay, I will keep it mind!

I'm sorry for being inattentive. Thank you!

igorkasyanchuk commented 2 years ago

@czepesch so now all works well?

czepesch commented 2 years ago

@igorkasyanchuk yes. It worked well when I was on gem 'rails_live_reload', git: 'https://github.com/railsjazz/rails_live_reload.git', branch: 'feature/websocket' then I saw you merged, removed git: branch and continued working. It was okay some time and then it started behaving like before. So I was confused 😵‍💫