Skip to content
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: add extendComponentMeta #73

Merged
merged 1 commit into from
Oct 29, 2024

Conversation

romhml
Copy link
Contributor

@romhml romhml commented Oct 11, 2024

This is a quick PoC to discuss about the introduction of a extendComponentMeta function to allow users to pass arbitrary objects into component meta data like so:

<script setup>
extendComponentMeta({ hello: 'world' })
</script>

This would allow library authors to pass additional component data to implement devtools more easily.

We might consider implementing a vite plugin to remove the function from the bundle after we parsed it. It might also make more sense to include it in vue-component-meta since this is where most of the parsing is done.

@romhml romhml force-pushed the feat/extend-component-meta branch from 0dbca73 to 8d5109a Compare October 11, 2024 11:47
@farnabaz
Copy link
Collaborator

Thank you @romhml
I'm merging this to test on the package and we can iterate on it in next releases

@farnabaz farnabaz merged commit 52eee5c into nuxtlabs:main Oct 29, 2024
@romhml
Copy link
Contributor Author

romhml commented Oct 29, 2024

I ended up implementing a slightly better version than this here if you want to have a look:
https://github.com/nuxt/ui/pull/2196/files#diff-4795a876424cc5bbc19726d11b6ff10eb6002253ad1d74dea1b1f7b47822e196R37

@adamdehaven
Copy link

Is extendComponentMeta stable enough for a long-term Production project?

I'd like to implement some custom data in components and this is exactly the implementation I'd like to use

@romhml
Copy link
Contributor Author

romhml commented Jan 11, 2025

@adamdehaven This implementation isn’t production-ready. I ended up rewriting it in Nuxt UI for the devtools (here’s the link if you’d like to take a look). To improve stability and parsing, it would be better to leverage Vue's language-tools.

@farnabaz I think we can roll it back for now.

@adamdehaven
Copy link

@romhml I'm using the /api/component-meta endpoint (without a component name) to get all components, then looping through them to provide data to a downstream app.

I'm really just wanting to be able to add a "description" of each component (although it's likely I'll want to add more data over time) from the component itself rather than needing to do a lookup (e.g. in a static map of name => descriptions)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants