Skip to content

feat: support named parameters for executeJs#24386

Draft
Artur- wants to merge 4 commits into
mainfrom
claude/fix-vaadin-flow-24385-TESgu
Draft

feat: support named parameters for executeJs#24386
Artur- wants to merge 4 commits into
mainfrom
claude/fix-vaadin-flow-24385-TESgu

Conversation

@Artur-
Copy link
Copy Markdown
Member

@Artur- Artur- commented May 20, 2026

Add withParameter(name, value) to a new PendingJavaScriptExecution
subtype returned from Element.executeJs and Page.executeJs, so the
JavaScript expression can read values by name instead of $0, $1,
…:

element.executeJs("doSomething(foo)")
        .withParameter("foo", "Some value");

The mechanism is purely server-side: each withParameter call appends
the value to the invocation's parameter list and prepends
let <name>=$N; to the expression. Positional $0/$1/... parameters
keep their meaning, and parameters cannot be added after the execution
has been sent to the browser. The same withParameter(name, value)
helper is added to JsFunction, where it captures the value and aliases
it in the body the same way.

callJsFunction keeps returning PendingJavaScriptResult so it
doesn't expose withParameter, matching the issue's request to scope
the feature to executeJs only.

Fixes #24385

Add `withParameter(name, value)` to a new `PendingJavaScriptExecution`
subtype returned from `Element.executeJs` and `Page.executeJs`, so the
JavaScript expression can read values by name instead of `$0`, `$1`,
&hellip;:

    element.executeJs("doSomething(foo)")
            .withParameter("foo", "Some value");

The mechanism is purely server-side: each `withParameter` call appends
the value to the invocation's parameter list and prepends
`let <name>=$N;` to the expression. Positional `$0`/`$1`/... parameters
keep their meaning, and parameters cannot be added after the execution
has been sent to the browser. The same `withParameter(name, value)`
helper is added to `JsFunction`, where it captures the value and aliases
it in the body the same way.

`callJsFunction` keeps returning `PendingJavaScriptResult` so it
doesn't expose `withParameter`, matching the issue's request to scope
the feature to `executeJs` only.

Fixes #24385
@cla-assistant
Copy link
Copy Markdown

cla-assistant Bot commented May 20, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ Artur-
❌ claude
You have signed the CLA already but the status is still pending? Let us recheck it.

Mockito.when(page.executeJs(...)).thenReturn(...) now requires
PendingJavaScriptExecution instead of PendingJavaScriptResult since
that's the new return type of executeJs.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 20, 2026

Test Results

 1 407 files   -   4   1 407 suites   - 4   1h 15m 44s ⏱️ - 3m 9s
 9 842 tests  - 115   9 763 ✅  - 125  67 💤  - 2  0 ❌ ±0  12 🔥 +12 
10 317 runs   - 115  10 222 ✅  - 139  69 💤  - 2  0 ❌ ±0  26 🔥 +26 

For more details on these errors, see this check.

Results for commit 7185220. ± Comparison against base commit f3c71b4.

♻️ This comment has been updated with latest results.

@Artur- Artur- marked this pull request as draft May 20, 2026 11:14
Comment thread flow-server/src/main/java/com/vaadin/flow/dom/JsFunction.java Outdated
Validation runs again when the invocation is serialised via JacksonCodec,
so the explicit dry-run on every withParameter / addNamedParameter call
just doubles the work without adding signal.
@sonarqubecloud
Copy link
Copy Markdown

Artur- added a commit that referenced this pull request May 20, 2026
Lead the keydown handler body and the listenOn delegate registration JS
with `const name = $N;` lines, so the rest of each body reads in terms
of `allowedKeys`, `requiredModifiers`, `resetFocus`, `preventDefault`
and `locator`, `handler`, `locatorSource` instead of `$0`..`$4`. Once
PR #24386 (issue #24385) lands these aliases can be replaced by
`JsFunction.withParameter(name, value)` directly.
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.

Support named parameters for executeJs.

2 participants