Support Runtime Payloads in Component Events
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- react, typescript
Research direction
The proposal touches the component emit() function, the event dispatcher, and the action parameter resolver, but the payload does not name those files, so locate them first by searching for emit and action binding code. Read how the dispatcher currently runs bindings and resolves params. Done means emit(event, payload) works, $event references resolve per dispatch, and existing emit("press") calls still pass tests. The open questions on $event syntax and sequential versus concurrent execution need maintainer input before coding.
Written by the indexing model from the issue text.
Description
Feature Request: Support Runtime Payloads in Component Events
Summary
Add support for passing runtime payloads when components emit events.
Currently, component events support emitting an event name, for example:
emit("press");
We propose extending this API to support an optional payload:
emit("press", {
id: link.id,
url: link.url,
});
This allows components to send interaction data to the action system without writing that data into the shared state store.
Problem
Today, a component that needs to pass runtime data to an action has no direct way to include that data in its event.
For example, consider a reusable Links component. When a user clicks a link, the component knows which link was clicked.
The generated JSON spec should decide what happens next:
- Open the link in the same tab.
- Open the link in a new tab.
- Track the click.
- Execute multiple actions.
The component should not need to know which actions are available or which actions the agent has selected.
One possible workaround is to write the clicked link data into shared state and then emit the event:
set("/events/linkClick", {
id: link.id,
url: link.url,
});
emit("press");
However, this uses application state as an event transport mechanism. It introduces shared state paths, extra state updates, and possible race conditions when multiple events occur close together.
Proposed API
Extend the event emission API with an optional payload.
type Emit = (
event: string,
payload?: unknown
) => void;
Example:
emit("press", {
id: link.id,
url: link.url,
});
The existing API must continue to work:
emit("press");
The payload should be transient and scoped to the event dispatch. It should not be written to the shared state store automatically.
Proposed JSON API
Allow action parameters to reference the payload of the event that triggered them.
Proposed syntax:
{
"type": "Links",
"props": {
"links": [
{
"id": "docs",
"label": "Documentation",
"url": "https://example.com/docs"
}
]
},
"on": {
"press": [
{
"action": "open_link",
"params": {
"url": {
"$event": "url"
},
"target": "_blank"
}
},
{
"action": "track_click",
"params": {
"linkId": {
"$event": "id"
}
}
}
]
}
}
Note: $event is a proposed syntax, not an existing feature. The issue should consider whether this is the best syntax and whether the entire payload should also be accessible.
Expected Behavior
- A component emits an event with an optional payload.
- The event dispatcher receives both the event name and payload.
- The dispatcher finds the action bindings for that event.
- The action parameter resolver can access the event payload.
- All actions bound to the same event can access the same payload.
- Each event dispatch has its own payload.
- Existing events without payloads continue to work.
Design Requirements
- Keep components generic and independent of application action names.
- Let the JSON spec decide which actions run.
- Support multiple action bindings for one event.
- Support static action parameters alongside dynamic event payload values.
- Do not require components to write temporary interaction data into shared state.
- Keep event payloads scoped to their dispatch.
- Keep the feature framework-agnostic so all supported renderers can use it.
- Preserve existing event behavior and API compatibility.
Important Considerations
Backward compatibility
The payload must be optional. Existing calls to emit("press") must remain valid.
Event isolation
Two events emitted close together must not share or overwrite each other's payload.
Action execution
All action bindings for one event should receive the correct payload. The implementation should define whether multiple actions execute sequentially or concurrently, consistent with the existing dispatcher behavior.
Payload typing
Consider whether the public API should use unknown or a JSON-compatible type such as Record<string, unknown>. The choice should match the library's runtime and serialization constraints.
Validation
Event payloads should be treated as runtime input. Action parameter validation must still apply.
EventHandle API
Review whether the event payload should also be supported by EventHandle.emit() and other event-related APIs, not only the component's emit() function.
Acceptance Criteria
-
emit(event, payload)is supported. -
emit(event)continues to work. - Event payloads are available when resolving action parameters.
- JSON action bindings can reference event payload fields.
- Multiple actions bound to one event can access the same payload.
- Separate event dispatches cannot accidentally share payload data.
- No shared state update is required to transport event data.
- Existing event behavior and
preventDefaultbehavior remain unchanged. - Tests cover payload resolution, multiple actions, missing payloads, and consecutive events.
- Documentation includes a component example and a JSON spec example.
Expected Benefit
This feature provides a clean separation of responsibilities:
- Component: Reports what happened and provides interaction data.
- JSON spec: Decides which actions to execute and how to use the data.
- Action handlers: Execute application behavior.
This makes components more reusable and keeps runtime interaction data separate from persistent application state.
Scope
This issue proposes event payload support. It does not require a new action execution API or changes to the action registry.
The implementation should extend the existing event and action-binding architecture where possible.
- Dominant language
- TypeScript
- Stars
- 20k
- Forks
- 1.1k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 25
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vercel-labs/json-render
-
React Quick Start examples fail at runtime: Renderer must be wrapped in JSONUIProviderPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 1/5 1-3 hours Newbie friendliness 86/100
vercel-labs/json-render#443 ·
Maintainers usually reply within 2 days
-
shadcn Grid/Stack are not responsive (fixed grid-cols-N, no min-w-0)Possibly taken @sushanshakya77 claimed this 67 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
vercel-labs/json-render#355 ·
Maintainers usually reply within 2 days
-
Array path helpers accept malformed RFC 6902 indexesPossibly taken @simonyang08 claimed this 106 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
vercel-labs/json-render#326 ·
Maintainers usually reply within 2 days
-
Support zod 4.4+ — _zod.version.minor type check prevents upgradeMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
vercel-labs/json-render#297 · 2 reactions ·
Maintainers usually reply within 2 days
-
feat: Generic `Spec` type supportPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
vercel-labs/json-render#275 · 1 reaction ·
Maintainers usually reply within 2 days
All issues in vercel-labs/json-render
Similar issues
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/clickhouse-js#1293 ·
Maintainers usually reply within 1 day
-
area: middleware enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
agent/quality testing
Difficulty 1/5 Under an hour Newbie friendliness 95/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
juspay/agent-distro#203 ·
Maintainers usually reply within 1 day