Repository navigation
docs: document importing module exports with @JsDefinitionImport - #6799
Conversation
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`).
Preview DeploymentThis PR has been deployed for preview. URL: https://docs-preview-pr-6799.fly.dev Changed pagesAdded content is highlighted in green; removed content is marked in red on each page.
Built from ddd10e3 |
|
@totally-not-ai update the contents based on the latest changes in Flow main branch |
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.
|
@mcollovati Updated the section to match Flow main:
|
vaadin-review-bot
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
📐 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
There was a problem hiding this comment.
Added [role="since:com.vaadin:vaadin@V25.5"] above the heading.
There was a problem hiding this comment.
Around line 24 — could not attach to the exact diff line.
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
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
💬 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
There was a problem hiding this comment.
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.
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
articles/flow/component-internals/element-api/calling-javascript.adoc@JsDefinitionImport: what its attributes map to in a JavaScriptimportstatement, 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 (withJsModuleInvokersas the alternative for code that later calls rely on), the naming rules for imported identifiers, where the annotation applies (includingJsModuleInvokersdefinitions 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 listJsModuleInvokersas the third marker interface.JsModuleInvokersitself is documented in #6805.Auto-generated by the Documentation Bot — review before merging.