Skip to content

Commit 2cf8e9d

Browse files
committed
Fix crash when reloading config.rb
The previous implementation cached the reactor on the extension instance. However, the instance doesn’t survive the reload and would try to create a new reactor. This failed, because the previous reactor wasn’t stopped. This change caches the reactor in the ractor class itself so it’s still there after the reload.
1 parent e3a3927 commit 2cf8e9d

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

lib/middleman-livereload/extension_3_1.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ def initialize(app, options_hash={}, &block)
2525
return unless app.environment == :development
2626
end
2727

28-
@reactor = nil
29-
3028
port = options.port.to_i
3129
host = options.host
3230
js_port = options.js_port || port
@@ -40,11 +38,7 @@ def initialize(app, options_hash={}, &block)
4038
extension = self
4139

4240
app.ready do
43-
if @reactor
44-
@reactor.app = self
45-
else
46-
@reactor = ::Middleman::LiveReload::Reactor.new(options_hash, self)
47-
end
41+
reactor = ::Middleman::LiveReload::Reactor.create(options_hash, self)
4842

4943
ignored = lambda do |file|
5044
return true if app.files.respond_to?(:ignored?) && app.files.send(:ignored?, file)
@@ -73,15 +67,15 @@ def initialize(app, options_hash={}, &block)
7367
reload_path = livereload_css_target
7468
end
7569

76-
@reactor.reload_browser(reload_path)
70+
reactor.reload_browser(reload_path)
7771
end
7872

7973
app.files.deleted do |file|
8074
next if ignored.call(file)
8175

8276
logger.debug "LiveReload: File deleted - #{file}"
8377

84-
@reactor.reload_browser("#{Dir.pwd}/#{file}")
78+
reactor.reload_browser("#{Dir.pwd}/#{file}")
8579
end
8680

8781
# Use the vendored livereload.js source rather than trying to get it from Middleman

lib/middleman-livereload/reactor.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ module LiveReload
77
class Reactor
88
attr_reader :thread, :web_sockets, :app
99

10+
def self.create(options, app)
11+
if @reactor
12+
@reactor.app = app
13+
else
14+
@reactor = new(options, app)
15+
end
16+
17+
@reactor
18+
end
19+
1020
def initialize(options, app)
1121
@app = app
1222
@web_sockets = []

0 commit comments

Comments
 (0)