Skip to content

docs: document importing module exports with @JsDefinitionImport - #6799

Merged
mcollovati merged 7 commits into
mainfrom
doc-bot/vaadin-flow/27457-1c43e60f1cb1d85d
Dec 1, 2026
Merged

mcollovati merged 7 commits into
mainfrom
doc-bot/vaadin-flow/27457-1c43e60f1cb1d85d

Conversation

@vaadin-bot

@vaadin-bot vaadin-bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Documentation for vaadin/flow#27457 by @totally-not-ai[bot].

Note

The source pull request is merged, so this documentation describes the final
shape of the change. Please review it and mark it ready for review.

Change categories: NEW_FEATURE, API_CHANGE

File Change
articles/flow/component-internals/element-api/calling-javascript.adoc Added an "Importing Module Exports" section documenting @JsDefinitionImport: what its attributes map to in a JavaScript import statement, how default and named exports are reached, module path resolution and the build failure for a missing ./ module, when the module loads and the call-ordering consequence (with JsModuleInvokers as the alternative for code that later calls rely on), the naming rules for imported identifiers, where the annotation applies (including JsModuleInvokers definitions and their nameless import), and the cases that are refused or stop the build (no own methods, JsSnippets, @JsStringFallback, a class). It includes an example of how imports work with inherited methods. The section intro and the snippets paragraph now list JsModuleInvokers as the third marker interface. JsModuleInvokers itself is documented in #6805.

Auto-generated by the Documentation Bot — review before merging.

Generated by Documentation Bot for #27457 · agent · 78.6 AIC · ⊞ 11.7K · ◷

  • expires on Dec 27, 2026, 4:35 PM UTC

Add a section to Calling JavaScript from the Server describing how
@JsDefinitionImport gives a declared expression names from a
JavaScript module to call, how the attributes map to an import
statement, when the module loads, and what the annotation refuses.

Documents vaadin/flow#27457 (`f0734b28bcf099843b280ec37237080b2a3226d8`).
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Preview Deployment

This PR has been deployed for preview.

URL: https://docs-preview-pr-6799.fly.dev

Changed pages

Added content is highlighted in green; removed content is marked in red on each page.

Built from ddd10e3

@mcollovati

Copy link
Copy Markdown
Contributor

@totally-not-ai update the contents based on the latest changes in Flow main branch

@mcollovati mcollovati added the flow label Dec 1, 2026
A missing ./ module and the annotation on a class now stop the build,
the annotation is refused with @JsStringFallback and also applies to
JsModuleInvokers definitions. Replace the connector example, now better
served by JsModuleInvokers, with a named-export example, and drop the
note about expressions shadowing an import, which Flow no longer
documents.
@totally-not-ai

totally-not-ai Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@mcollovati Updated the section to match Flow main:

  • A missing ./ module now stops the build with an error naming the interface, methods and module. npm packages aren't checked in advance.
  • @JsDefinitionImport on a class now stops the build instead of being logged. An optimized production build checks only the classes the app reaches.
  • The annotation is also refused with @JsStringFallback. It applies to JsModuleInvokers definitions too, where a nameless import names the module used as this.
  • Added how default and named exports are reached, and that a @JsModule on the same interface still loads eagerly.
  • The call-ordering paragraph now points to JsModuleInvokers for code that later calls rely on. So the example now imports a named export instead of a connector.
  • Dropped the note about an expression's let/const hiding an import, since the Javadoc no longer describes it.

JsModuleInvokers itself is documented in #6805. That's why it's only mentioned here without a link: its anchor doesn't exist until that PR merges.

@mcollovati
mcollovati marked this pull request as ready for review December 1, 2026 17:15

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed the changes — left 3 comments.

Finding
📐 The new section documents a 25.5 feature inside a section badged as 25.4, with no since badge of its own
⚠️ The page still says a definition extends "one of two marker interfaces", but the new section names a third
💬 The page recommends JsModuleInvokers but never explains it or links anywhere

When the JavaScript isn't about a particular element, declare it the same way and run it through [methodname]`Page.executeJs(Class)`, which works with global browser APIs instead of with an element (see <</flow/advanced/browser-access#declaring-javascript-in-java,Accessing the Browser Page>>). There, every method needs [annotationname]`@JsExpression`, since there's no element whose JavaScript function could be called.

