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

missing css in client manifest legacy chunks #10782

Closed
7 tasks done
IlyaSemenov opened this issue Nov 4, 2022 · 6 comments
Closed
7 tasks done

missing css in client manifest legacy chunks #10782

IlyaSemenov opened this issue Nov 4, 2022 · 6 comments

Comments

@IlyaSemenov
Copy link
Contributor

IlyaSemenov commented Nov 4, 2022

Describe the bug

When I generate a client manifest with @vitejs/plugin-legacy plugin enabled, legacy chunks are missing css entries.

Example:

{
  "index-legacy.html": {
    "file": "assets/index-legacy.1b2bcd2a.js",
    "src": "index-legacy.html",
    "isEntry": true
  },
  "vite/legacy-polyfills-legacy": {
    "file": "assets/polyfills-legacy.907dbd91.js",
    "src": "vite/legacy-polyfills-legacy",
    "isEntry": true
  },
  "index.html": {
    "file": "assets/index.9f336c05.js",
    "src": "index.html",
    "isEntry": true,
    "css": [
      "assets/index.824f0ed3.css"
    ]
  },
  "index.css": {
    "file": "assets/index.824f0ed3.css",
    "src": "index.css"
  }
}

In the example above, index.html includes a css dependency, but the respective index-legacy.html does not.

This is affecting third party libraries which rely on the manifest to inject the respective<link rel="stylesheet"> into HTML head. For example: nuxt/bridge#561.

Reproduction

https://stackblitz.com/edit/vitejs-vite-mjitx2?file=dist/manifest.json

Steps to reproduce

Run npm install followed by npm run build. Examine dist/manifest.json.

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    @vitejs/plugin-legacy: ~2.3.0 => 2.3.0 
    vite: ~3.2.1 => 3.2.2

Used Package Manager

npm

Logs

No response

Validations

@IlyaSemenov
Copy link
Contributor Author

My naive hotfix for the time being is using the following pnpm patch:

diff --git a/dist/node/chunks/dep-4da11a5e.js b/dist/node/chunks/dep-4da11a5e.js
index ef2d5d810506e20169239232d9972f1adf9bcdd8..114693e1473f068b95f016efa096ddf992521413 100644
--- a/dist/node/chunks/dep-4da11a5e.js
+++ b/dist/node/chunks/dep-4da11a5e.js
@@ -44284,7 +44284,7 @@ function cssPostPlugin(config) {
                     // this is a shared CSS-only chunk that is empty.
                     pureCssChunks.add(chunk.fileName);
                 }
-                if (opts.format === 'es' || opts.format === 'cjs') {
+                if (opts.format === 'es' || opts.format === 'cjs' || opts.format === 'system') {
                     const cssAssetName = chunk.facadeModuleId
                         ? normalizePath$3(path$n.relative(config.root, chunk.facadeModuleId))
                         : chunk.name;

This is simply based on the fact that plugin-legacy sets system for the output format:

const createLegacyOutput = (
options: OutputOptions = {}
): OutputOptions => {
return {
...options,
format: 'system',

I am not competent enough to tell if this is a valid approach or if it will break things under different circumstances.

@sapphi-red
Copy link
Member

This is expected because legacy chunks uses the inlined CSS (#2062).

@IlyaSemenov
Copy link
Contributor Author

I see. So I suppose that's a downstream problem in the sense that any downstream app should not rely on legacy chunks only?

@sapphi-red
Copy link
Member

sapphi-red commented Nov 8, 2022

I guess using only legacy chunks will work because all the CSS used are inlined. Maybe you faced a bug caused by #9761 that affected Vite 3.1.x?
It's fixed in 3.2.0 so upgrading Vite might work.

@IlyaSemenov
Copy link
Contributor Author

Right, pinning vite to 3.2.3 makes nuxt-bridge work, however the result is unsatisfactory. Inlining CSS in a SSR build leads to the flash of unstyled content (FOUC). The server delivers pre-rendered HTML but the styles only appear after the entire set of scripts loads and starts. Legacy clients with no javascript (e.g. web crawlers) don't get any styles at all.

I am not sure how to proceed here from the triage point of view. On the one hand, vite 3.2 works "as expected". On the other hand, the current "expected" behaviour is not friendly to the downstream SSR tooling that operates with legacy chunks.

@sapphi-red
Copy link
Member

I think we can close this issue because avoiding inlining CSS in legacy is tracked in #2062.

@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Nov 8, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Nov 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants