Skip to content

Fix theme discovery and Vite dev server in dev mode#37033

Merged
techknowlogick merged 15 commits intogo-gitea:mainfrom
silverwind:vitetheme
Mar 30, 2026
Merged

Fix theme discovery and Vite dev server in dev mode#37033
techknowlogick merged 15 commits intogo-gitea:mainfrom
silverwind:vitetheme

Conversation

@silverwind
Copy link
Copy Markdown
Member

@silverwind silverwind commented Mar 29, 2026

  1. In dev mode, discover themes from source files in web_src/css/themes/ instead of AssetFS. In prod, use AssetFS only. Extract shared collectThemeFiles helper to deduplicate theme file handling.
  2. Implement fs.ReadDirFS on LayeredFS to support theme file discovery.
  3. IsViteDevMode now 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.
  4. Refactor theme caching from mutex to atomic pointer with time-based invalidation, allowing themes to refresh when vite dev mode state changes.
  5. Move ViteDevMiddleware into ProtocolMiddlewares so it applies to both install and web routes.
  6. Show a ViteDevMode label in the page footer when vite dev server is active.
  7. Add /__vite_dev_server_check endpoint to vite dev server for the health check.
  8. Ensure .vite directory exists before writing the dev-port file.
  9. Minor CSS fixes: footer gap, navbar mobile alignment.

This PR was written with the help of Claude Opus 4.6

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 29, 2026
@silverwind silverwind marked this pull request as draft March 29, 2026 18:55
@github-actions github-actions bot added modifies/go Pull requests that update Go code modifies/frontend labels Mar 29, 2026
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>
@wxiaoguang
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 from AssetFS.
  • Move ViteDevMiddleware into ProtocolMiddlewares so it applies to both install and web routes.
  • Create the .vite directory 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>
@silverwind silverwind marked this pull request as ready for review March 30, 2026 08:44
@silverwind
Copy link
Copy Markdown
Member Author

silverwind commented Mar 30, 2026

Deduplicated theme discovery and tested make clean-all watch, works.

Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
@wxiaoguang
Copy link
Copy Markdown
Contributor

Really need to teach AI about how to use the framework to write correct code, which is the responsibility of the AI ​​user.

@silverwind
Copy link
Copy Markdown
Member Author

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.

@github-actions github-actions bot added the modifies/templates This PR modifies the template files label Mar 30, 2026
@wxiaoguang
Copy link
Copy Markdown
Contributor

and make sure the difference between dev mod and production mode won't cause regressions when building releases.

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.

@silverwind
Copy link
Copy Markdown
Member Author

make frontend one-time works I guess, it's not as convenient as the dev server, but it's acceptable to me, I personally would only use make watch.

@wxiaoguang
Copy link
Copy Markdown
Contributor

make frontend one-time works I guess, it's not as convenient as the dev server, but it's acceptable to me, I personally would only use make watch.

make frontend is the only way to check whether the assets work in production without a full build and new setup. I think it is useful to debug some potential problems in the future.

@silverwind
Copy link
Copy Markdown
Member Author

Yeah sure. I personally use TAGS=bindata make clean-all build && ./gitea to test the prod build, but it's the same outcome.

@wxiaoguang
Copy link
Copy Markdown
Contributor

wxiaoguang commented Mar 30, 2026

Yeah sure. I personally use TAGS=bindata make clean-all build && ./gitea to test the prod build, but it's the same outcome.

But it still uses your existing app.ini, which usually is "dev mode", and then use your vite dev server.

..... whether the assets work in production without a full build and new setup. ....

It's hard to test the assets without a "new setup" after introducing the vite dev server if there is no way to switch.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 30, 2026
@silverwind
Copy link
Copy Markdown
Member Author

pr description update with all changes.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 30, 2026
@techknowlogick techknowlogick enabled auto-merge (squash) March 30, 2026 14:22
@silverwind silverwind added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 30, 2026
@techknowlogick techknowlogick merged commit 612ce46 into go-gitea:main Mar 30, 2026
26 checks passed
@GiteaBot GiteaBot added this to the 1.26.0 milestone Mar 30, 2026
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 30, 2026
@silverwind silverwind deleted the vitetheme branch March 30, 2026 15:09
@lunny lunny added the skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. label Mar 30, 2026
zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 31, 2026
* 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)
silverwind added a commit to silverwind/gitea that referenced this pull request Apr 2, 2026
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/frontend modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants