Repository navigation
feat(nuxt3): remove <script setup> transform and prefer top level await - #579
Conversation
7cdca9a to
3cf4f33
Compare
|
Here I ran into a problem on Vite, with the new vue plugin, the SFC in dev now transforms into a single file instead of descriptors with queries. As our transformation needs to be after the vue's compilation, not the explicitly set To solve this:
I have checked the framework/packages/nuxt3/src/app/composables/component.ts Lines 56 to 67 in 3cf4f33 |
|
After a second thought, I guess always apply the transformation makes more sense here.
In the last two commits, I have make the transformation always enabled. |
<script setup> for asyncData<script setup>
|
Thanks for PR @antfu. Some notes:
|
| export function useAsyncData (defaults?: AsyncDataOptions) { | ||
| const nuxt = useNuxtApp() | ||
| const vm = getCurrentInstance() | ||
| const vm = getCurrentNuxtComponentInstance('asyncData') |
There was a problem hiding this comment.
useAsyncData CAN be used without defineNuxtComponent as well! Only promise shortcut (usage without await) needs wrapping :)
There was a problem hiding this comment.
so asyncData has to be in nuxt component, while useAsyncData doesn't right?
There was a problem hiding this comment.
AH, I see. But I guess then we will need to figure out a way to warn users when used with non-await usage without defineNuxtComponent - especially when we are doing API detection and it could be used in the nested composable, in that this will fail silently and leading to a confusing result which could be hard for users to realize that <script setup nuxt> is required. s
There was a problem hiding this comment.
We can check nuxt._pendingPromises at some point before sending a response in development to warn users about pending promises.
There was a problem hiding this comment.
So I guess we will still need to do some transformation to check that for all components but in dev only?
|
Shall we remove the Our website can document both version :) |
93b18e8 to
097db9d
Compare
This reverts commit 164fd57.
|
Another thought: Giving the fact that
We might not actually need this transform in the first place? |
That's a good point! We can instead try to mimic the top-level await with instance preservation for vue 2 (bridge) users :) |
<script setup><script setup> transform and prefer top level await
|
Summary of last commits:
|
<script setup> transform and prefer top level await<script setup> transform and prefer top level await
Resolves nuxt/bridge#101
viteandwebpacktonuxt3usingunplugin.WhenasyncDatais presented in the SFC, thenuxtmodifier could be omitted.<script setup>(see comments below)defineNuxtComponentby avoiding object allocation for the normal components.asyncDatais called outside ofdefineNuxtComponent