Skip to content

feat: support named parameters for executeJs#24386

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

feat: support named parameters for executeJs#24386
Artur- wants to merge 3 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

@cla-assistant
Copy link
Copy Markdown

cla-assistant Bot commented May 20, 2026

CLA assistant check
All committers have signed the CLA.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 20, 2026

Test Results

 1 416 files   -   4   1 416 suites   - 4   1h 17m 53s ⏱️ - 2m 36s
 9 885 tests  - 115   9 807 ✅  - 125  66 💤  - 2  0 ❌ ±0  12 🔥 +12 
10 357 runs   - 115  10 264 ✅  - 139  67 💤  - 2  0 ❌ ±0  26 🔥 +26 

For more details on these errors, see this check.

Results for commit ba38bc1. ± Comparison against base commit 6bad3ec.

♻️ 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
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.
claude added 3 commits May 25, 2026 10:13
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
Mockito.when(page.executeJs(...)).thenReturn(...) now requires
PendingJavaScriptExecution instead of PendingJavaScriptResult since
that's the new return type of executeJs.
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.
@Artur- Artur- force-pushed the claude/fix-vaadin-flow-24385-TESgu branch from 7185220 to ba38bc1 Compare May 25, 2026 10:28
@sonarqubecloud
Copy link
Copy Markdown

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