Fix CDN_HOST support in Vite configuration#12
Merged
mikehikes merged 4 commits intoforked-mainfrom Nov 12, 2025
Merged
Conversation
5adbcab to
bbea141
Compare
After upgrading to Mastodon v4.5+ which switched from Webpack to Vite,
the CDN_HOST environment variable was no longer being respected for
Vite-generated assets. This caused all dynamically imported JavaScript
chunks, emoji data files, and other assets to be loaded from the local
domain instead of the configured CDN.
Root cause: Vite's base path was hardcoded to `/${outDirName}/` in
vite.config.mts, which made all asset URLs relative to the local domain.
Vite generates these URLs at build time using import.meta.glob() and
code splitting, so they don't respect Rails' runtime config.asset_host.
Solution: Configure Vite's base option to use CDN_HOST during production
builds. The base path now uses the full CDN URL when CDN_HOST is set
and isProdBuild is true, falling back to the relative path otherwise.
This fixes asset loading for:
- JavaScript chunks (e.g., schedule_idle_task-*.js)
- Emoji data files (e.g., compact-*.json)
- CSS files and other Vite-managed assets
Note: CDN_HOST must be set as an environment variable during the
production build, not just at runtime:
export CDN_HOST=https://mastodon-static.theatl.social
yarn build:production
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
bbea141 to
f7286cf
Compare
Consolidate asset copying in Dockerfile.
This passes the CDN_HOST variable to the Docker build so that Vite can generate asset URLs with the CDN domain during compilation. Without this, the Dockerfile receives CDN_HOST but the workflow wasn't passing it, so assets were still using relative paths. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…heconnector into fix-cdn-host-vite-config
This was referenced Nov 12, 2025
mikehikes
added a commit
that referenced
this pull request
Nov 12, 2025
This commit rolls back TheConnector to Mastodon v4.5.0 by: 1. Reverting PR #12 (CDN_HOST build-time fix) 2. Reverting PR #11 (v4.6.0-alpha.1 merge) 3. Merging v4.5.0 final on top of PR #10's state This restores runtime CDN_HOST functionality that was broken by upstream commit ff5d745 (import.meta.glob for emoji loading). Version: 4.5.0-theatlsocial-20251112 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
4 tasks
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.
Summary
Fixes CDN_HOST environment variable not being respected after upgrading to Mastodon v4.5+, which switched from Webpack to Vite.
Problem
After the v4.5+ upgrade, all Vite-generated assets (JavaScript chunks, emoji data files, CSS) were being loaded from the local domain instead of the configured CDN at
mastodon-static.theatl.social.Root Cause: Vite's
basepath was hardcoded to/${outDirName}/in vite.config.mts. Since Vite generates asset URLs at build time (viaimport.meta.glob()and code splitting), these URLs don't respect Rails' runtimeconfig.asset_hostsetting.Solution
Configure Vite's
baseoption to useCDN_HOSTduring production builds:Affected Assets
This fix ensures the following assets correctly use the CDN:
schedule_idle_task-*.js)compact-*.json)Build Requirements
Important:
CDN_HOSTmust be set as an environment variable during the production build, not just at runtime:Or in Dockerfile:
Testing
After merging and rebuilding with
CDN_HOSTset:/packs/assets/compact-*.jsonbecomehttps://mastodon-static.theatl.social/packs/assets/compact-*.json🤖 Generated with Claude Code