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

FOUC on dev ssr #1287

Closed
medz opened this issue Aug 18, 2024 · 15 comments · Fixed by #1308
Closed

FOUC on dev ssr #1287

medz opened this issue Aug 18, 2024 · 15 comments · Fixed by #1308

Comments

@medz
Copy link

medz commented Aug 18, 2024

Environment

  • Operating System: Darwin
  • Node Version: v22.6.0
  • Nuxt Version: 2.18.1
  • CLI Version: 3.12.0
  • Nitro Version: 2.9.7
  • Package Manager: [email protected]
  • Builder: vite
  • User Config: bridge, vite, nitro, alias, css, modules, experimental, build, head, plugins, components, buildModules, moment, axios, vue, router, serverHandlers, devServerHandlers, devServer, typescript
  • Runtime Modules: @nuxtjs/[email protected], @pinia/[email protected]
  • Build Modules: (), @nuxtjs/[email protected], @nuxt/[email protected]

Reproduction

Any Nuxt 2 project of Nuxt Bridge cannot extract css

Describe the bug

When the Nuxt 2 project was gradually upgraded using the bridge, it was found that after enabling Vite, all styles were style tags dynamically generated by JS and could not be extracted into separate css files. This caused the page to not display properly when loaded for the first time.

Additional context

No response

Logs

No response

@wattanx
Copy link
Collaborator

wattanx commented Aug 19, 2024

Have you tried vite.legacy: false?
ref: #1164

@medz
Copy link
Author

medz commented Aug 19, 2024

@wattanx vite.legacy: false succeeded, but compared with the webpack package, the page still flickers and displays no style first. This problem will not occur after webpack packaging. Nuxt 3 will not have this problem either.

@medz
Copy link
Author

medz commented Aug 19, 2024

So I think the vite issue still exists.

@wattanx
Copy link
Collaborator

wattanx commented Aug 20, 2024

It seems to work in a production build.
(npm run build && npm run start)
https://stackblitz.com/edit/github-yueotr

There may be a problem in the case of dev

@medz
Copy link
Author

medz commented Aug 20, 2024

It seems to work in a production build. (npm run build && npm run start) https://stackblitz.com/edit/github-yueotr

There may be a problem in the case of dev

@wattanx
I think you should have noticed that although the style is successfully extracted, the application style still flickers.

You can try to use webpack to extract the style in the same way, and there will be no flickering.

@medz
Copy link
Author

medz commented Aug 20, 2024

Rather than flickering, it should be a lag in enabling styles

@wattanx
Copy link
Collaborator

wattanx commented Aug 20, 2024

There seemed to be a flicker in the production build as well.
(I didn't notice it because it was fast).

It still behaves the same as Nuxt 3 in production mode.

We'll look into it, but it will take time.

memo:
In the case of webpack, the style is applied by SSR.
For vite, styles are not applied in SSR (same for Nuxt 3).

@wattanx wattanx changed the title Unable to extract CSS (vite: true) FOUC on dev ssr Sep 8, 2024
@wattanx wattanx mentioned this issue Sep 8, 2024
7 tasks
@medz
Copy link
Author

medz commented Oct 19, 2024

@wattanx I think we should reopen it and revise the title.

Yes, you solve the problem of style flashing in #1308, but it has not solved the problem of flashing after Pord Build packaging.

My configuration:

export default defineNuxtConfig({
  ssr: true,
  sourcemap: true,
  bridge: {
    capi: true,
    vite: { legacy: true },
    nitro: true,
    meta: true,
    macros: { pageMeta: true },
  },
  vite: {
    css: {
      postcss: {
        plugins: [tailwindcss(), autoprefixer()],
      },
    },
  },
});

At present, this is the biggest reason that hinders me to continue to upgrade to Nuxt 3. Because there are a lot of dependence that needs to be upgraded. But this problem forced me to continue to use the webpack@v4, so I couldn't continue to gradually upgrade other contents.

@medz
Copy link
Author

medz commented Oct 19, 2024

@wattanx
I only made a minimum replica: https://stackblitz.com/~/github.com/medz/github-avnkvf

@medz
Copy link
Author

medz commented Oct 19, 2024

In addition, this seems to be the return of #561

@medz
Copy link
Author

medz commented Oct 19, 2024

<template>
  <div>
    <h1>test</h1>
  </div>
</template>

<style>
h1 {
  color: red;
}
</style>

@medz
Copy link
Author

medz commented Oct 19, 2024

Image
For this purpose, I also created a minimal implementation for Nuxt 3. The behavior is essentially different. There is only one reason why Nuxt 3 is not present:

Nuxt 3 writes the style of pages or components to the html head, and Nuxt bridge does not do this.

This is why the page flickers after Nuxt bridge enables vite.

example: https://stackblitz.com/~/github.com/medz/github-8bvs9l

@medz
Copy link
Author

medz commented Oct 19, 2024

Image
This is the output after Nuxt bridge enables vite. There is no h1{color:red} style, and the style is applied in JS only after index.xxx.js is loaded.

This causes the flickering.

@wattanx
Copy link
Collaborator

wattanx commented Oct 20, 2024

Could you create a new issue? (I might miss it otherwise)

@medz
Copy link
Author

medz commented Oct 20, 2024

Could you create a new issue? (I might miss it otherwise)

Yes 👉 #1334

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

Successfully merging a pull request may close this issue.

2 participants