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

<style> tags are not generated in SSR since Nuxt 3.12 #4

Open
Tsuyoshi84 opened this issue Jun 20, 2024 · 1 comment
Open

<style> tags are not generated in SSR since Nuxt 3.12 #4

Tsuyoshi84 opened this issue Jun 20, 2024 · 1 comment

Comments

@Tsuyoshi84
Copy link

Tsuyoshi84 commented Jun 20, 2024

Environment

  • Nuxt: 3.12.2
  • naive-ui: 2.38.2
  • nuxtjs-naive-ui: 1.0.2

Reproduction

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

Describe the bug

Since Nuxt 3.12, it seems like the <script> tags in the <head> are not generated correctly in SSR. Because of that, the page style initially loaded is broken. (After the hydration step, it will be fixed since the script tags are injected)

I assume the following change affected this module's process as it removed ssrContext.styles, which is leveraged by this module during SSR.

nuxt/nuxt@2d1ab61

@monsterkai233
Copy link

monsterkai233 commented Jun 27, 2024

you can add a plugin

import { setup } from '@css-render/vue3-ssr'
import { defineNuxtPlugin } from '#app'
export default defineNuxtPlugin(nuxtApp => {
  if (import.meta.server) {
    const { collect } = setup(nuxtApp.vueApp)
    nuxtApp.ssrContext!.head.push({
      style: () =>
        collect()
          .split('</style>')
          .map(block => {
            const id = block.match(/cssr-id="(.+?)"/)?.[1]
            const style = (block.match(/>(.*)/s)?.[1] || '').trim()
            return {
              ['cssr-id']: id,
              innerHTML: style
            }
          })
    })
  }
})

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

No branches or pull requests

2 participants