nuxt / scripts

Plug-and-play script optimization for Nuxt applications. (Public Preview)
https://scripts.nuxt.com
MIT License
134 stars 9 forks source link

Detect & Warn Top Level Await Brick #46

Closed harlan-zw closed 1 day ago

harlan-zw commented 1 month ago

The following code will potentially brick Vue component as the await won't be resolved until the script loads and the script can't load until the trigger is fired (which relies on the component being mounted in most cases).

<script setup>
const { $script } = useScript('..')

await $script.load()
// or await $script
</script>
danielroe commented 1 month ago

Could we implement this as an eslint rule? (cc: @antfu)

antfu commented 1 month ago

I don't have the context, but is that saying that users should not await for $script coming from useScript? Should we provide auto-fix/suggestions as well?