-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: allow computed properties within useMeta
#255
Conversation
* use like `useMeta(() => ({ title: message.value }))` for computed head * nuxt-community/typescript-template#225 * closes #254
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/nuxt-community/composition-api/hyqyi8bk6 |
@mathe42 I've reverted much of the special handling of |
When null doesn't overwrite the global meta data it's fine. I can't test this in the next 2 weeks |
if (process.client) | ||
watch(Object.values(refs), vm.$meta().refresh, { immediate: true }) | ||
if (init instanceof Function) { | ||
_computedHead.push(computed(init)) |
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.
Is it possible that there is a bug here?
Is it possible that pushing something to computedHead add the computedRef at component level instead of instance level?
I am trying to debug a problem where a meta tag is repeated use the function syntax useMeta(() => ({ ... }))
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.
Have you added the hid
property to deduplicate?
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.
You are right, I am not adding the property hid
, but I think that the property only will hide the problem.
The problem is not related to several components trying to write the same property. I only have one component on the tree trying using useMeta
setup() {
useMeta(() => {
return {
meta: [
{ property: 'og:title', content: 'page title' }
]
}
});
}
The problem I am facing is that every request is adding a new duplicated property (I am doing server-side rendering). So I think that somehow, the state is being stored between each request.
If I print the value _computedHead
here https://github.com/nuxt-community/composition-api/pull/255/files#diff-e0058ab35c645c7435fbc38c50432eabeec5d30d5ad15c4278e083edb897842dR106 I can see that it add a new entry on each request.
I will try to create a minimal reproduction repository.
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.
Here is the repository https://github.com/axelhzf/nuxt-use-meta-bug
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.
Thanks @axelhzf - good catch.
Usage:
In addition to the existing usage for
useMeta
, this adds the possibility to pass a function which will effectively generate a computed head state and be merged with any other head values.nuxt-community/typescript-template#225
closes #254