Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ildarkayumov
Copy link

Fixes #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

this.connectedContexts.add(context)
context.connect()

if (!this.connectedContexts.has(context)) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need this to prevent double controller#connect

@sebastianludwig
Copy link

sebastianludwig commented May 28, 2024

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

@ildarkayumov
Copy link
Author

@marcoroth can you check this please?

@nemesit
Copy link

nemesit commented Oct 17, 2024

Would be nice if this could be merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

disconnect() not called if outlet is accessed in connect()
3 participants