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

fix: don't inject CSS sourcemap for direct requests #13115

Merged
merged 4 commits into from May 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/css.ts
Expand Up @@ -404,7 +404,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
}

if (isDirectCSSRequest(id)) {
return await getContentWithSourcemap(css)
return htmlProxyRE.test(id) ? await getContentWithSourcemap(css) : css
Copy link
Member

Choose a reason for hiding this comment

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

I think we should generate the sourcemap in the htmlInlineProxyPlugin.


Then, we can just run return null in this line I guess. (The plugin container will add the sourcemap if needed)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure to understand. I've read part of the code of the plugin and I don't understand where is the pipeline called. I've the impression that the cache map is set with the tag content directly without transformation and then on this line we return this content

Copy link
Member

Choose a reason for hiding this comment

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

Ah, my bad. I was misunderstanding the code. I pushed the code I had in my mind.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh ok I didn't saw that call to the pluginContainer and just saw the load part.
I have no opinion on where this code 🤷‍♂️

}
// server only
if (options?.ssr) {
Expand Down
15 changes: 11 additions & 4 deletions playground/css-sourcemap/__tests__/css-sourcemap.spec.ts
Expand Up @@ -29,7 +29,7 @@ describe.runIf(isServe)('serve', () => {

test('linked css', async () => {
const res = await page.request.get(
new URL('./linked.css', page.url()).href,
new URL('./linked-with-import.css', page.url()).href,
ArnaudBarre marked this conversation as resolved.
Show resolved Hide resolved
{
headers: {
accept: 'text/css',
Expand All @@ -40,12 +40,19 @@ describe.runIf(isServe)('serve', () => {
const map = extractSourcemap(css)
expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
{
"mappings": "AAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACT,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACb,CAAC;",
"mappings": "AAAA;EACE,UAAU;AACZ;;ACAA;EACE,UAAU;AACZ",
"sources": [
"/root/linked.css",
"be-imported.css",
"linked-with-import.css",
],
"sourcesContent": [
".linked {
".be-imported {
color: red;
}
",
"@import '@/be-imported.css';

.linked-with-import {
color: red;
}
",
Expand Down