Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checks on component setup to avoid runtime errors #246

Open
bombillazo opened this issue Jun 9, 2023 · 2 comments
Open

Add checks on component setup to avoid runtime errors #246

bombillazo opened this issue Jun 9, 2023 · 2 comments

Comments

@bombillazo
Copy link

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

Sometimes the component failed to load since not all conditions to handle the component are met. These changes add checks to avoid runtime errors.

Here is the diff that solved my problem:

diff --git a/node_modules/nprogress/nprogress.js b/node_modules/nprogress/nprogress.js
index b23b300..d99e2d6 100644
--- a/node_modules/nprogress/nprogress.js
+++ b/node_modules/nprogress/nprogress.js
@@ -240,11 +240,14 @@
       spinner && removeElement(spinner);
     }
 
+    if(!parent){
+      parent   = document.querySelector('body')
+    }
+
     if (parent != document.body) {
       addClass(parent, 'nprogress-custom-parent');
     }
-
-    parent.appendChild(progress);
+    parent?.appendChild(progress);
     return progress;
   };
 
@@ -433,7 +436,8 @@
     if (hasClass(oldList, name)) return; 
 
     // Trim the opening space.
-    element.className = newList.substring(1);
+    if(element)
+      element.className = newList.substring(1);
   }
 
   /**
@@ -460,7 +464,7 @@
    */
 
   function classList(element) {
-    return (' ' + (element.className || '') + ' ').replace(/\s+/gi, ' ');
+    return (' ' + (element?.className || '') + ' ').replace(/\s+/gi, ' ');
   }
 
   /**

This issue body was partially generated by patch-package.

@bombillazo
Copy link
Author

@rstacruz Hey there, any chance this can be merge to fix the runtime bugs?

@bombillazo
Copy link
Author

Im also willing to help out as maintainer if you're too busy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant