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

Open
7 tasks done
georgemincof opened this issue Sep 5, 2024 · 6 comments
Open
7 tasks done

5.4.3 production bug #18038

georgemincof opened this issue Sep 5, 2024 · 6 comments

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.

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

No branches or pull requests

4 participants