[[importing-module-exports]]
=== Importing Module Exports

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 The new section documents a 25.5 feature inside a section badged as 25.4, with no since badge of its own

@JsDefinitionImport carries @since 25.5 in Flow (flow-server/src/main/java/com/vaadin/flow/js/JsDefinitionImport.java:117), while this repository pins 25.4.0-beta4 in pom.xml and the enclosing == Declaring JavaScript in Java section is marked [role="since:com.vaadin:vaadin@V25.4"] (line 21), matching the @since 25.4 of JsDefinition, JsInvokers and JsExpression.

A reader on 25.4 therefore takes @JsDefinitionImport to be available and gets a compile error. CONVENTIONS.md:82 requires the badge: "Do not write Vaadin version numbers in text. Mark new features with a since badge instead: the [role="since:com.vaadin:vaadin@V25.2"] attribute above a section heading."

Add [role="since:com.vaadin:vaadin@V25.5"] above the heading.

calling-javascript.adoc:138 · conventions

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.

Added [role="since:com.vaadin:vaadin@V25.5"] above the heading.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Around line 24 — could not attach to the exact diff line.

⚠️ The page still says a definition extends "one of two marker interfaces", but the new section names a third

Line 24 reads: "It also extends one of two marker interfaces, which decides what its methods declare: [interfacename]JsInvokers … or [interfacename]JsSnippets … An interface can't extend both."

The new section names JsModuleInvokers as a definition marker four times. JsDefinition's Javadoc lists three markers: JsInvokers, JsModuleInvokers and JsSnippets (flow-server/src/main/java/com/vaadin/flow/js/JsDefinition.java:41-47). As it stands, the page contradicts itself a few paragraphs apart.

Update line 24 to name all three markers.

calling-javascript.adoc:24 · accuracy

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.

The intro now lists JsModuleInvokers alongside JsInvokers and JsSnippets, and so does the snippets paragraph that said "exactly one of". Both mentions are wrapped in inline 25.5 badges.


The annotation can be repeated, and several annotations that name the same module load it as one module. The imports belong to the interface that declares them: a method inherited from another interface sees the imports of the interface that declares the method, not those of the interface it's called through.

The module is loaded the first time a method of the declaring interface is called, not when the application starts, so a module that only some views need doesn't slow the others down; later calls reuse the loaded module. A [annotationname]`@JsModule` on the same interface is still loaded eagerly. Because the call waits for its modules, even ones already loaded, its JavaScript runs after the JavaScript of the calls that follow it in the same round trip, rather than in call order, and two calls that import different modules may run in either order. When a later call depends on what this one does, make it from the result of this one, for example by returning [classname]`PendingJavaScriptResult` and making the next call in its handler. Code that later calls rely on, such as the connector that a component sets up, is better called through an interface that extends [interfacename]`JsModuleInvokers`, whose modules are loaded with the view.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💬 The page recommends JsModuleInvokers but never explains it or links anywhere

"Code that later calls rely on, such as the connector that a component sets up, is better called through an interface that extends [interfacename]JsModuleInvokers, whose modules are loaded with the view."

JsModuleInvokers and Page.executeModuleJs() appear nowhere else in articles/. A reader who accepts the recommendation has no way to act on it: the page never says that the instance comes from Page.executeModuleJs(Class), nor that the interface needs exactly one nameless @JsDefinitionImport per declaring interface.

The PR description says JsModuleInvokers is documented in a separate pull request. If this one can merge first, add a short forward link or hold them together.

calling-javascript.adoc:165 · clarity

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.

The recommendation now says how to act on it: call it through Page.executeModuleJs(Class), and name the module with a @JsDefinitionImport that imports no names. The full section is in #6805. I left out a cross-reference because its anchor doesn't exist until #6805 merges, and a link now would be broken. Whichever of the two PRs merges second can add the link.

… 25.5 badge

Also name JsModuleInvokers as the third definition marker where the
page still listed only two.
…in 25.4

Both were backported to Flow 25.4, so the 25.4 badge of the enclosing
Declaring JavaScript in Java section already covers them.
@mcollovati
mcollovati merged commit 4ddd6fb into main Dec 1, 2026
10 of 11 checks passed
@mcollovati
mcollovati deleted the doc-bot/vaadin-flow/27457-1c43e60f1cb1d85d branch December 1, 2026 17:44
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.

3 participants