vite: SVG Icons Not Rendering Consistently with Vite Due to Path Resolution Issues
Describe the bug
I am experiencing inconsistent behavior with SVG icons in my Vue application using Vite. When using the Icon.vue component to display SVG icons from a sprite file, some icons intermittently do not render. The issue seems related to path resolution or caching behavior in Vite.
I am doing:
- Creating and using a Vue component (
Icon.vue) to display SVG icons. - Loading SVG icons from a sprite file using paths starting with
/.
What I expect is:
- All SVG icons, including
search,hamburger,notification,play, anddots-vert, should render correctly.
What actually happening is:
- Initially, some icons do not render (e.g.,
playanddots-vert). - Reloading the page, clearing the cache, or restarting the Vite server was expected to fix the issue, but it didn’t happen.
- The issue seems related to path resolution or caching, as switching the path to
/public/temporarily resolves the problem.
Reproduction
https://stackblitz.com/~/github.com/otabekoff/vitejs-vite-tco99a
Steps to reproduce
Reproducing the issue involves creating a Vue component that uses SVG sprites and observing the inconsistent rendering of icons.
So, I’ve provided a ready code example on StackBlitz. After installing the project, follow the instructions in the instructions.md file. The issue persists there as well, not just on my local setup.
System Info
System:
OS: Windows 11 10.0.22631
CPU: (8) x64 Intel(R) Core(TM) i7-8665U CPU @ 1.90GHz
Memory: 4.96 GB / 15.74 GB
Binaries:
Node: 20.11.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.22 - ~\AppData\Roaming\npm\yarn.CMD
npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD
pnpm: 8.14.1 - ~\AppData\Local\pnpm\pnpm.CMD
Browsers:
Edge: Chromium (127.0.2651.74)
Internet Explorer: 11.0.22621.3527
But I've also Chrome latest and using it. Whatever the browser is, having the same issue. I've tested it on Edge too.
Used Package Manager
npm
Logs
Click to expand!
> vite --debug
vite:config bundled config file loaded in 1359.34ms +0ms
vite:config using resolved config: {
vite:config plugins: [
vite:config 'vite:optimized-deps',
vite:config 'vite:watch-package-data',
vite:config 'vite:pre-alias',
vite:config 'alias',
vite:config 'vite-plugin-inspect',
vite:config 'vite-plugin-vue-inspector',
vite:config 'vite-plugin-vue-devtools',
vite:config 'vite:modulepreload-polyfill',
vite:config 'vite:resolve',
vite:config 'vite:html-inline-proxy',
vite:config 'vite:css',
vite:config 'vite:esbuild',
vite:config 'vite:json',
vite:config 'vite:wasm-helper',
vite:config 'vite:worker',
vite:config 'vite:asset',
vite:config 'vite:vue',
vite:config 'vite:wasm-fallback',
vite:config 'vite:define',
vite:config 'vite:css-post',
vite:config 'vite:worker-import-meta-url',
vite:config 'vite:asset-import-meta-url',
vite:config 'vite:dynamic-import-vars',
vite:config 'vite:import-glob',
vite:config 'vite-plugin-vue-inspector:post',
vite:config 'vite:client-inject',
vite:config 'vite:css-analysis',
vite:config 'vite:import-analysis'
vite:config ],
vite:config css: { preprocessorOptions: { scss: [Object] }, lightningcss: undefined },
vite:config resolve: {
vite:config mainFields: [ 'browser', 'module', 'jsnext:main', 'jsnext' ],
vite:config conditions: [],
vite:config extensions: [
vite:config '.mjs', '.js',
vite:config '.mts', '.ts',
vite:config '.jsx', '.tsx',
vite:config '.json'
vite:config ],
vite:config dedupe: [ 'vue' ],
vite:config preserveSymlinks: false,
vite:config alias: [ [Object], [Object], [Object], [Object] ]
vite:config },
vite:config optimizeDeps: {
vite:config holdUntilCrawlEnd: true,
vite:config force: undefined,
vite:config esbuildOptions: { preserveSymlinks: false }
vite:config },
vite:config server: {
vite:config preTransformRequests: true,
vite:config host: undefined,
vite:config sourcemapIgnoreList: [Function: isInNodeModules$1],
vite:config middlewareMode: false,
vite:config fs: {
vite:config strict: true,
vite:config allow: [Array],
vite:config deny: [Array],
vite:config cachedChecks: undefined
vite:config }
vite:config },
vite:config define: {
vite:config __VUE_OPTIONS_API__: true,
vite:config __VUE_PROD_DEVTOOLS__: false,
vite:config __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false
vite:config },
vite:config ssr: {
vite:config target: 'node',
vite:config external: [],
vite:config optimizeDeps: { noDiscovery: true, esbuildOptions: [Object] }
vite:config },
vite:config configFile: 'C:/vueprojects/bekky-dev/vite.config.js',
vite:config configFileDependencies: [ 'C:/vueprojects/bekky-dev/vite.config.js' ],
vite:config inlineConfig: {
vite:config root: undefined,
vite:config base: undefined,
vite:config mode: undefined,
vite:config configFile: undefined,
vite:config logLevel: undefined,
vite:config clearScreen: undefined,
vite:config optimizeDeps: { force: undefined },
vite:config server: { host: undefined }
vite:config },
vite:config root: 'C:/vueprojects/bekky-dev',
vite:config base: '/',
vite:config decodedBase: '/',
vite:config rawBase: '/',
vite:config publicDir: 'C:/vueprojects/bekky-dev/public',
vite:config cacheDir: 'C:/vueprojects/bekky-dev/node_modules/.vite',
vite:config command: 'serve',
vite:config mode: 'development',
vite:config isWorker: false,
vite:config mainConfig: null,
vite:config bundleChain: [],
vite:config isProduction: false,
vite:config esbuild: { jsxDev: true },
vite:config build: {
vite:config target: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
vite:config cssTarget: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
vite:config outDir: 'dist',
vite:config assetsDir: 'assets',
vite:config assetsInlineLimit: 4096,
vite:config cssCodeSplit: true,
vite:config sourcemap: false,
vite:config rollupOptions: {},
vite:config minify: 'esbuild',
vite:config terserOptions: {},
vite:config write: true,
vite:config emptyOutDir: null,
vite:config copyPublicDir: true,
vite:config manifest: false,
vite:config lib: false,
vite:config ssr: false,
vite:config ssrManifest: false,
vite:config ssrEmitAssets: false,
vite:config reportCompressedSize: true,
vite:config chunkSizeWarningLimit: 500,
vite:config watch: null,
vite:config commonjsOptions: { include: [Array], extensions: [Array] },
vite:config dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] },
vite:config modulePreload: { polyfill: true },
vite:config cssMinify: true
vite:config },
vite:config preview: {
vite:config port: undefined,
vite:config strictPort: undefined,
vite:config host: undefined,
vite:config https: undefined,
vite:config open: undefined,
vite:config proxy: undefined,
vite:config cors: undefined,
vite:config headers: undefined
vite:config },
vite:config envDir: 'C:/vueprojects/bekky-dev',
vite:config env: { BASE_URL: '/', MODE: 'development', DEV: true, PROD: false },
vite:config assetsInclude: [Function: assetsInclude],
vite:config logger: {
vite:config hasWarned: false,
vite:config info: [Function: info],
vite:config warn: [Function: warn],
vite:config warnOnce: [Function: warnOnce],
vite:config error: [Function: error],
vite:config clearScreen: [Function: clearScreen],
vite:config hasErrorLogged: [Function: hasErrorLogged]
vite:config },
vite:config packageCache: Map(1) {
vite:config 'fnpd_C:/vueprojects/bekky-dev' => {
vite:config dir: 'C:/vueprojects/bekky-dev',
vite:config data: [Object],
vite:config hasSideEffects: [Function: hasSideEffects],
vite:config webResolvedImports: {},
vite:config nodeResolvedImports: {},
vite:config setResolvedCache: [Function: setResolvedCache],
vite:config getResolvedCache: [Function: getResolvedCache]
vite:config },
vite:config set: [Function (anonymous)]
vite:config },
vite:config createResolver: [Function (anonymous)],
vite:config worker: { format: 'iife', plugins: '() => plugins', rollupOptions: {} },
vite:config appType: 'spa',
vite:config experimental: { importGlobRestoreExtension: false, hmrPartialAccept: false },
vite:config getSortedPlugins: [Function: getSortedPlugins],
vite:config getSortedPluginHooks: [Function: getSortedPluginHooks]
vite:config } +28ms
vite:deps Hash is consistent. Skipping. Use --force to override. +0ms
Port 5173 is in use, trying another one...
VITE v5.4.1 ready in 1955 ms
➜ Local: http://localhost:5174/
➜ Network: use --host to expose
➜ Vue DevTools: Open http://localhost:5174/__devtools__/ as a separate window
➜ Vue DevTools: Press Alt(⌥)+Shift(⇧)+D in App to toggle the Vue DevTools
➜ press h + enter to show help
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 18 (7 by maintainers)
@otabekoff change icon names, just remove the sprite svg, use just the icon name:
/ui-icons.svg#<icon>=><icon>I’m preparing reproduction fixing your problem, I guess there is small regression on watcher… give me 5 minutes