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

No styles injected on SSR resulting in Large Layout Shifts on load #4210

Closed
Gerrproger opened this issue Jul 27, 2023 · 14 comments
Closed

No styles injected on SSR resulting in Large Layout Shifts on load #4210

Gerrproger opened this issue Jul 27, 2023 · 14 comments
Assignees
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Milestone

Comments

@Gerrproger
Copy link

Gerrproger commented Jul 27, 2023

Describe the bug

So guys, you are not considering SSR at all.
There is an issue opened almost a year ago #3070 and successfully ignored by @tugcekucukoglu.

I was able to work around this by importing components like import Button from 'primevue/button/Button.vue'; instead of import Button from 'primevue/button';.
But since v3.30.0 you removed <style> from vue files and introduced useStyle() which does not apply styles on SSR at all:

const defaultDocument = DomHandler.isClient() ? window.document : undefined;

So now there is no way to inject component styles during SSR.

I hope you will not just close this issue like was done to #4184.

Reproducer

https://stackblitz.com/edit/nuxt-starter-fz1hbf?file=app.vue

PrimeVue version

3.x.x

Vue version

3.x

Language

TypeScript

Build / Runtime

Nuxt

Browser(s)

All

Steps to reproduce the behavior

  1. Install Nuxt
  2. Create Nuxt plugin as described in https://github.com/primefaces/primevue#nuxt-integration
  3. Enabled SSR
  4. Watch Primevue styles being injected only after hydration

Expected behavior

Primevue styles being injected during SSR.

@Gerrproger Gerrproger added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Jul 27, 2023
@chris-paganon
Copy link

I have exactly the same issue here while deploying to Cloudfare pages in SSG. The only solution I found was to add a loader on top of the content until everything is mounted. But that kind of defeats the purpose of SSR and SSG.

I came to the same conclusion that styles loaded with useStyles were the issue.

@tugcekucukoglu
Copy link
Member

Please try to use the latest PrimeVue and Nuxt version.

If problem still persists, please create a reproducer link using this example: https://stackblitz.com/edit/nuxt-starter-zhqkh9?file=plugins%2Fprimevue.js,nuxt.config.ts,app.vue

@tugcekucukoglu tugcekucukoglu added Resolution: Cannot Replicate Issue could not be replicated by Core Team and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Aug 16, 2023
@tugcekucukoglu tugcekucukoglu self-assigned this Aug 16, 2023
@github-actions
Copy link

We're unable to replicate your issue, if you are able to create a reproducer or add details please edit this issue. This issue will be closed if no activities in 20 days.

@chris-paganon
Copy link

You can easily replicate the issue: you currently have it on your main Primevue website. You have added a a cool loading animation to hide the layout shift and missing styles, if I block the JS I can clearly see the missing styles on the homepage 1st load.

@Gerrproger
Copy link
Author

@tugcekucukoglu Please check out this fresh reproducer link I've created https://stackblitz.com/edit/nuxt-starter-fz1hbf?file=app.vue

@mannyyang
Copy link

I'm having the same issue as well

@tugcekucukoglu tugcekucukoglu added Status: Pending Review Issue or pull request is being reviewed by Core Team and removed Resolution: Cannot Replicate Issue could not be replicated by Core Team labels Aug 22, 2023
@mannyyang
Copy link

Any workarounds people have done besides adding a loader on top before mounting? I've found that adding styles manually helps but kind of defeats the purpose

@lwpinion
Copy link

We are in the same boat. Our header uses the Menubar, so it jumps around when the page loads. Not an ideal user experience by any means! Having a loading icon for content of a page is acceptable, but not the header of the page.

Seems like our best option might just be making a custom component instead of using the built-in Menubar.

@lwpinion
Copy link

I was able to work around this by importing components like import Button from 'primevue/button/Button.vue'; instead of import Button from 'primevue/button';.

@Gerrproger
Can you elaborate on this? I tried doing this with the Menubar, but it doesn't seem to make a difference.

@Gerrproger
Copy link
Author

@lwpinion You should install version < 3.30.0 for this to work.

@tballak
Copy link

tballak commented Sep 27, 2023

@lwpinion You should install version < 3.30.0 for this to work.

Can you add nonce for CSP to primevue if you use an older version (< 3.30.0) ?

@mertsincan
Copy link
Member

Hi all,

I'm currently working on this issue. I'll solve this with a nuxtjs module in the next release and share the details here after completing it. Thanks a lot for your understanding!

@mertsincan mertsincan added Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add and removed Status: Pending Review Issue or pull request is being reviewed by Core Team labels Sep 27, 2023
@mertsincan mertsincan added this to the 3.35.1 milestone Sep 27, 2023
@mertsincan
Copy link
Member

I have completed the nuxt module and will release it as soon as possible. Example configs;

/* nuxt.config.js */
  ...
  primevue: {
    usePrimeVue: true,
    options: {
       // PrimeVue Config Options
       // ripple, pt etc.
    },
    components: {
      prefix: '',
      name: undefined,
      include: undefined,
      exclude: undefined
    },
    directives: {
      prefix: '',
      name: undefined,
      include: undefined,
      exclude: undefined
    },
    composables: {
      prefix: '',
      name: undefined,
      include: undefined,
      exclude: undefined
    }
  }
...

Best Regards,

@tmlmt
Copy link

tmlmt commented Dec 1, 2023

Since had been working great since @mertsincan's nuxt-primevue module was released, but Primevue v3.41.0 broke things and there's again large layout shifts at page load

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Projects
None yet
Development

No branches or pull requests

8 participants