Skip to content

Commit 4b07e87

Browse files
committed
Add basic Hotwire Spark support
1 parent 60f92f3 commit 4b07e87

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Diff for: lib/custom_elements/rails/railtie.rb

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,23 @@ module CustomElements
22
module Rails
33
class Railtie < ::Rails::Engine
44
initializer "custom_elements-rails.assets.precompile" do |app|
5-
if app.config.respond_to? :assets
5+
if app.config.respond_to?(:assets)
66
app.config.assets.precompile += %w( custom_elements-rails.js )
77
end
88
end
9+
10+
initializer "custom_elements-rails.spark", after: "hotwire_spark.config" do |app|
11+
spark_available = app.config.respond_to?(:hotwire) && app.config.hotwire.respond_to?(:spark)
12+
if spark_available
13+
puts "spark_available"
14+
# Custom elements don't seem to work with morphing
15+
Hotwire::Spark.html_reload_method = :replace
16+
17+
# Just force full reloads after custom element change for now
18+
Hotwire::Spark.html_paths << ::Rails.root.join("app/javascript/custom_elements").to_s
19+
Hotwire::Spark.html_extensions << "js"
20+
end
21+
end
922
end
1023
end
1124
end

0 commit comments

Comments
 (0)