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

Livereload not working with asset-hashing enabled outside of the build-block #71

Open
kasper opened this issue Jan 22, 2015 · 14 comments
Open

Comments

@kasper
Copy link

kasper commented Jan 22, 2015

I can’t seem to get the latest livereload and Middleman to work on OS X 10.10.1 and Ruby 2.2.0. It sometimes states it’s listening for browsers to connect, sometimes not. However no updates are pushed to Safari. Reloading manually works fine.

File Gemfile

gem 'middleman', '3.3.7'
gem 'middleman-livereload', '3.4.2'

File config.rb

activate :livereload
middleman-site $ bundle exec middleman --verbose
== The Middleman is loading
== Activating: sprockets
== Reading:  Local config
== Activating: livereload
== Activating: directory_indexes
== Activating: asset_hash
== Activating: minify_css
== Activating: minify_javascript
Loaded extensions:
== Extension: sprockets
== Extension: livereload
== Extension: directory_indexes
== Extension: asset_hash
== Extension: minify_css
== Extension: minify_javascript
== Extension: frontmatter
== File Change: config.rb
== File Change: source/assets/stylesheets/style.css.scss
== File Change: source/index.html.haml
== File Change: source/layouts/layout.haml
== Rebuilding resource list
== LiveReload accepting connections from http://10.0.1.14:35729
[2015-01-22 18:27:15] INFO  WEBrick 1.3.1
[2015-01-22 18:27:15] INFO  ruby 2.2.0 (2014-12-25) [x86_64-darwin14]
== The Middleman is standing watch at http://0.0.0.0:4567
== Inspect your site configuration at http://0.0.0.0:4567/__middleman/
[2015-01-22 18:27:15] INFO  WEBrick::HTTPServer#start: pid=4117 port=4567
== Request: /
== Finishing Request: index.html (0.01s)
== File Change: source/index.html.haml
== Rebuilding resource list
LiveReload: File changed - source/index.html.haml
== LiveReloading path: /
^C[2015-01-22 18:28:10] INFO  going to shutdown ...
[2015-01-22 18:28:10] INFO  WEBrick::HTTPServer#start done.
== The Middleman is shutting down
@Arcovion
Copy link
Contributor

Try activate :live_reload, host: '127.0.0.1', port: '4567'

@kasper
Copy link
Author

kasper commented Jan 23, 2015

@Arcovion Nope, doesn’t work.

middleman-site $ bundle exec middleman --verbose
== The Middleman is loading
== Activating: sprockets
== Reading:  Local config
== Activating: livereload
== Activating: directory_indexes
== Activating: asset_hash
== Activating: minify_css
== Activating: minify_javascript
Loaded extensions:
== Extension: sprockets
== Extension: livereload
== Extension: directory_indexes
== Extension: asset_hash
== Extension: minify_css
== Extension: minify_javascript
== Extension: frontmatter
== File Change: .rubocop.yml
== File Change: .ruby-version
== File Change: config.rb
== File Change: LICENSE.md
== File Change: README.md
== File Change: source/assets/images/.keep
== File Change: source/assets/javascripts/.keep
== File Change: source/assets/stylesheets/style.css.scss
== File Change: source/index.html.haml
== File Change: source/layouts/layout.haml
== Rebuilding resource list
== LiveReload accepting connections from http://127.0.0.1:4567
[2015-01-23 11:50:01] INFO  WEBrick 1.3.1
[2015-01-23 11:50:01] INFO  ruby 2.2.0 (2014-12-25) [x86_64-darwin14]
== The Middleman is standing watch at http://0.0.0.0:4567
== Inspect your site configuration at http://0.0.0.0:4567/__middleman/
[2015-01-23 11:50:01] INFO  WEBrick::HTTPServer#start: pid=838 port=4567
^C[2015-01-23 11:51:53] INFO  going to shutdown ...
[2015-01-23 11:51:53] INFO  WEBrick::HTTPServer#start done.
== The Middleman is shutting down

The server responds with an empty reply.

