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

with Vite 5 prerendered pages are missing CSS #11390

Open
xmlking opened this issue Dec 19, 2023 · 4 comments
Open

with Vite 5 prerendered pages are missing CSS #11390

xmlking opened this issue Dec 19, 2023 · 4 comments

Comments

@xmlking
Copy link

xmlking commented Dec 19, 2023

Describe the bug

I am using Kit 2 and Vite 5, when I build then preview prerendered pages are missing CSS lines in HTML

when I switch back, to Vite 4.5.0 (still keeping kit 2 changes) there are getting generated. e.g.,
image

Reproduction

Repo: https://github.com/xmlking/spectacular/tree/main/apps/console-fb

to reproduce:

  1. upgrade Vite from 4.5.1 to 5.0.10 in apps/console-fb/package.json
  2. pnpm i
  3. turbo build --filter=console-fb
  4. turbo preview --filter=console-fb
    You will get distorted page due to missing CSS

Logs

N/A

System Info

System:
    OS: macOS 14.1.2
    CPU: (10) arm64 Apple M1 Max
    Memory: 18.02 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.3.0 - /opt/homebrew/bin/node
    npm: 10.2.4 - /opt/homebrew/bin/npm
    pnpm: 8.12.1 - /opt/homebrew/bin/pnpm
    bun: 1.0.15 - /opt/homebrew/bin/bun
  Browsers:
    Chrome: 120.0.6099.109
    Safari: 17.1.2
  npmPackages:
    @sveltejs/adapter-auto: 3.0.0 => 3.0.0 
    @sveltejs/adapter-node: 2.0.0 => 2.0.0 
    @sveltejs/adapter-vercel: 4.0.2 => 4.0.2 
    @sveltejs/enhanced-img: 0.1.6 => 0.1.6 
    @sveltejs/kit: 2.0.2 => 2.0.2 
    @sveltejs/vite-plugin-svelte: 3.0.1 => 3.0.1 
    svelte: 4.2.8 => 4.2.8 
    vite: 4.5.1 => 4.5.1

Severity

serious, but I can work around it

Additional Information

N/A

@eltigerchino
Copy link
Member

Please include a minimal reproduction instead of your entire project.

@xmlking
Copy link
Author

xmlking commented Feb 3, 2024

I finally found the root cause for this issue. my env:

  1. ✅ SvelteKit project with "@sveltejs/kit": "^2.0.0" and some prerendered landing and blog routes
  2. ✅ Using @vite-pwa/sveltekit for offline access support with ServiceWorker. and having serviceWorker: { register: false } in svelte.config.js as recommended in their docs
  3. 🙅🏽 Added preloadStrategy: 'preload-mjs' in svelte.config.js according to sveltekit docs assuming it give better performance
output: {
	preloadStrategy: 'preload-mjs'
},

after I remove preloadStrategy: 'preload-mjs' setting in svelte.config.js css is generated as expected.

lesson learned: while using prerender = true routes, don't use preloadStrategy: 'preload-mjs'

First I though vite-pwa/sveltekit caused the issue. but it is doing its job well 👍🏽

@eltigerchino
Copy link
Member

Thanks for posting your findings. I think it’s worth it to keep this open since it should still prerender correctly even with that preload strategy

@srueg
Copy link

srueg commented Feb 4, 2024

Might be related: #11428

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

3 participants