Skip to content

feat: run framework helpers through declared JavaScript - #26858

Merged
mcollovati merged 10 commits into
mainfrom
feat/declared-js-context-call-sites
Nov 5, 2026
Merged

mcollovati merged 10 commits into
mainfrom
feat/declared-js-context-call-sites

Conversation

@totally-not-ai

@totally-not-ai totally-not-ai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Review risk: two-way door — Page.open/setLocation, attaching existing elements and polymer template model sync move to declared JavaScript; if wrong, those features break in the browser, and reverting restores the string expressions.

Part of #26698
Depends on #26857

Summary

The last framework call sites that sent string expressions because they need client-side helpers now use declared JavaScript with the execution context added in #26857. They therefore work under a content security policy without unsafe-eval, and what runs in the browser is the same as before.

What changed

  • Page.open(…), openUnsafe(…) and setLocation(…) run Page.NavigationJs.open(url, windowName). It still dispatches vaadin-redirect-pending, calls $executionContext.stopApplication() for _self, and then calls window.open. NavigationJs is a new nested interface marked internal-only, kept apart from the public PageJs because it does not check the URL itself.
  • AbstractNodeStateProvider.attachExistingElement runs AttachExistingElementJs.attachExistingElement(parent, previousSibling, tagName, id). The parent can be an element or a shadow root.
  • AbstractTemplate (flow-polymer-template) runs TemplateModelJs.registerUpdatableModelProperties / populateModelProperties.
  • Each expression is the old one with this. replaced by $executionContext.. The deferral until nodes are bound and the call order are unchanged.
  • Behavior note: like every declared function, these are generated as async functions. An exception thrown inside one, with no result subscriber, now shows up as an unhandled promise rejection instead of being reported through the client console logger. Timing does not change: none of the bodies awaits.

Test summary

  • Server tests now check the queued declared calls (definition, method and arguments) for setLocation, open, openUnsafe, attaching an existing element, and template model registration/population. They also check that an unsafe URL queues nothing.
  • Ran the integration tests for these paths locally, all green: PageIT (test-default), and AttachExistingElementIT, AttachExistingElementByIdIT, UpdatableModelPropertiesIT and PolymerModelPropertiesIT (test-root-context). The generated bundle contained the new functions in the context registry.

API Changes

// com.vaadin.flow.component.page.Page.NavigationJs — Added (internal use only)
public interface NavigationJs extends Serializable
void open(String url, String windowName)

// com.vaadin.flow.dom.impl.AbstractNodeStateProvider.AttachExistingElementJs — Added (internal use only)
public interface AttachExistingElementJs extends Serializable
void attachExistingElement(Node<?> parent, Element previousSibling, String tagName, int id)

// com.vaadin.flow.component.polymertemplate.AbstractTemplate.TemplateModelJs — Added (internal use only)
public interface TemplateModelJs extends Serializable
void registerUpdatableModelProperties(Element template, ArrayNode properties)
void populateModelProperties(Element template, ArrayNode properties)

Fixes #26698

Declared JavaScript runs against the element and has no way to reach the
callbacks that an executeJs expression gets through its context object,
such as stopApplication or the element to state node mapping. Framework
code that needs them can therefore not move off string expressions.

A @JsDefinition method annotated with the internal
@JsWithExecutionContext is generated into a separate bundle registry as a
function taking that context as its first parameter, executionContext,
while `this` stays the element. The client passes the context only to
functions found in that registry, and the marker is part of the function
id.

Part of #26698
Page.open/setLocation, attaching an existing element and the polymer
template model sync no longer send string expressions. They are
declared @JsExpression methods marked with @JsWithExecutionContext, so
they reach the same helpers through executionContext and work under a
content security policy without unsafe-eval.

Part of #26698
@totally-not-ai

totally-not-ai Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Fixed the reported issues in PageTest. The open/setLocation tests and the createUI helper no longer declare a local ui that hides the field, and each assertThrows lambda now makes a single call on a Page taken beforehand instead of chaining getPage() inside it. No behavior change, and PageTest passes (26 tests).

@mcollovati
mcollovati marked this pull request as ready for review November 5, 2026 14:29
@mcollovati mcollovati added the csp label Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

 1 675 files  ±0   1 761 suites  ±0   2h 18m 55s ⏱️ + 8m 49s
13 244 tests  - 1  13 176 ✅  - 1  68 💤 ±0  0 ❌ ±0 
13 878 runs   - 1  13 810 ✅  - 1  68 💤 ±0  0 ❌ ±0 

Results for commit d3733e9. ± Comparison against base commit 9a67a81.

♻️ This comment has been updated with latest results.

Base automatically changed from feat/declared-js-execution-context to main November 5, 2026 17:05
@mcollovati
mcollovati requested review from vaadin-review-bot and removed request for vaadin-review-bot November 5, 2026 17:07

@vaadin-review-bot vaadin-review-bot left a comment

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.

✅ Nothing to flag — the changes look good.

@mcollovati
mcollovati enabled auto-merge November 5, 2026 17:21
@sonarqubecloud

sonarqubecloud Bot commented Nov 5, 2026

Copy link
Copy Markdown

@mcollovati
mcollovati added this pull request to the merge queue Nov 5, 2026
Merged via the queue into main with commit 55a221e Nov 5, 2026
53 checks passed
@mcollovati
mcollovati deleted the feat/declared-js-context-call-sites branch November 5, 2026 18:02
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Documentation Bot: No documentation needed for this change.

The change moves three framework-internal call sites (Page.open/setLocation, attaching an existing element, and polymer template model sync) from string-based executeJs calls to the declared-JavaScript mechanism, so they work under a content security policy without unsafe-eval. The three new interfaces this introduces are explicitly internal-only, and the JavaScript that runs in the browser, and the public API surface a reader interacts with, are unchanged.

Nothing was opened in vaadin/docs. If you disagree, the change has to be documented by hand there.

Generated by Documentation Bot for #26858 · agent · 69.1 AIC · ⊞ 11.7K · ◷

@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with Vaadin 25.4.0-alpha6.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make context-dependent executeJs call sites work as declared JavaScript

3 participants