~ $ curl -v http://127.0.0.1:4567
* Rebuilt URL to: http://127.0.0.1:4567/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 4567 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: 127.0.0.1:4567
> Accept: */*
> 
* Empty reply from server
* Connection #0 to host 127.0.0.1 left intact
curl: (52) Empty reply from server

By the way, if I edit livereload settings while the server is running, I get an infinite loop of errors.

[2015-01-23 11:48:37] ERROR NoMethodError: undefined method `[]' for nil:NilClass
    /Users/Kasper/.rbenv/versions/2.2.0/lib/ruby/2.2.0/webrick/server.rb:174:in `block in start'

With the default settings, I’m not even seeing livereload.js injected into my Haml-templates. Shouldn’t it be?

@Arcovion
Copy link
Contributor

Actually, leave off the port option - only change the host to 127.0.0.1.
It should be injected on any html page with a tag, you can check for a response with this:

curl -v -H "Connection: Upgrade" -H "Upgrade: websocket" 127.0.0.1:35729

@kasper
Copy link
Author

kasper commented Jan 23, 2015

@Arcovion Ok. The WebSocket server is working with both the default settings and custom host. I can see curl connecting to Middleman as well. For some reason the livereload.js is not injected to the page.

middleman-site $ curl -v -H 'Connection: Upgrade' -H 'Upgrade: websocket' localhost:35729
* Rebuilt URL to: localhost:35729/
* Hostname was NOT found in DNS cache
*   Trying ::1...
* connect to ::1 port 35729 failed: Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 35729 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:35729
> Accept: */*
> Connection: Upgrade
> Upgrade: websocket
> 
< HTTP/1.1 101 Web Socket Protocol Handshake
< Upgrade: WebSocket
< Connection: Upgrade
< WebSocket-Origin: 
< WebSocket-Location: ws://localhost:35729/
middleman-site $ curl -v -H 'Connection: Upgrade' -H 'Upgrade: websocket' 10.0.1.14:35729
* Rebuilt URL to: 10.0.1.14:35729/
* Hostname was NOT found in DNS cache
*   Trying 10.0.1.14...
* Connected to 10.0.1.14 (10.0.1.14) port 35729 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: 10.0.1.14:35729
> Accept: */*
> Connection: Upgrade
> Upgrade: websocket
> 
< HTTP/1.1 101 Web Socket Protocol Handshake
< Upgrade: WebSocket
< Connection: Upgrade
< WebSocket-Origin: 
< WebSocket-Location: ws://10.0.1.14:35729/
middleman-site $ curl -v http://localhost:4567
* Rebuilt URL to: http://localhost:4567/
* Hostname was NOT found in DNS cache
*   Trying ::1...
* connect to ::1 port 4567 failed: Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 4567 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:4567
> Accept: */*
> 
< HTTP/1.1 200 OK 
< Content-Type: text/html; charset=utf-8
< Content-Length: 153
* Server WEBrick/1.3.1 (Ruby/2.2.0/2014-12-25) is not blacklisted
< Server: WEBrick/1.3.1 (Ruby/2.2.0/2014-12-25)
< Date: Fri, 23 Jan 2015 13:58:17 GMT
< Connection: Keep-Alive
< 
<!DOCTYPE html>
<html>
  <head>
    <meta charset='UTF-8'>
    <title>Hello World!</title>
  </head>
  <body>
    <p>Hello World!</p>
  </body>
</html>
* Connection #0 to host localhost left intact

@Arcovion
Copy link
Contributor

Everything looks correct to me, could be a bug in the underlying rack-livereload middleware (which is what injects the <script> tags)
@tdreyno any ideas?

@tdreyno
Copy link
Member

tdreyno commented Jan 23, 2015

Not really. I don't use live reload and most of this code is community contributed, so it's a mystery.

@everflux
Copy link

I had the same problem when having

activate :asset_hash

outside of the :build block.
When moving the asset_hash to the build configuration the livereload code was injected correctly and worked.

@tdreyno
Copy link
Member

tdreyno commented Jan 31, 2015

@everflux That makes a bit of sense. Can anyone else confirm this is how their config is setup?

@kasper
Copy link
Author

kasper commented Jan 31, 2015

@tdreyno Actually, I have asset-hashing also activated outside of the build-block. I have to test this...

@kasper
Copy link
Author

kasper commented Feb 1, 2015

@tdreyno @everflux Yes, indeed that is the issue. I got livereload working. Activating asset-hashing outside of the build-block prevents livereload to be injected correctly.

@kasper kasper changed the title Livereload not working on Ruby 2.2.0 + Safari Livereload not working with asset-hashing enabled outside of the build-block Feb 1, 2015
@tdreyno
Copy link
Member

tdreyno commented Feb 1, 2015

Wonderful. We've got a new team who will be maintaining this repo. This looks like a great bug for them to jump in on. cc @marytaylor

@emanuelet
Copy link

same thing happen with autoprefixer outside of the building block

@Liney
Copy link

Liney commented May 21, 2016

I just resolved this on my pc. Opened port 35729 on my firewall.

@sandstrom
Copy link
Contributor

I'm doing some issue-gardening 🌿🌷🌾 and came across this issue.

Sorry that this has lingered for quite a while! I'd suggest either closing this issue or submitting a PR with an implementation or at least a failing test.

(this repo is maintained by a few people contributing their free time, unfortunately we can't solve every issue on our own, so help from others is needed for some of the more exotic issues that crops up)

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

No branches or pull requests

7 participants