[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] headerlib: Finally fix the headerlib bug that fused native js modules...

Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <697be53d46cbe_3b183c74158cf@gitlab-sidekiq-low-urgency-cpu-bound-v2-5b89569cd5-hwknq.mail>

Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
e8613e5e by Benoit Grégoire at 2026-01-29T22:45:29+00:00
[FIX] headerlib: Finally fix the headerlib bug that fused native js modules...
---
* [FIX] headerlib: Finally fix the headerlib bug that fused native js modules together.  If you think this broke something, make sure you read the following...
//Modules cannot be fused together in a single script tag, it was a bug.
//By now (2026-01-19 the following slightly adapted message has been pinned at the top of the tiki community chat channel for well over a year,
//and developpers have been warned in MR reviews dozens of times, so there is no excuse for not knowing about this anymore)
/* Important note for all developers regarding javascript modules.
 * I've been baffled by some of the code submitted when migrating dependencies from composer
 * (and no doubt some of you were baffled by my reviews).
 *
 * The cliffnotes;   Code like
 *
 * $headerlib->add_js_module("import { mountApp } from '@vue-sfc-loader';");
 * $headerlib->add_js_module("mountApp('$name', '$file', $data);//rest of code");
 * is not supposed to work.  At all.
 *
 * You are supposed to do
 *
 * $headerlib->add_js_module("import { mountApp } from '@vue-sfc-loader';mountApp('$name', '$file', $data);//rest of code");
 *
 * (off course you'd normally do it with heredoc or nowdoc syntax, the above is just to illustrate)
 *
 * ...
 *
 * I discovered we have a important bug in headerlib, which fuses the modules together.
 * Part of the point of native js modules is to have isolated namespaces.  So this is a bug, not just an implementation detail.
 * As such, it will be fixed in ... and any code like the above that I missed at review will stop working whenever it lands...
*/

See merge request tikiwiki/tiki!9447

- - - - -


1 changed file:

- lib/headerlib.php


Changes:

=====================================
lib/headerlib.php
=====================================
@@ -872,10 +872,37 @@ class HeaderLib
             foreach ($this->js_modules as $x => $js) {
                 $b .= "// js_modules $x \n";
                 foreach ($js as $j) {
-                    $b .= "$j\n";
+                    //Modules cannot be fused together in a single script tag, it was a bug.
+                    //By now (2026-01-19 the following slightly adapted message has been pinned at the top of the tiki community chat channel for well over a year,
+                    //and developpers have been warned in MR reviews dozens of times, so there is no excuse for not knowing about this anymore)
+
+
+                    /* Important note for all developers regarding javascript modules.
+                    * I've been baffled by some of the code submitted when migrating dependencies from composer
+                    * (and no doubt some of you were baffled by my reviews).
+                    *
+                    * The cliffnotes:   Code like
+                    *
+                    * $headerlib->add_js_module("import { mountApp } from '@vue-sfc-loader';");
+                    * $headerlib->add_js_module("mountApp('$name', '$file', $data);//rest of code");
+                    * is not supposed to work.  At all.
+                    *
+                    * You are supposed to do:
+                    *
+                    * $headerlib->add_js_module("import { mountApp } from '@vue-sfc-loader';mountApp('$name', '$file', $data);//rest of code");
+                    *
+                    * (off course you'd normally do it with heredoc or nowdoc syntax, the above is just to illustrate)
+                    *
+                    * ...
+                    *
+                    * I discovered we have a important bug in headerlib, which fuses the modules together.
+                    * Part of the point of native js modules is to have isolated namespaces.  So this is a bug, not just an implementation detail.
+                    * As such, it will be fixed in ... and any code like the above that I missed at review will stop working whenever it lands...
+                    */
+                    $b .= $this->wrap_js("$j\n", true);
                 }
             }
-            $output .= $this->wrap_js($b, true);
+            $output .= $b;
         }
 
         // we get one sorted array with script tags



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/e8613e5e7f8c7c2cf177c1bd49d8b275501c84fc

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/e8613e5e7f8c7c2cf177c1bd49d8b275501c84fc
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.