Skip to content

feat!: NativeLabel.setFor() lazily resolves and auto-generates IDs#24425

Open
Artur- wants to merge 4 commits into
mainfrom
claude/slack-session-7fVlC
Open

feat!: NativeLabel.setFor() lazily resolves and auto-generates IDs#24425
Artur- wants to merge 4 commits into
mainfrom
claude/slack-session-7fVlC

Conversation

@Artur-
Copy link
Copy Markdown
Member

@Artur- Artur- commented May 22, 2026

The setFor(Component) method now uses beforeClientResponse to lazily resolve the component's ID at sync time rather than requiring it immediately. If the component still doesn't have an ID by then, one is automatically generated.

This makes NativeLabel easier to use because developers no longer need to manually assign IDs to components when using setFor().

Fixes #24424

https://claude.ai/code/session_014v3s2ioBp5pSwd4F3Euqt5

The setFor(Component) method now uses beforeClientResponse to lazily
resolve the component's ID at sync time rather than requiring it
immediately. If the component still doesn't have an ID by then, one is
automatically generated.

This makes NativeLabel easier to use because developers no longer need
to manually assign IDs to components when using setFor().

Fixes #24424

https://claude.ai/code/session_014v3s2ioBp5pSwd4F3Euqt5
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 22, 2026

Test Results

 1 420 files  ±0   1 420 suites  ±0   1h 19m 41s ⏱️ -54s
10 005 tests +5   9 937 ✅ +5  68 💤 ±0  0 ❌ ±0 
10 477 runs  +5  10 408 ✅ +5  69 💤 ±0  0 ❌ ±0 

Results for commit 653f833. ± Comparison against base commit 38c25dd.

♻️ This comment has been updated with latest results.

@mstahv
Copy link
Copy Markdown
Member

mstahv commented May 25, 2026

Same pattern should be applied also for setAriaLabelledBy(String ariaLabelledBy) (in HasAriaLabel). Check if there could be a common helper.

Adds a Component overload of setAriaLabelledBy that lazily resolves the
target component's id at sync time and auto-generates one if needed,
mirroring the pattern introduced for NativeLabel.setFor(Component).

The lazy-resolve-and-auto-generate logic is extracted into a new
ComponentUtil.resolveOrGenerateIdLater helper and reused by both
NativeLabel.setFor(Component) and HasAriaLabel.setAriaLabelledBy(Component).

Note: as with NativeLabel.setFor, the new Component overload makes
setAriaLabelledBy(null) ambiguous; callers clearing the attribute must
cast to (String) null.
@github-actions github-actions Bot added +0.1.0 and removed +0.0.1 labels May 25, 2026
@mstahv
Copy link
Copy Markdown
Member

mstahv commented May 25, 2026

Now Claude should seek for other similar patterns in the framework (and in flow-componens project) that I have missed/don't remember.

A thing to also consider: deprecate the current versions that work with string identifier. I can only see those relevant/better for some integrations with other frameworks/libraries and then Element API level of integration might be even better.

@mshabarov mshabarov requested a review from mcollovati May 25, 2026 11:44
HtmlComponentSmokeTest.testSetter requires each setter to have a getter
of the matching type. The new Component overload doesn't (getter still
returns Optional<String>), mirroring NativeLabel.setFor(Component) which
already has an isSpecialSetter exclusion for the same reason.
@sonarqubecloud
Copy link
Copy Markdown

* @param labelComponent
* the component to use as the label, not {@code null}
*/
default void setAriaLabelledBy(Component labelComponent) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The introduction of this method is potentially a breaking change that might cause compilation errors if the application used to call setAriaLabelledBy(String) with null as an argument.
Perhaps it's fine but should be documented in the release notes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Somebody would in this case be clearing the "binding" to a label component. This is maybe one of those cases that it can happen even if we don't believe it. My hunch is this would be extremely rare (and easy to fix), so I'd just do that release note comment and follow the situation. If the world explodes in e.g. ecosystem build or otherwise during beta period, we can rollback or rename to e.g. setAriaLabelledByComponent.

Copy link
Copy Markdown
Collaborator

@mcollovati mcollovati left a comment

Choose a reason for hiding this comment

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

Overall looks good. There's only the potential breaking change introduced by the new setAriaLabelledBy method.

@mcollovati mcollovati changed the title feat: NativeLabel.setFor() lazily resolves and auto-generates IDs feat!: NativeLabel.setFor() lazily resolves and auto-generates IDs May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make NativeLabel bettter for developer

5 participants