hotwired / hotwired/stimulus

Custom `targetAttributeForScope` breaks target lifecycle callbacks

Open
#809 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
13.1k
Forks
441
PR merge metrics
No merged PRs in 30d

Description

When using a custom targetAttributeForScope callback, target (dis)connected callbacks no longer work. This seems to be because TargetObserver hardcodes the default attribute format:

https://github.com/hotwired/stimulus/blob/101a060f961e9240b55b29e25fdfe82c79b9c5b0/src/core/target_observer.ts#L75-L77

All target properties on the controller ([name]Target, has[Name]Target, etc) do work as expected.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/core/target_observer.ts at the linked lines where TargetObserver builds the target attribute. Trace how targetAttributeForScope is used alongside target lifecycle observation, then verify that custom attributes trigger connected and disconnected callbacks while existing target properties continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.