cheng-alvin / durian.js

Durian.js is a lightweight Javascript framework that allows for custom HTML tag to create interactive components for large applications! Easy to learn, light and fun to develop with!
MIT License
2 stars 2 forks source link

Issues with `shadowRootEval()` #18

Closed cheng-alvin closed 10 months ago

cheng-alvin commented 10 months ago

Bug report 🐛

After further review and revision of the shadowRootEval() function as in /packages/core/src/shadowRootEval.js and committed in #15, I have found a couple of issues with the function. Here's a list below.

  1. Unable to catch errors - If errors occur during the eval() function, there is no way to catch it without throwing an annoying Uncaught Error to the console.
  2. Closed scope - You cannot access the variables that are outside the same component or in the child component (Nested components or a component declared within another durian component)
  3. Stubborn <script> tag detection - The function could not detect if the script is inside a src attribute that normal people use; the function just simply detects the innerHTML from the HTML document.

Technical information 💻

Here is the function just for reference:

export function shadowRootEval($) {
  $.querySelectorAll("script").forEach((script) => {
    eval(script.innerHTML); // Potential fix? - Alvin <eventide1029@gmail.com>
  });
}

Other sources 📖

cheng-alvin commented 10 months ago

This issue is now fixed in https://github.com/cheng-alvin/durian.js/commit/1ae2942932a6b71abde1ca8ad328763799890b8c of pull request #20! After review and after the checks pass, this would be merged in the next Beta release! Have a great day!

cheng-alvin commented 10 months ago

20 is now closed and this issue has been resolved!