@@ -8,10 +8,14 @@ if (process.env.NODE_ENV !== 'production') {
8
8
require ( 'preact/debug' ) ;
9
9
}
10
10
11
- // Register & add the debug web component, tagName and attributes are automatically read from the component
12
- register ( App , null , null , App . options ) ;
11
+ function initializeApp ( ) {
12
+ // Prevent registering the custom element twice
13
+ if ( window [ 'SHEL_NEOS_COMMANDBAR_INITIALIZED' ] ) return ;
14
+ window [ 'SHEL_NEOS_COMMANDBAR_INITIALIZED' ] = true ;
15
+
16
+ // Register & add the debug web component, tagName and attributes are automatically read from the component
17
+ register ( App , null , null , App . options ) ;
13
18
14
- window . addEventListener ( 'neoscms-i18n-initialized' , ( ) => {
15
19
// Get the top bar left container and create a custom element to render the command bar into
16
20
const topBarLeft = document . querySelector ( '.neos-top-bar-left' ) ;
17
21
const pluginContainer = document . createElement ( 'command-bar-container' ) ;
@@ -24,4 +28,11 @@ window.addEventListener('neoscms-i18n-initialized', () => {
24
28
pluginContainer . setAttribute ( 'styleuri' , commandBarStyleTag . href ) ;
25
29
26
30
topBarLeft . appendChild ( pluginContainer ) ;
27
- } ) ;
31
+ }
32
+
33
+ // If the api is already initialized, initialize the app as the event listener wouldn't be called anymore
34
+ if ( window . NeosCMS ?. I18n ?. initialized ) {
35
+ initializeApp ( ) ;
36
+ } else {
37
+ window . addEventListener ( 'neoscms-i18n-initialized' , initializeApp ) ;
38
+ }
0 commit comments