feat(nuxt): allow useAppConfig with specific key#6776
Conversation
✅ Deploy Preview for nuxt3-docs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
|
/cc @antfu Do you know any better way to resolve it than computed? |
|
One tricky way here is that when using a key, we will need to use |
|
Do you mean |
Indeed both computed and toRef make access harder with |
Co-authored-by: Daniel Roe <daniel@roe.dev>
|
Chaining |
|
TODO: Type support |
| nuxtApp._appConfig = reactive(__appConfig) as AppConfig | ||
| } | ||
| if (key) { | ||
| return reactive(toRef(nuxtApp._appConfig, key)) |
There was a problem hiding this comment.
I suspect this would work. Wrapping a ref with reactive() will return as-is.
I am not very sure about this feature. Kinda babysitting TBH. It's basically the limitation of reactive objects, same as you can't restructure Components' props - stating useAppConfig returns a reactive object should be enough.
I feel the best solution to improve this is the Reactivity Transform and the later vuejs/core#5856
|
With fix in #6788, HMR issue should be solved. Let's revise this idea later. |
🔗 Linked issue
❓ Type of change
📚 Description
Context: #6333
useAppConfigreturns a reactive object but it is super easy to loose reactivity when restructuring it's interface likeconst theme = useAppConfig().themeis not reactive anymore to accept HMR.This PR adds a simple addition using computed for one top-level key.
Todo:
.value📝 Checklist