Skip to content

feat(web_core): expose the raw action on GenericBinder action closures - #4055

Closed
Anoshor wants to merge 8 commits into
a2ui-project:mainfrom
Anoshor:feat/binder-raw-action
Closed

Anoshor wants to merge 8 commits into
a2ui-project:mainfrom
Anoshor:feat/binder-raw-action

Conversation

@Anoshor

@Anoshor Anoshor commented Nov 8, 2026 •

Copy link
Copy Markdown

Description

GenericBinder turns an action prop into an (options?) => Promise<void> closure, and that closure is all a host or component receives. It cannot tell an event action from a function call action before invoking it, for example to show a loading state only for a server event, or to record analytics.

As proposed in the issue, bindAction now attaches the unresolved action to the closure as rawAction. The value is the action as the component declared it (bindings such as {path: '/user/name'} are not resolved). Cached closures are only reused when the action is jsonEquals to the cached one, so rawAction always matches the current action. The action prop is now typed as a new exported ActionClosure: the same callable as before plus an optional rawAction, so reading it needs no cast. It is optional in the type so a plain function, such as a test double, is still assignable to an action property; GenericBinder always sets it.

Verification:

  • New test in generic-binder.test.ts binds an event action with a data binding in its context and asserts rawAction deep-equals the declared action.
  • yarn test in typescript/core/web_core: 1659 passed, 0 failed. @a2ui/react and @a2ui/lit still build.

Fixes #3780

Pre-launch Checklist

One time:

For this PR:

  • I have updated the relevant CHANGELOG.md file.
  • I updated/added relevant documentation.
  • My code changes (if any) have tests.
  • If my branch is on a fork, I have verified that scripts/e2e_test.sh passes.

Hosts and components only receive the `() => Promise<void>` closure for an
action prop, so they cannot tell an event action from a function call
action before invoking it (to show a spinner only for server events, or
for analytics).

Attach the unresolved action to the closure as `rawAction`.

Fixes a2ui-project#3780

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request exposes the unresolved action on action closures as a rawAction property in GenericBinder, allowing hosts to inspect the action before invoking it. A corresponding unit test and changelog entry have been added. The feedback suggests using Object.assign to attach the property to the closure in a cleaner, more type-safe manner instead of using a double type assertion.

};
// Lets hosts inspect the unresolved action (event or function call)
// before invoking it, for example to show a spinner only for server events.
(closure as unknown as Record<string, unknown>)['rawAction'] = value;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using a double type assertion (as unknown as Record<string, unknown>) and string-based property access is less idiomatic in TypeScript. We can use Object.assign to attach the property to the closure in a cleaner, more type-safe manner.

Suggested change
(closure as unknown as Record<string, unknown>)['rawAction'] = value;
Object.assign(closure, {rawAction: value});

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Applied in 381cd63. Thanks.

@github-actions github-actions Bot added the status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs label Nov 8, 2026
@Anoshor

Anoshor commented Nov 12, 2026

Copy link
Copy Markdown
Author

Hi @jacobsimionato, this attaches the raw action to the action closures as rawAction, as proposed in #3780. One thing to decide: rawAction isn't part of the prop's TypeScript type, so a host needs a cast to read it. It's up to date with main and mergeable. Could you take a look when you have time?

@polina-c

polina-c commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

From triage bot, analysis:

For humans

TL;DR
Case: this external PR is a small feature for an issue filed by a team member.
Suggestion: review it and assign jacobsimionato.

Summary:
The PR attaches the unresolved action to the action closures that GenericBinder creates in @a2ui/web_core, as a rawAction property, so that a host can tell an event from a function call before invoking it. It fixes #3780.

Targeted issues:
#3780

Why flagged for triage:
This external PR has no assignee.

Suggestion:
Review the PR and assign jacobsimionato, who filed #3780 and proposed this approach in it. The author asked them for a review on 2026-11-12, with no answer yet. It is a small change with a test: one Object.assign call in bindAction, just before the closure is cached. rawAction is not part of the prop's TypeScript type, so a host needs a cast to read it; the reviewer should decide whether that is acceptable. gspencergoog, who wrote 9 of the 15 commits to generic-binder.ts, is the other choice. #4170 by jacobsimionato also changes bindAction, for v1.0 @action. It already conflicts with main, so this PR adds little to its rebase. The PR merges cleanly with main, and its CI runs wait for maintainer approval. #3780 has no priority label yet.

  1. Add labels: component: core sdk, type: feature/enhancement
  2. Assign: jacobsimionato
  3. Related items: feat(core): dual-read and schema-lessly resolve v1.0 @child, @action, and @functionCall #4170

