Using middleware causes Rails actions to be invoked twice
shepmaster opened this issue · comments
Bug Report
Describe the bug
When a middleware is used, Rails actions are invoked twice for every Reflex action.
To Reproduce
Add a middleware:
class DummyMiddleware
def initialize(app)
@app = app
end
def call(env)
@app.call(env)
end
end
StimulusReflex.configure do |config|
config.middleware.use DummyMiddleware
end
Then perform a page morph. In our application, we use Stimulus Reflex for live form validation, so every (debounced) input triggers a reflex. In the logs below, I'm hitting a in a form field.
Expected behavior
The controller action is invoked once:
StimulusReflex::Channel#receive({ ... })
Processing by ProjectsController#new as HTML
Completed 200 OK in 109ms (Views: 69.5ms | ActiveRecord: 18.6ms | Allocations: 108076)
[ActionCable] Broadcasting to StimulusReflex::Channel:1;1: { ... }
StimulusReflex::Channel transmitting ... (via streamed from StimulusReflex::Channel:1;1)
[46cc5e92] 1/1 StimulusReflex::Reflex#default_reflex -> #new_project via Page Morph (morph)
Actual behavior
The controller action is invoked twice:
StimulusReflex::Channel#receive({ ... })
Processing by ProjectsController#new as HTML
Completed 200 OK in 118ms (Views: 71.5ms | ActiveRecord: 17.2ms | Allocations: 109144)
Processing by ProjectsController#new as HTML
Completed 200 OK in 6ms (Views: 5.3ms | ActiveRecord: 0.0ms | Allocations: 9249)
[ActionCable] Broadcasting to StimulusReflex::Channel:1;1: { ... }
[46cc5e92] 1/1 StimulusReflex::Reflex#default_reflex -> #new_project via Page Morph (morph)
StimulusReflex::Channel transmitting ... (via streamed from StimulusReflex::Channel:1;1)
Versions
StimulusReflex
- Gem: 3.4.1
- Node package: 3.4.1
External tools
- Ruby: 3.0.2p107 (2021-07-07 revision 0db68f0233) [arm64-darwin21]
- Rails: 6.1.4.1
- Node: v16.13.0
Browser
- Chrome 98.0.4706.0 (Official Build) canary (arm64)
Jake, can you comment on whether this issue persists after implementing the solution discussed in #565, please?
I'm going to close this based on the provided solution in #565. Please feel free to re-open this issue if you still encounter something weird, thank you!