This is an automated email from the ASF dual-hosted git repository.
thiagohp pushed a commit to branch feature/requirejs-less
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git
The following commit(s) were added to refs/heads/feature/requirejs-less by this
push:
new 4f1e2f759 TAP5-2810: fixing ES modules imports with function calls in
AJAX request
4f1e2f759 is described below
commit 4f1e2f75984027b6607f3ab33bfc314c6926f3d6
Author: Thiago H. de Paula Figueiredo <[email protected]>
AuthorDate: Tue Jul 29 07:23:11 2025 -0300
TAP5-2810: fixing ES modules imports with function calls in AJAX request
---
.../internal/services/EsModuleInitsManager.java | 13 ++++----
.../services/PartialMarkupDocumentLinker.java | 2 +-
.../src/main/typescript/src/t5/core/pageinit.ts | 35 ++++++++++++++++------
.../assets/es-modules/app/multi-zone-update.js | 5 ++++
4 files changed, 40 insertions(+), 15 deletions(-)
diff --git
a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EsModuleInitsManager.java
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EsModuleInitsManager.java
index 04f3a2a67..96a01f1d0 100644
---
a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EsModuleInitsManager.java
+++
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EsModuleInitsManager.java
@@ -76,14 +76,17 @@ public class EsModuleInitsManager
{
final EsModuleInitializationImpl initImpl =
(EsModuleInitializationImpl) init;
final JSONArray arguments = initImpl.getArguments();
+ final JSONArray initArray = new JSONArray();
+
+ initArray.add(initImpl.getModuleName());
+
if (arguments != null)
{
- list.add(new JSONArray(initImpl.getModuleName(),
arguments));
- }
- else
- {
- list.add(new JSONArray().put(initImpl.getModuleName()));
+ initArray.addAll(arguments);
}
+
+ list.add(initArray);
+
}
}
else
diff --git
a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PartialMarkupDocumentLinker.java
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PartialMarkupDocumentLinker.java
index ae0614459..7cd6a770a 100644
---
a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PartialMarkupDocumentLinker.java
+++
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PartialMarkupDocumentLinker.java
@@ -116,7 +116,7 @@ public class PartialMarkupDocumentLinker implements
DocumentLinker
List<Object> allInits = new ArrayList<>(inits.size() +
esModuleInits.size());
allInits.addAll(inits);
allInits.addAll(esModuleInits);
- reply.in(InternalConstants.PARTIAL_KEY).put("inits",
JSONArray.from(inits));
+ reply.in(InternalConstants.PARTIAL_KEY).put("inits",
JSONArray.from(allInits));
}
}
diff --git a/tapestry-core/src/main/typescript/src/t5/core/pageinit.ts
b/tapestry-core/src/main/typescript/src/t5/core/pageinit.ts
index 197af3680..85d13124c 100644
--- a/tapestry-core/src/main/typescript/src/t5/core/pageinit.ts
+++ b/tapestry-core/src/main/typescript/src/t5/core/pageinit.ts
@@ -111,15 +111,8 @@ const addStylesheets = function(newStylesheets:
StylesheetLink) {
const invokeInitializer = function(tracker: () => any, qualifiedName: string,
initArguments: any[]) {
const [moduleName, functionName] = Array.from(qualifiedName.split(':'));
- // @ts-ignore
- return require([moduleName], function(moduleLib: any) {
+ function executeInitializer(moduleLib: any) {
- // If it's an AMD module generated by TypeScript and it has a default
export,
- // it gets wrapped, so we try to unwrap it here.
- if (moduleLib != null && moduleLib.__esModule && moduleLib["default"] !=
null) {
- moduleLib = moduleLib["default"];
- }
-
try {
// Some modules export nothing but do some full-page initialization,
such as adding
// event handlers to the body.
@@ -153,7 +146,31 @@ const invokeInitializer = function(tracker: () => any,
qualifiedName: string, in
} finally {
tracker();
}
- });
+
+ }
+
+ if (requireJsEnabled) {
+
+ // @ts-ignore
+ return require([moduleName], function(moduleLib: any) {
+
+ // If it's an AMD module generated by TypeScript and it has a default
export,
+ // it gets wrapped, so we try to unwrap it here.
+ if (moduleLib != null && moduleLib.__esModule && moduleLib["default"] !=
null) {
+ moduleLib = moduleLib["default"];
+ }
+
+ return executeInitializer(moduleLib);
+
+ });
+
+ } else {
+
+ return import(moduleName).then(function(moduleLib: any) {
+ return executeInitializer(moduleLib['default']);
+ });
+
+ }
};
// Pre-loads a number of libraries in order. When the last library is loaded,
diff --git
a/tapestry-core/src/test/resources/META-INF/assets/es-modules/app/multi-zone-update.js
b/tapestry-core/src/test/resources/META-INF/assets/es-modules/app/multi-zone-update.js
new file mode 100644
index 000000000..411363128
--- /dev/null
+++
b/tapestry-core/src/test/resources/META-INF/assets/es-modules/app/multi-zone-update.js
@@ -0,0 +1,5 @@
+import dom from "t5/core/dom";
+
+export default function (id, message) {
+ dom(id).update(message);
+};
\ No newline at end of file