stimulusreflex / stimulus_reflex

Build reactive applications with the Rails tooling you already know and love.
https://docs.stimulusreflex.com
MIT License
2.28k stars 172 forks source link

If the element no longer exists, try to find it. #412

Closed jonathan-s closed 3 years ago

jonathan-s commented 3 years ago

Feature Request

In the lifecycle, if the element was morphed out of existence StimulusReflex warns the user that the element is no longer there and that we should move the reflex higher up.

What we can do is to try and find the element if the element has an id or data-key.

https://github.com/hopsoft/stimulus_reflex/blob/6daf13fbe526c0b14e5bff1b1c5a9f2e483ccdd0/javascript/lifecycle.js#L146

Is your feature request related to a problem?

When a morph modifies the html code it will no longer 'contain' that element. The element can still be findable by an id or similar.

Describe the solution you'd like

See above.

marcoroth commented 3 years ago

Hey @jonathan-s, this is what we are doing on L148 🙈

https://github.com/hopsoft/stimulus_reflex/blob/6daf13fbe526c0b14e5bff1b1c5a9f2e483ccdd0/javascript/lifecycle.js#L148

jonathan-s commented 3 years ago

Just realized! Feels like it always happens when I open an issue 🤦‍♂️