Skip to content

Vite5: Inconsistent crossorigin attribute in css tags #17929

Closed
@fallemand

Description

@fallemand

Describe the bug

We noticed that after the migration to Vite5, in production, most CSS imports contain the crossorigin attribute (after #12991).
But in some cases, we noticed it was missing.
For example:

<!-- In most pages this asset is added with crossorigin -->
<link rel="stylesheet" crossorigin src="cdn.blabla.test/some-css-123123.css">

<!--In other pages is added without -->
<link rel="stylesheet" src="cdn.blabla.test/some-css-123123.css">

This leads to problems when we cache the file response without crossorigin and later the browser tries to use it for the import with crossorigin.

Access to CSS stylesheet at 'https://cdn.getyourguide.com/tf/assets/compiled/client/assets/css-slider-card-CMnb0hfz-v2  
'from origin 'https://www.getyourguide.com/' has been blocked by CORS policy: No 'Access-Control-Allow-Origin'   
header is present on the requested resource.

The issue is coming from this line: mportAnalysisBuild.ts#L126
We add the crossorigin for JS but not for CSS.
image

Reproduction

Steps to reproduce

No response

System Info

System:
    OS: macOS 14.6.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 1.71 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.15.1 - ~/.nvm/versions/node/v20.15.1/bin/node
    npm: 10.7.0 - ~/.nvm/versions/node/v20.15.1/bin/npm
    pnpm: 9.4.0 - ~/.nvm/versions/node/v20.15.1/bin/pnpm
  Browsers:
    Brave Browser: 127.1.68.141
    Safari: 17.6

Used Package Manager

pnpm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions