vite_ruby icon indicating copy to clipboard operation
vite_ruby copied to clipboard

`assets:clean` incorrectly removes files created in the same build

Open KevinBerthier opened this issue 2 years ago • 2 comments

Description 📖

Some assets are missing on production after deployment. It happens totally randomly. A redeployment fixes the issue

Reproduction 🐞

deploy.rb

set :keep_releases, 5
set :use_sudo, false

set :log_level, :debug

set :linked_files, %w[config/database.yml config/application.yml config/secrets.yml public/.htaccess]
set :linked_dirs, %w[.bundle log storage public/system public/uploads downloads node_modules tmp/pids tmp/cache tmp/sockets tmp/dumps]

set :bundle_jobs, 2
set :keep_assets, 2
set :assets_prefix, 'vite'

vite.config.ts

import { resolve } from 'path'
import { defineConfig } from 'vite'
import VuePlugin from '@vitejs/plugin-vue'
import { visualizer } from "rollup-plugin-visualizer";
import ViteRails from 'vite-plugin-rails'
import legacy from '@vitejs/plugin-legacy'



export default defineConfig({
  plugins: [
    legacy({ renderLegacyChunks: false }), // reads .browserlistrc
    ViteRails({
      stimulus: false,
      fullReload: {
        additionalPaths: ['app/**/*', 'config/locales/**/*']
      },
    }), VuePlugin(), visualizer()
  ],
  resolve: {
    alias: {
      '@assets': resolve(__dirname, 'app/assets'),
      '@stylesheets': resolve(__dirname, 'app/assets/stylesheets'),
      '@images': resolve(__dirname, 'app/assets/images'),
      '@pdp': resolve(__dirname, 'app/javascript/apps/pdp'),
    },
  },

})
Vite Ruby Info
bin/vite present?: true
vite_ruby: 3.3.4
vite_rails: 3.0.15
rails: 7.0.7.2
node: v20.5.1
npm: 9.8.0
yarn: 1.22.17
pnpm: 
ruby: ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [arm64-darwin22]

installed packages:
[email protected] /Users/kevinberthier/code/KevinBerthier/graphiste
├─┬ @vitejs/[email protected]
│ └── [email protected] deduped
├─┬ @vitejs/[email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected] deduped
│ ├─┬ [email protected]
│ │ └── [email protected] deduped
│ ├─┬ [email protected]
│ │ └── [email protected] deduped
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
└── [email protected]

KevinBerthier avatar Sep 25 '23 14:09 KevinBerthier

After further investigations, we found that assets:clean was flaky because the method #versions uses mtime to determine versions, but sometimes a deployment can spread on multiples mtimes/versions (3 in our case).

Our temporary solution was to increase keep_assets

Sprocket seems to clean assets the same manner but seems to be able to generate all assets with an identical mtime

KevinBerthier avatar Oct 03 '23 14:10 KevinBerthier

Hi Kevin! Thanks for reporting.

It seems like files in a Vite build have a different mtime, so the vite:clean task should be modified to cluster files within the time span that a build typically requires (modified 5 minutes apart should cover most cases).

PRs are welcome!

ElMassimo avatar Jun 07 '24 23:06 ElMassimo

Closed in 824b4ef.

ElMassimo avatar Aug 12 '24 13:08 ElMassimo