-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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 <[email protected]>
Chaining |
TODO: Type support |
const nuxtApp = useNuxtApp() | ||
if (!nuxtApp._appConfig) { | ||
nuxtApp._appConfig = reactive(__appConfig) as AppConfig | ||
} | ||
if (key) { | ||
return reactive(toRef(nuxtApp._appConfig, key)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
useAppConfig
returns a reactive object but it is super easy to loose reactivity when restructuring it's interface likeconst theme = useAppConfig().theme
is not reactive anymore to accept HMR.This PR adds a simple addition using computed for one top-level key.
Todo:
.value
π Checklist