To adjust the analysis and apply its suggestion, run in your a2ui checkout:

tools/internal/triage/triage_ui.sh https://github.com/a2ui-project/a2ui/pull/4055
For software
<a2ui>
root = TriageAnalysis(
  tldr="""Case: this external PR is a small feature for an issue filed by a team member.
Suggestion: review it and assign `jacobsimionato`.""",
  summary="""The PR attaches the unresolved action to the action closures that `GenericBinder` creates in `@a2ui/web_core`, as a `rawAction` property, so that a host can tell an event from a function call before invoking it. It fixes #3780.""",
  reason="""This external PR has no assignee.""",
  suggestion="""Review the PR and assign `jacobsimionato`, who filed #3780 and proposed this approach in it. The author [asked them](https://github.com/a2ui-project/a2ui/pull/4055#issuecomment-6833006630) for a review on 2026-11-12, with no answer yet. It is a small change with a test: one `Object.assign` call in `bindAction`, just before [the closure is cached](https://github.com/a2ui-project/a2ui/blob/496df0e76e2ad9aba4cc2a12abe066f43d4f171d/typescript/core/web_core/src/resolution/generic-binder.ts#L1444). `rawAction` is not part of the prop's TypeScript type, so a host needs a cast to read it; the reviewer should decide whether that is acceptable. `gspencergoog`, who wrote [9 of the 15 commits](https://github.com/a2ui-project/a2ui/commits/main/typescript/core/web_core/src/resolution/generic-binder.ts) to `generic-binder.ts`, is the other choice. #4170 by `jacobsimionato` also changes `bindAction`, for v1.0 `@action`. It already conflicts with `main`, so this PR adds little to its rebase. The PR merges cleanly with `main`, and its CI runs wait for maintainer approval. #3780 has no priority label yet.""",
  added_labels=["component: core sdk", "type: feature/enhancement"],
  new_assignees=["jacobsimionato"],
  targeted_issues=[3780],
  related_items=[4170]
)
</a2ui>

This analysis is auto-created to help humans to triage this item. Please, do not treat it as a team decision.

🤖 Agent-generated

@polina-c

Copy link
Copy Markdown
Collaborator

Thanks for the PR. Assigning it to jacobsimionato, who proposed this fix in #3780, to decide on it, including whether rawAction needs to be part of the prop's TypeScript type.

@polina-c polina-c added component: core sdk Affects the core SDK layer in any language status: assigned-for-triage issue/pr is assigned to a domain expert for further triage type: feature/enhancement and removed status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs labels Nov 20, 2026
# Conflicts:
#	typescript/core/web_core/CHANGELOG.md
Declare rawAction in the type of an action property instead of leaving it
reachable only through a cast. ActionClosure is the callable the binder
already returned plus an optional rawAction. It is optional so a plain
function, such as a test double, is still assignable to an action property.
@Anoshor

Anoshor commented Nov 21, 2026

Copy link
Copy Markdown
Author

Thanks @jacobsimionato. On the question of whether rawAction belongs in the prop's TypeScript type: I've added it in 04fcfb8. An action property is now typed as an exported ActionClosure, the same callable as before plus rawAction, so a host reads props.onTap?.rawAction without a cast.

I made rawAction optional in the type on purpose. GenericBinder always sets it, but a required member would stop a plain () => Promise<void> from being assignable to an action property, and the existing "Resolved prop types" test (and any hand-built props or test doubles) relies on that. If you'd rather make it required and accept the break, it's a one-word change.

web_core passes 1659 tests, and @a2ui/react and @a2ui/lit still build. It's up to date with main.

# Conflicts:
#	typescript/core/web_core/CHANGELOG.md
@jacobsimionato

Copy link
Copy Markdown
Collaborator

Thank you for your contribution! I'm afraid I looked at #3780 again and I now don't think it's a good idea, for reasons I posted on the issue! So I'll close that issue and this PR.

Sorry to mess you around here!

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

Labels

component: core sdk Affects the core SDK layer in any language status: assigned-for-triage issue/pr is assigned to a domain expert for further triage type: feature/enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[web_core] GenericBinder action closures should expose raw action payload

3 participants