hotwired / stimulus

A modest JavaScript framework for the HTML you already have
https://stimulus.hotwired.dev/
MIT License
12.73k stars 426 forks source link

Do not ScopeObserver#scopeReferenceCounts when outlet is called before controller is connected #771

Open ildarkayumov opened 6 months ago

ildarkayumov commented 6 months ago

Fixes https://github.com/hotwired/stimulus/issues/763

The problem occurs when Outlet is accessed before controller has been connected by Stimulus and somebody tries to disconnect such controller later.

in such case ScopeObserver#elementMatchedValue is called 2 times so this.scopeReferenceCounts is eq 2. and during ScopeObserver#elementUnmatchedValue this counter this.scopeReferenceCounts remains >= 1 so scopeDisconnected(value) is not called

sebastianludwig commented 6 months ago

I can confirm that this PR resolves the initially reported issue in #763 🎉 Thank you very much!

ildarkayumov commented 6 months ago

@marcoroth can you check this please?

nemesit commented 1 month ago

Would be nice if this could be merged