Skip to content

Commit

Permalink
Re-evaluate script tags
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldrapper committed Mar 22, 2024
1 parent 13b9825 commit eb1b0f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/phlex/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Rails
autoload :Layout, "phlex/rails/layout"
autoload :SGML, "phlex/rails/sgml"
autoload :UnbufferedOverrides, "phlex/rails/unbuffered_overrides"
autoload :Streaming, "phlex/rails/streaming"
end

CSV.prepend Phlex::Rails::CSV::Overrides
Expand Down
7 changes: 7 additions & 0 deletions lib/phlex/rails/streaming.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ def stream(view)
if Rails.env.development?
js = <<~JAVASCRIPT
document.documentElement.innerHTML = "#{view_context.j(debug_body.join)}";
// Re-evaluate all script tags
document.querySelectorAll("script").forEach((script) => {
newScript = document.createElement("script");
newScript.text = script.text;
script.replaceWith(newScript);
});
JAVASCRIPT
else
js = <<~JAVASCRIPT
Expand Down

0 comments on commit eb1b0f8

Please sign in to comment.