Do not interact with `require()` while `define.amd` is unset
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 12 Apr 2023 08:20:56 +0000 (10:20 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 12 Apr 2023 08:20:56 +0000 (10:20 +0200)
During development I noticed that regularly `focus-trap` failed to load
properly, likely due to being pulled in by some module while `define.amd` was
unset and thus failing to register itself as a module due to the UMD header.

Fix this by moving the `define.amd` unsetting and resetting into dedicated
`<script>` tags that wrap jQuery + WCF.js and nothing else.

com.woltlab.wcf/templates/headIncludeJavaScript.tpl

index 82909cd344641e64c31444afea9f3f9191819c35..484c279f50174a98ce66529c02d0d849ddfadc1c 100644 (file)
@@ -101,10 +101,6 @@ window.addEventListener('pageshow', function(event) {
                        styleChanger: {if $__wcf->getStyleHandler()->showStyleChanger()}true{else}false{/if}
                });
        });
-       
-       // prevent jQuery and other libraries from utilizing define()
-       __require_define_amd = define.amd;
-       define.amd = undefined;
 </script>
 
 {include file='__devtoolsLanguageChooser'}
@@ -115,17 +111,23 @@ window.addEventListener('pageshow', function(event) {
 </script>
 {/if}
 
+<script data-relocate="true">
+       // prevent jQuery and other libraries from utilizing define()
+       __require_define_amd = define.amd;
+       define.amd = undefined;
+</script>
 {js application='wcf' lib='jquery' hasTiny=true}
 {js application='wcf' lib='jquery-ui' hasTiny=true}
 {js application='wcf' lib='jquery-ui' file='touchPunch' bundle='WCF.Combined' hasTiny=true}
 {js application='wcf' lib='jquery-ui' file='nestedSortable' bundle='WCF.Combined' hasTiny=true}
 {js application='wcf' file='WCF.Assets' bundle='WCF.Combined' hasTiny=true}
 {js application='wcf' file='WCF' bundle='WCF.Combined' hasTiny=true}
-
 <script data-relocate="true">
        define.amd = __require_define_amd;
        $.holdReady(true);
-       
+</script>
+
+<script data-relocate="true">
        WCF.User.init(
                {@$__wcf->user->userID},
                {if $__wcf->user->userID}'{@$__wcf->user->username|encodeJS}'{else}''{/if}