user_saml icon indicating copy to clipboard operation
user_saml copied to clipboard

SAML Settings not properly initialized due to global jQuery conflicts

Open blizzz opened this issue 5 years ago • 4 comments

Steps to reproduce

  1. Use Nextcloud 20
  2. Have user_saml and, for instance, nextbackup enabled
  3. Go to SAML settings for fresh configuration

Expected behaviour

  • the SAML mode chooser should appear

Actual behaviour

  • only the section title is displayed, otherwise the page is empty

Logs

Browser log

Uncaught TypeError: $(...).tipsy is not a function
    <anonymous> script.js:113
    jQuery 6
    Webpack 6
script.js:113:27

^ script.js refers here to the nextbackup's js file (which should not be injected there anyhows).

A quick solutions is to detangle the initialization from jQuery:

diff --git a/js/admin.js b/js/admin.js
index c932053..0fb1384 100644
--- a/js/admin.js
+++ b/js/admin.js
@@ -117,7 +117,7 @@
    }
 })(OCA);
 
-$(function() {
+var samlInit = function() {
 
    var type = $('#user-saml').data('type');
 
@@ -407,4 +407,23 @@ $(function() {
            nextSibling.slideDown();
        }
    });
-});
+};
+
+function ready(callbackFunc) {
+   if (document.readyState !== 'loading') {
+       // Document is already ready, call the callback directly
+       callbackFunc();
+   } else if (document.addEventListener) {
+       // All modern browsers to register DOMContentLoaded
+       document.addEventListener('DOMContentLoaded', callbackFunc);
+   } else {
+       // Old IE browsers
+       document.attachEvent('onreadystatechange', function() {
+           if (document.readyState === 'complete') {
+               callbackFunc();
+           }
+       });
+   }
+}
+
+ready(samlInit);

the better approach is, of course, to webpack it and stay away from the global $.

blizzz avatar Oct 28 '20 11:10 blizzz

@pbek perhaps you are interested in the nextbackup bits mentioned here

blizzz avatar Oct 28 '20 11:10 blizzz

Thank you, @blizzz. Is that anything that can be reported at https://github.com/pbek/nextbackup and that I can fix?

pbek avatar Oct 28 '20 12:10 pbek

Thank you, @blizzz. Is that anything that can be reported at https://github.com/pbek/nextbackup and that I can fix?

Apparently tipsy is being used, but not available. Best is also to bundle your JS through webpack and not rely what might be there, or not. As for the SAML backend, the global jQuery use was actually deprecated with 19 https://github.com/nextcloud/server/issues/18479.

blizzz avatar Oct 28 '20 12:10 blizzz

Thank you for the heads up.

pbek avatar Oct 28 '20 14:10 pbek