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

failed CSS preloads prevent loading dependencies #18042

Closed
7 tasks done
danielroe opened this issue Sep 6, 2024 · 1 comment · Fixed by #18046
Closed
7 tasks done

failed CSS preloads prevent loading dependencies #18042

danielroe opened this issue Sep 6, 2024 · 1 comment · Fixed by #18046

Comments

@danielroe
Copy link
Contributor

danielroe commented Sep 6, 2024

Describe the bug

context: nuxt/nuxt#26972
Nuxt reproduction: https://stackblitz.com/edit/github-wg3yu6-bpadkv
Vite-only reproduction: https://stackblitz.com/edit/vitejs-vite-ce8f5t (you'll need to block CSS in your browser devtools)

If there is an issue loading a CSS dependency, you'll get this error:

Error: Unable to preload CSS for /assets/App-BBLnt7oG.css

However, the error that's thrown can't be worked around, even if e.preventDefault is called on it. If you register an error handler and try to suppress it, you'll get a different error instead:

// This changes the error but is still fatal
window.addEventListener('vite:preloadError', event => {
  event.preventDefault()
})
// TypeError: Cannot read properties of undefined (reading 'default')

I believe this is because the dep array is loaded with Promise.all, the other deps are blocked. I would suggest using Promise.allSettled.

The issue can occur in Google crawling a site, for example, if the CSS file references assets that are too large. See this search: https://www.google.com/search?q=%22Unable+to+preload+CSS%22+%22internal+server+error 🙈

Reproduction

https://stackblitz.com/edit/vitejs-vite-ce8f5t

Steps to reproduce

  1. Do a yarn build, yarn preview
  2. Go to your network tab and block *.css, then refresh the page

System Info

System:
    OS: macOS 14.6.1
    CPU: (8) arm64 Apple M2
    Memory: 53.66 MB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.5.0 - ~/.local/share/mise/installs/node/20.5.0/bin/node
    npm: 9.8.0 - ~/.local/share/mise/installs/node/20.5.0/bin/npm
    pnpm: 9.9.0 - ~/.local/share/mise/installs/node/20.5.0/bin/pnpm
    bun: 1.0.20 - ~/.bun/bin/bun
  Browsers:
    Chrome: 128.0.6613.120
    Safari: 17.6
  npmPackages:
    @vitejs/plugin-vue: 5.1.3 => 5.1.3

Used Package Manager

yarn

Logs

No response

Validations

Copy link

stackblitz bot commented Sep 6, 2024

@github-actions github-actions bot locked and limited conversation to collaborators Sep 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant