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

[11.x] Fix SyntaxError on Vite prefetch with empty assets #53659

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

jnoordsij
Copy link
Contributor

When $assets is empty and the 'aggressive' strategy is applied in the Vite prefetcher, the resulting JS includes the fragment:

        const fragment = new DocumentFragment
        [].forEach((asset) => fragment.append(makeLink(asset)))
        document.head.append(fragment)

When executed this yields an error Uncaught SyntaxError: expected expression, got ']'. Although not hurtful (there is nothing to do anyways), it is still a slight nuisance.

This MR fixes the issue by adding a semicolon to eagerly terminate the previous statement. An alternative way would be to rewrite the entire statement to not write any html at all when $assets is empty, given that there is nothing to do.

@taylorotwell taylorotwell merged commit cee8695 into laravel:11.x Nov 25, 2024
40 checks passed
@jnoordsij jnoordsij deleted the fix-empty-assets branch November 25, 2024 15:33
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

Successfully merging this pull request may close these issues.

2 participants