fix(css): remove css-post plugin sourcemap#9914
Conversation
|
For anyone trying to wrap their had around this, like I did, here's what I've figured:
At this point the issue is two fold:
The good thing is however that the css code wrapped into a variable inside the HMR JS response already includes the sourcemap for the CSS, so there is really no need to add the same sourcemap at the end of the HMR JS file too. This is what the fix relies on: by not only returning the new HMR JS code, but an empty dummy source map as well, it forces the source maps collected in the context so far to be ignored when the source maps are combined. The empty sourcemap masks the others, so no sitemap is generated at the end so the response is sent to the browser as it is, without additional source map attached to the end, what is done for most responses otherwise. The issue in theory is there both when And finally why the sourcemap is not needed at all in the HMR JS file carrying the css payload? Because another file is already loaded by the URL So how come it worked in some browsers and not in others? It is because some browsers ignored the sourcemap from the css request and relied on the other one provided in the other request. After all these requests are for the same file, only differ in query parameters, and there's no standard approach what to do if multiple request claim to provide mappings for a given source. Chrome tries to apply all of them. Firefox processes both sourcemaps and shows two versions of the same source, one based on each. And I assume Safari simply ignores the later one. |
Compatibility was broken with fix vitejs#9914 but also we don't need and don't want to add dummy sourcemaps to HMR JS requests.
Description
fixes #9830
/src/components/HelloWorld.vuehas the sourcemap below.{ "version": 3, "mappings": "AACA;AAEA;AAAA,EACA;AAAA,IACA;AAAA,EACA;AAAA,EACA;AACA;AACA;AAAA,MACA;AAAA,IACA;AAAA,EACA;AACA", "names": [], "sources": [ "/home/projects/mkliybgym.github/src/components/HelloWorld.vue" ], "file": "/home/projects/mkliybgym.github/src/components/HelloWorld.vue", "sourcesContent": [ "<script lang=\"ts\">\nimport Vue from 'vue';\n\nexport default Vue.extend({\n props: {\n msg: { type: String },\n },\n data() {\ndebugger;\n return {\n count: 0,\n };\n },\n});\n</script>\n\n<template>\n <div>\n <h1>{{ msg }}</h1>\n\n <div class=\"card\">\n <button type=\"button\" @click=\"count++\">count is {{ count }}</button>\n <p>\n Edit\n <code>components/HelloWorld.vue</code> to test HMR\n </p>\n </div>\n\n <p>\n Check out\n <a href=\"https://vuejs.org/guide/quick-start.html#local\" target=\"_blank\"\n >create-vue</a\n >, the official Vue + Vite starter\n </p>\n <p>\n Install\n <a href=\"https://github.com/johnsoncodehk/volar\" target=\"_blank\">Volar</a>\n in your IDE for a better DX\n </p>\n <p class=\"read-the-docs\">Click on the Vite and Vue logos to learn more</p>\n </div>\n</template>\n\n<style lang=\"postcss\" scoped>\n.read-the-docs {\n color: #888;\n}\n</style>\n" ] }/src/components/HelloWorld.vue?vue&type=style&index=0&scoped=true&lang.postcsshas the sourcemap below.{ "version": 3, "sources": [ "/home/projects/mkliybgym.github/src/components/HelloWorld.vue" ], "names": [], "mappings": ";AA4CA;EACE,WAAW;AACb", "file": "HelloWorld.vue", "sourcesContent": [ "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n.read-the-docs {\n color: #888;\n}\n" ] }/src/components/HelloWorld.vue'ssourcesContenthas correct content but/src/components/HelloWorld.vue?vue&type=style&index=0&scoped=true&lang.postcsshas a empty lines for non-style part.Actually, this sourcemap comes from vite-plugin-vue2 and needs a fix on their side.
That said,
vite:css-postdoes not need to return sourcemap as the sourcemap is injected inside CSS. So I removed it by settingmap: { mappings: '' }.Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).