Skip to content

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

Merged
taylorotwell merged 1 commit intolaravel:11.xfrom
jnoordsij:fix-empty-assets
Nov 25, 2024
Merged

[11.x] Fix SyntaxError on Vite prefetch with empty assets#53659
taylorotwell merged 1 commit intolaravel:11.xfrom
jnoordsij:fix-empty-assets

Conversation

@jnoordsij
Copy link
Copy Markdown
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
@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