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

5.4.3 production bug #18038

Closed
7 tasks done
georgemincof opened this issue Sep 5, 2024 · 11 comments · Fixed by #18367
Closed
7 tasks done

5.4.3 production bug #18038

georgemincof opened this issue Sep 5, 2024 · 11 comments · Fixed by #18367
Labels
p4-important Violate documented behavior or significantly improves performance (priority)

Comments

@georgemincof
Copy link

Describe the bug

Hi!

We encountered an issue with version 5.4.3 that breaks our app in production:

This change affects users who already have the CSS resources cached. By adding the crossorigin attribute, the browser automatically cancels the requests due to CORS.

For some reason, the failed preload is causing the entire app to break.

For now, I’ve locked the version to 5.4.2 until I find a solution.

Reproduction

Steps to reproduce

No response

System Info

-

Used Package Manager

npm

Logs

No response

Validations

@vitejs vitejs deleted a comment Sep 5, 2024
@georgemincof
Copy link
Author

A solution to force cache invalidation is to change the CSS asset file name using the following options:

For example, notice the 0 added after the [hash]:

build: {
  rollupOptions: {
    output: {
      assetFileNames: (chunkInfo) => {
        // https://github.com/vitejs/vite/issues/18038
        if (chunkInfo.name?.endsWith(".css")) {
          return "assets/[name]-[hash]0[extname]";
        }

        return "assets/[name]-[hash][extname]";
      },
    },
  },
},

@seanogdev
Copy link

We also encountered this issue this morning. Thankfully, downgrading to 5.4.2 fixed this for us also 👍

@sapphi-red
Copy link
Member

@georgemincof @seanogdev Would you try 5.4.5+? A related fix has been included.

@peroo
Copy link

peroo commented Sep 19, 2024

@sapphi-red We ran into a production outage yesterday after updating from vite 5.2.8 to 5.4.6, because of this change in behavior. Users who had dynamically imported css chunks cached would crash with Unable to preload CSS.

From what I can tell the fix in 5.4.5 only applies to vite:preloadError, which doesn't really help us since reloading the page won't make a difference as long as the chunk has the same URI, which is the case for us.

We'll probably have to invalidate the cache by temporarily changing the css chunk filename as suggested above.

@georgemincof
Copy link
Author

Right... the real problem here is the "crossorigin" attribute. The issue that preload brings is more of a side effect.
Any app using a CDN in production with static content rules will face this breaking change due to CORS.

In conclusion, I believe this can be closed, as the fix that worked for us should address the issue for the majority. It's not that big of a problem...

@seanogdev
Copy link

Its not a big problem no 👍 It is just a bit cumbersome to have to modify the asset hash function in vite due to a patch version, a lot of our css files dont change that often so this vite config change will need to stay for the foreseeable.

@wcpaez
Copy link

wcpaez commented Sep 20, 2024

I had production outage after updating from vite 5.3.5 to 5.4.7.

@sapphi-red
Copy link
Member

Hmm, does it only happen on Chromium browsers (e.g. Chrome, Edge)? It feels like it's similar to https://www.hacksoft.io/blog/handle-images-cors-error-in-chrome (https://issues.chromium.org/issues/40381978).

@phthhieu
Copy link

phthhieu commented Oct 1, 2024

We also have production outage after updating from vite 5.3.3 to 5.4.8.

@sapphi-red sapphi-red added the p2-to-be-discussed Enhancement under consideration (priority) label Oct 1, 2024
@sapphi-red sapphi-red moved this from Discussing to P2 - 5 in Team Board Oct 1, 2024
@github-project-automation github-project-automation bot moved this to Discussing in Team Board Oct 1, 2024
@smartin88
Copy link

We also experience this issue when upgrading to the latest version of Nuxt, which uses Vite 5.4.6. Downgrading to 5.4.2 worked, but now there is a reported security vulnerability. I have tried the workaround from @georgemincof but this causes all of our CSS assets not to load at all.

@bluwy bluwy moved this from P2 - 5 to Has plan in Team Board Oct 16, 2024
@sapphi-red sapphi-red added p4-important Violate documented behavior or significantly improves performance (priority) and removed p2-to-be-discussed Enhancement under consideration (priority) labels Oct 16, 2024
@sapphi-red
Copy link
Member

Published v5.4.10 that changes all hashes of CSS files. It should be fine to upgrade now that the hashes are different from the older deployed ones.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p4-important Violate documented behavior or significantly improves performance (priority)
Projects
Archived in project
7 participants