fix(optimizer): handle more chars that will be sanitized#22208
fix(optimizer): handle more chars that will be sanitized#22208sapphi-red wants to merge 2 commits intovitejs:mainfrom
Conversation
| "version": 3, | ||
| }, | ||
| visualization: "https://evanw.github.io/source-map-visualization/#MjQ3AGNvbnN0IGZvbyA9IF9fdml0ZV9fY2pzSW1wb3J0MF9fdml0ZWpzX3Rlc3RJbXBvcnRlZVBrZ1siZm9vIl07Ly8gcHJldHRpZXItaWdub3JlCmltcG9ydCBfX3ZpdGVfX2Nqc0ltcG9ydDBfX3ZpdGVqc190ZXN0SW1wb3J0ZWVQa2cgZnJvbSAiL25vZGVfbW9kdWxlcy8udml0ZS9kZXBzL0B2aXRlanNfdGVzdC1pbXBvcnRlZS1wa2cuanM/dj0wMDAwMDAwMCI7CmNvbnNvbGUubG9nKCJ3aXRoLW11bHRpbGluZS1pbXBvcnQiLCBmb28pOwoyNDgAeyJtYXBwaW5ncyI6IjtBQUNBLFNBQ0UsV0FDSztBQUVQLFFBQVEsSUFBSSx5QkFBeUIsSUFBSSIsInNvdXJjZXMiOlsid2l0aC1tdWx0aWxpbmUtaW1wb3J0LnRzIl0sInZlcnNpb24iOjMsInNvdXJjZXNDb250ZW50IjpbIi8vIHByZXR0aWVyLWlnbm9yZVxuaW1wb3J0IHtcbiAgZm9vXG59IGZyb20gJ0B2aXRlanMvdGVzdC1pbXBvcnRlZS1wa2cnXG5cbmNvbnNvbGUubG9nKCd3aXRoLW11bHRpbGluZS1pbXBvcnQnLCBmb28pXG4iXX0=" | ||
| visualization: "https://evanw.github.io/source-map-visualization/#MjQ5AGNvbnN0IGZvbyA9IF9fdml0ZV9fY2pzSW1wb3J0MF9fdml0ZWpzX3Rlc3RJbXBvcnRlZVBrZ1siZm9vIl07Ly8gcHJldHRpZXItaWdub3JlCmltcG9ydCBfX3ZpdGVfX2Nqc0ltcG9ydDBfX3ZpdGVqc190ZXN0SW1wb3J0ZWVQa2cgZnJvbSAiL25vZGVfbW9kdWxlcy8udml0ZS9kZXBzL0B2aXRlanNfMmZ0ZXN0LWltcG9ydGVlLXBrZy5qcz92PTAwMDAwMDAwIjsKY29uc29sZS5sb2coIndpdGgtbXVsdGlsaW5lLWltcG9ydCIsIGZvbyk7CjI0OAB7Im1hcHBpbmdzIjoiO0FBQ0EsU0FDRSxXQUNLO0FBRVAsUUFBUSxJQUFJLHlCQUF5QixJQUFJIiwic291cmNlcyI6WyJ3aXRoLW11bHRpbGluZS1pbXBvcnQudHMiXSwidmVyc2lvbiI6Mywic291cmNlc0NvbnRlbnQiOlsiLy8gcHJldHRpZXItaWdub3JlXG5pbXBvcnQge1xuICBmb29cbn0gZnJvbSAnQHZpdGVqcy90ZXN0LWltcG9ydGVlLXBrZydcblxuY29uc29sZS5sb2coJ3dpdGgtbXVsdGlsaW5lLWltcG9ydCcsIGZvbylcbiJdfQ==" |
There was a problem hiding this comment.
The sourcemap changes are caused by the optimized filename change.
|
The approach of aligning One concern: |
bluwy
left a comment
There was a problem hiding this comment.
I checked and I think this should invalidate the metadata hash so it's reoptimized on Vite update. Otherwise it might still refer to the old paths.
| .replaceAll('_', '__') | ||
| // replace any characters that will be replaced by sanitizeFileName | ||
| .replace(invalidUrlPathCharRE, (c) => '_' + c.charCodeAt(0).toString(16)) | ||
| .replace( | ||
| additionalFlattenIdCharRE, | ||
| (c) => '_' + c.charCodeAt(0).toString(16), | ||
| ) | ||
| .replace(replaceNestedIdRE, '__'), |
There was a problem hiding this comment.
The _2f pattern here makes it harder to read personally. I understand making it robust, but maybe we can go with a middleground:
What if we do the normal underscore replacements for the commons chars, like / and ., and then do the _2f pattern for the rest? Maybe even _2f_ so it's slightly easier to read.
Also, it'd be nice to have some more tests for the new chars.
Since
$is also sanitized by Rolldown bysanitizeFileName, the filename does not contain$.#21886 fixed a similar issue for
+, but it was not a general fix. In this PR, I've rewritten theflattenIdfunction to escape any characters that will be escaped by the defaultsanitizeFileName.close #22198