Replies: 6 comments 3 replies
-
You've hit upon a tricky aspect of how PrimeVue handles its CSS styles, and it's definitely related to how it dynamically injects styles based on component usage. Understanding the Problem: PrimeVue uses a clever technique to only inject the CSS styles needed for components that are actually used in your application. This is a performance optimization, but it creates a few challenges:
Why Your Approach Isn't Working: While hiding components with
Potential Solutions:
Additional Considerations:
Debugging Tips:
Remember: PrimeVue's style injection mechanism is a balance between performance and flexibility. You might need to experiment with different techniques to find the best solution for your specific use case. Let me know if you have any further questions or would like more code examples! |
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply @vieira-brz ! I've tried a lot of the things you have suggested, but to no avail. In the end, the only thing that really worked for me was pre-loading all of the controls that I utilize in my control library, in my main app's App.vue. I just slapped a v-show="false" so that they rendered, but so that they were hidden. For applying the theme dynamically, I force a reload of the page after the user chooses another palette. Kind of lame, but it works. Maybe there's a way to provide/inject some sort of 'theme' service from PrimeVue into my control library, but as of now I haven't found any examples of that. Thanks again! |
Beta Was this translation helpful? Give feedback.
-
@MonkFox I have been stuck with this problem for a couple of hours now... Did you manage to find a real solution? |
Beta Was this translation helpful? Give feedback.
-
@savonbeldi If my component code is local to the dependent project, things work as expected. It's when the components are referenced from the package that styling breaks. Reuseable, custom components integrating PrimeVue components seems pretty logical to me. Reuseable grid toolbars, module/page/section headers, custom DataGrid components with specific behavior and OData protocol, for example. In regard to the styling mechanism, this seems to not be supported out of the box with versions 3.45.0+. If you're able to solve this somehow, I would love to be notified. Thanks |
Beta Was this translation helpful? Give feedback.
-
Hi @MonkFox, Do you use @primevue/nuxt-module? |
Beta Was this translation helpful? Give feedback.
-
Thanks @vieira-brz for the possible solutions provided. I am interested in the solution 1 that you provided, but I didn't get it right yet. My case is similar that the one in the discussion, custom components that use PrimeVue's native components in a separate npm package. The styles are shown well in the Storybook project where the PrimeVue is installed but not in the projects where the npm package is installed. The problem is that all component variables are missing (example We found a very manual workaround, copying all the variables component by component in Storybook, put them in an CSS file and export it along with the library, but there should be a more maintenable way to do it, I opened a discussion about this some months ago, just in case it helps: https://github.com/orgs/primefaces/discussions/2436#discussioncomment-10272692 |
Beta Was this translation helpful? Give feedback.
-
Describe the Issue
I have custom components that utilize PrimeVue's native components in a separate npm package.
The site and the package both reference the same 4.0.0-rc-1 PrimeVue versions (/themes too).
I'm doing this because I have multiple sites that serve different functions, but are used by the same user base, so I want to keep the UI consistent.
I'm running into an issue where if I do not import and render the PrimeVue components hidden (v-show="false") that are used in my separate package in the site's App.vue, then the corresponding PrimeVue's component's <style data-primevue-style-id="[COMPONENTTYPE]-variables"/> are not written to the head tag.
For Example:
I thought that having this in place would work as a hacky work-around, but when I started testing the updatePreset() function that is called subsequently in the ThemeSwitcher.vue, a lot of the semantic css classes are removed and no longer exist (--p-form-field-background for example).
This what I'm seeing when the app is initially loaded:
This is after changing the theme ( calling updatePreset() )
Is there a way to force all of the primitive, sematic and component classes/tokens to be created regardless of actual use in the application?
Or is there something I'm doing incorrectly when using my wrapper components from a npm package?
PrimeVue version
4.0.0-rc-1
Language
Vue/Typescript
Build / Runtime
Vite
Beta Was this translation helpful? Give feedback.
All reactions