alpinejs/alpine

Bug with Livewire V3 navigate.

WyattCast44 opened this issue · 2 comments

function cloneScriptTag(el) {

Summary:

The cloneScriptTag function is causing a ReferenceError due to the variable attr not being defined in the for...of loop. This bug prevents the function from executing properly when trying to clone script tags, leading to potential issues when dealing with scripts in the HTML document.

Steps to Reproduce:

Navigate to the cloneScriptTag function in the repository.
Attempt to execute the function with a sample script element containing attributes.

Expected Result:

The cloneScriptTag function should execute successfully and return a cloned script element, replicating the attributes and content of the input script element.

Actual Result:

The function throws a ReferenceError, stating that attr is not defined. Consequently, the function fails to perform the cloning operation correctly, leading to unexpected behavior when dealing with script tags in the HTML document.

Fix:

In the cloneScriptTag function, the variable attr used in the for...of loop needs to be explicitly defined using const or let to avoid the ReferenceError. The corrected code is as follows:

function cloneScriptTag(el) {
    let script = document.createElement('script');

    script.textContent = el.textContent;
    script.async = el.async;

    for (let attr of el.attributes) {
        script.setAttribute(attr.name, attr.value);
    }

    return script;
}

Additional Information:

I discovered this bug while trying the Livewire V3 beta, very possible it is due to something in my code - just thought I would create an issue if anyone else is experiencing this as well.

Please let me know if you need any further information or assistance. Congratulations on launching V3! 🎉

Environment:

Operating System: Windows 10
Browser: Google Chrome 114.0.5735.199

Attachments:

Screenshot (258)
Screenshot (259)

@WyattCast44 i'm having the same issue, only when i explicitly build Livewire and Alpine and use @livewireScriptConfig

btw, this should be moved to a discussion, see #1423

Moving this to discussions, thanks @alejandrozepeda