Skip to content

Comments

fix(css): apply server.origin to public file urls in CSS (fix #18457)#21697

Open
SalvatoreT wants to merge 1 commit intovitejs:mainfrom
SalvatoreT:salvatoret/18457/css-config-server-origin
Open

fix(css): apply server.origin to public file urls in CSS (fix #18457)#21697
SalvatoreT wants to merge 1 commit intovitejs:mainfrom
SalvatoreT:salvatoret/18457/css-config-server-origin

Conversation

@SalvatoreT
Copy link

Fixes #18457

Vite's CSS plugin rewrites url() references during dev by resolving them to absolute URLs with the dev server's origin hardcoded. The server.origin config exists but is only applied in some code paths (module assets in templates and JS imports) but not in others (CSS url() rewriting path).

Similar to @kajic on #18457, I have a base for creating the HTML and a different one for the Vite server.

This has turned out to be a problem for me because I serve HTML generated by a Vite SSR server from a server in front of the Vite dev server. In short, a server at http://127.0.0.1:8000/ requests HTML from Vite running at http://127.0.0.1:5173/, and the fronting server returns the HTML it got from Vite to the browser. At this point, all URLs in the HTML are relative to http://127.0.0.1:8000/, instead of being relative to http://127.0.0.1:5173/, so all static assets on the page fail to load.

This change just lest the server.origin also get applied to the CSS files too.


  • Read the Contributing Guidelines at https://github.com/vitejs/vite/blob/main/CONTRIBUTING.md.
  • Check that there isn't already a PR that solves the problem the same way. If you find a duplicate, please help us review it.
  • Update the corresponding documentation if needed.
  • Include relevant tests that fail without this PR but pass with it. If the tests are not included, explain why.

…18457)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a unit test here, would you add a test to playground/backend-integration?

Also it would be nice to have tests for non-public assets.

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

Successfully merging this pull request may close these issues.

Support server.origin for references in HTML files

2 participants