Fix theme discovery and Vite dev server in dev mode#37033
Fix theme discovery and Vite dev server in dev mode#37033techknowlogick merged 15 commits intogo-gitea:mainfrom
Conversation
1. In dev mode, discover themes from source files in web_src/css/themes/ instead of relying on built assets. Custom themes are still discovered via AssetFS. 2. Move ViteDevMiddleware into ProtocolMiddlewares so it applies to both install and web routes. 3. Ensure .vite directory exists before writing the dev-port file. Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
|
Duplicate code for "handling theme files". Maybe need to think more about how to make it maintainable, and make sure the difference between dev mod and production mode won't cause regressions when building releases. |
There was a problem hiding this comment.
Pull request overview
Improve dev-mode behavior for theme discovery and Vite integration by sourcing themes from repo files, applying Vite middleware across routes, and ensuring the Vite port file can be written reliably.
Changes:
- Discover built-in themes from
web_src/css/themes/in dev mode, while still loading custom themes fromAssetFS. - Move
ViteDevMiddlewareintoProtocolMiddlewaresso it applies to both install and web routes. - Create the
.vitedirectory before writing the dev server port file.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| vite.config.ts | Ensures .vite output directory exists before writing the dev-port file. |
| services/webtheme/webtheme.go | Updates theme discovery to read source themes in dev mode and dedupe names across sources. |
| routers/web/web.go | Removes dev-only Vite middleware registration from web routes. |
| routers/common/middleware.go | Applies Vite dev middleware earlier/globally via protocol middlewares. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Extract collectThemeFiles helper to deduplicate theme file handling. In dev mode, only read source files (Vite serves them directly). In prod mode, only read from AssetFS. Remove seenNames dedup logic since the two sources no longer overlap. Log warning on ReadDir failure. Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
|
Deduplicated theme discovery and tested |
Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
Signed-off-by: silverwind <me@silverwind.io>
|
Really need to teach AI about how to use the framework to write correct code, which is the responsibility of the AI user. |
My prompt did include "reduce duplication" but I guess it didn't spot all. |
Added a label, then developers can clearly know what assets the site is using. Now, even in dev mode, site can choose between vite dev server (run it) and pre-built assets (make frontend and stop vite dev server), and can test different assets separately. |
|
|
|
|
Yeah sure. I personally use |
But it still uses your existing app.ini, which usually is "dev mode", and then use your vite dev server.
It's hard to test the assets without a "new setup" after introducing the vite dev server if there is no way to switch. |
|
pr description update with all changes. |
* main: Refactor issue sidebar and fix various problems (go-gitea#37045) Add tests for pull request's content_version in API (go-gitea#37044) Enable concurrent vitest execution (go-gitea#36998) Fix theme discovery and Vite dev server in dev mode (go-gitea#37033) bump snapcraft deps (go-gitea#37039) Expose content_version for optimistic locking on issue and PR edits (go-gitea#37035)
* origin/main: (192 commits) Fix NuGet package upload error handling (go-gitea#37074) Desaturate dark theme background colors (go-gitea#37056) Update JS dependencies and misc tweaks (go-gitea#37064) Redirect to the only OAuth2 provider when no other login methods and fix various problems (go-gitea#36901) Show workflow link (go-gitea#37070) Remove leftover `webpackChunkName` comments from codeeditor (go-gitea#37062) Update Go dependencies (go-gitea#36781) Add webhook name field to improve webhook identification (go-gitea#37025) (go-gitea#37040) Upgrade `go-git` to v5.17.2 (go-gitea#37060) Replace Monaco with CodeMirror (go-gitea#36764) Update Combine method to treat warnings as failures and adjust tests (go-gitea#37048) Raise minimum Node.js version to 22.18.0 (go-gitea#37058) Update golangci-lint to v2.11.4 (go-gitea#37059) Upgrade `golang.org/x/image` to v0.38.0 (go-gitea#37054) Increase e2e test timeouts on CI to fix flaky tests (go-gitea#37053) Refactor "org teams" page and help new users to "add member" to an org (go-gitea#37051) Refactor issue sidebar and fix various problems (go-gitea#37045) Add tests for pull request's content_version in API (go-gitea#37044) Enable concurrent vitest execution (go-gitea#36998) Fix theme discovery and Vite dev server in dev mode (go-gitea#37033) ... # Conflicts: # templates/user/dashboard/feeds.tmpl
web_src/css/themes/instead of AssetFS. In prod, use AssetFS only. Extract sharedcollectThemeFileshelper to deduplicate theme file handling.fs.ReadDirFSonLayeredFSto support theme file discovery.IsViteDevModenow performs an HTTP health check against the vite dev server instead of only checking the port file exists. Result is cached with a 1-second TTL.ViteDevMiddlewareintoProtocolMiddlewaresso it applies to both install and web routes.ViteDevModelabel in the page footer when vite dev server is active./__vite_dev_server_checkendpoint to vite dev server for the health check..vitedirectory exists before writing the dev-port file.This PR was written with the help of Claude Opus 4.6