升級 Rails 8.1.3.1 並換裝 dartsass-rails - #54
Merged
Merged
Conversation
Rails 7.2 系列安全修補已於 2026-08-09 結束(見 docs/RAILS_UPGRADE_RESEARCH.md), 依官方建議逐個 minor 升級,本批次先升至 8.0.5.1 並啟用 load_defaults 8.0。 app:update 範本逐檔取捨: - 接受範本:public/ 錯誤頁與 icon、bin/setup、filter_parameter_logging(新增 cvv/cvc)、initializers/assets.rb、test.rb、development.rb 的 Rails 8 預設 (cache_store 改 memory_store、query_log_tags_enabled)、production.rb 的 silence_healthcheck_path、public_file_server 快取標頭、TaggedLogging.logger - 保留自訂:application.rb 的 Taipei 時區與 css_compressor nil workaround、 production.rb 的 assume_ssl/ALLOWED_HOSTS 與 /up host 豁免、assets.compile false、development.rb 的 sprockets assets.quiet/debug/compile、bin/brakeman (不加回 --ensure-latest)、bin/dev(沿用 Procfile.dev + foreman) - 移除範本雜訊:puma.rb 的 solid_queue plugin(本專案未用該 gem)、 production.rb 的 action_mailer default_url_options 佔位主機名、 app:update 誤帶入的三個 ActiveStorage migration(本專案無相關資料表) 驗證:bin/rails test 222 runs 全綠、test:system 13 runs 全綠、 rubocop 0 offenses、production assets:precompile exit 0、無 Rails deprecation。
接續上一批次,升到安全修補支援至 2027-10-10 的 8.1 系列,並啟用 load_defaults 8.1。 app:update 範本逐檔取捨: - 接受範本:public/ 錯誤頁、bin/rubocop 與 bin/setup(新增 --reset)、 content_security_policy 註解、development.rb 的 verbose_redirect_logs、 puma.rb 的 WEB_CONCURRENCY 說明 - 保留自訂:application.rb 的 Taipei 時區與 css_compressor nil workaround、 production.rb 的 assume_ssl/force_ssl(範本又把兩者註解掉)、 ALLOWED_HOSTS 與 /up host 豁免、assets.compile false、development.rb 的 sprockets assets.quiet/debug/compile、bin/brakeman、bin/dev - 不採用:範本新增的 bin/ci 與 config/ci.rb(與既有 GitHub Actions workflow 重複)、puma.rb 的 solid_queue plugin、action_mailer 佔位主機名、 再次誤帶入的 ActiveStorage migration schema.rb 為 8.1 的欄位字母排序一次性重排:已逐行比對確認除 Schema[7.2]→[8.1] 版本標記與 plpgsql→pg_catalog.plpgsql(8.1 改為輸出 schema 限定的擴充名稱)外,內容完全相同,無欄位增刪。 .github/workflows/ci.yml 以 .ruby-version 取版本、未寫死 Rails 版本,無需同步。 驗證:bin/rails -v 為 8.1.3.1、test 222 runs 全綠、test:system 13 runs 全綠、 rubocop 0 offenses、production assets:precompile exit 0、無 deprecation warning。
sassc/sassc-rails(libsass 綁定)上游已停止維護,換成官方 Dart Sass 實作。
沿用既有 sprockets 管線:dart-sass 將 site.scss/boss.scss 編進
app/assets/builds/,再由 sprockets 加 digest 輸出,與 tailwind.css 同路徑。
dartsass:build 已自動掛在 assets:precompile 與 test:prepare 之後,CI 無需調整。
實質不相容只有一處:dart-sass 沒有 sprockets 的 asset-url() helper,且不會
報錯,而是把 asset-url("bg.jpg") 當未知 CSS 函式原樣輸出、背景圖靜默消失。
3 處引用改為 CSS custom property(--site-bg-image/--boss-bg-image),由 layout
與 Boss 頁的 yield :head 以 image_path 注入帶 digest 的網址,兼顧 dart-sass
與資產指紋。兩份 scss 其餘語法 dart-sass 完全相容,無需改寫。
連帶處理:
- manifest.js 移除 link_directory ../stylesheets .css,避免 sprockets 自行編
scss 而找不到 sassc
- 刪除無任何引用、且 require_tree . 會把 scss 拉進 sprockets 的
app/assets/stylesheets/application.css
- Procfile.dev 補上 dartsass:watch
- 移除 config.assets.css_compressor = nil workaround(libsass 不再參與;實測
production precompile 後 tailwind.css digest 與移除前相同,確認無壓縮器介入)
- Gemfile.lock 的 BUNDLED WITH 對齊實際執行的 bundler 2.7.2,清掉
dartsass:build 子行程造成的 Gem::Platform 重複定義警告
- brakeman.ignore 移除 EOLRails 條目(升級後該警告已消失)
- README 技術棧、ARCHITECTURE「CSS 編譯器」節、UI_STYLE_GUIDE、REFACTOR_PLAN
同步改寫;RAILS_UPGRADE_RESEARCH 補上實作附錄
驗證:test 222 runs 全綠、test:system 13 runs 全綠、rubocop 0 offenses、
brakeman exit 0 且 0 ignored、production assets:precompile exit 0、
db:drop→db:prepare→db:seed×2 冪等、dev server root 200 + demo 登入 302,
首頁與 Boss 戰畫面實際目視確認背景圖與版面正常。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
需求說明
Rails 7.2 已於 2026-08-09 完全 EOL(安全修補停止)。依
docs/RAILS_UPGRADE_RESEARCH.md官方查證:跳過只剩兩個月支援的 8.0、直上 8.1.3.1(安全修補至 2027-10-10),並順勢兌現 README 掛載已久的 sassc→dartsass 換裝。變更內容(3 commits)
app:update逐檔取捨(範本兩度覆蓋assume_ssl/force_ssl/hosts 豁免/時區等自訂設定,均已復原並記錄於 commit message 與研究文件附錄)、load_defaults 8.0、deprecation 清零load_defaults 8.1、schema 欄位字母排序的一次性重排asset-url()且靜默失效——3 處改為 layout 以image_path注入 CSS 變數,兼顧指紋與相容;移除 libsass 的css_compressor = nilworkaround;brakeman 的 EOLRails ignore 隨升級移除(回到真零警告)測試確認
bin/rails test:222 runs, 1044 assertions, 0 failures;test:system:13 runs, 0 failures