Skip to content

Refactor htmx and fetch-action related code#37186

Merged
wxiaoguang merged 4 commits intogo-gitea:mainfrom
wxiaoguang:refactor-htmx
Apr 13, 2026
Merged

Refactor htmx and fetch-action related code#37186
wxiaoguang merged 4 commits intogo-gitea:mainfrom
wxiaoguang:refactor-htmx

Conversation

@wxiaoguang
Copy link
Copy Markdown
Contributor

@wxiaoguang wxiaoguang commented Apr 12, 2026

This is the first step (the hardest part). I have tested:

  • repo file list last commit message lazy load
  • admin server status monitor
  • watch/unwatch (normal page, watchers page)
  • star/unstar (normal page, watchers page)
  • project view, delete column
  • workflow dispatch, switch the branch
  • commit page: load branches and tags referencing this commit

The legacy "data-redirect" attribute is removed, it only makes the page reload (sometimes using an incorrect link).

Also did cleanup for some devtest pages.

Next PR will completely remove htmx without introducing so many JS code changes.

@wxiaoguang
Copy link
Copy Markdown
Contributor Author

wxiaoguang commented Apr 12, 2026

Repo file list lazy load

image

Workflow dispatch

image image

Commit page

image

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 12, 2026
@wxiaoguang wxiaoguang mentioned this pull request Apr 12, 2026
@wxiaoguang wxiaoguang force-pushed the refactor-htmx branch 3 times, most recently from b7bf493 to 4001304 Compare April 12, 2026 09:20
@wxiaoguang wxiaoguang requested a review from Copilot April 12, 2026 09:36
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

This PR is an initial refactor step to replace several htmx-driven interactions with the existing fetch-action mechanism plus a lightweight “fetch sync” DOM update path (including optional Idiomorph morphing), preparing for later removal of htmx.

Changes:

  • Reworked common-fetch-action to support sync HTML responses (data-fetch-sync) and periodic/auto triggers (data-fetch-trigger).
  • Updated templates to use data-fetch-* attributes for watch/unwatch, star/unstar, repo file list last-commit lazy loading, and admin system status refresh.
  • Removed the htmx morph extension wiring and added direct Idiomorph usage/type declarations.

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
web_src/js/globals.ts Stops loading the htmx Idiomorph extension globally.
web_src/js/features/common-fetch-action.ts Core refactor: adds sync DOM update path, triggers, and Idiomorph integration.
web_src/css/repo/home-file-list.css Tweaks loading indicator styling for file list cells.
types.d.ts Adds a local module declaration for idiomorph.
templates/repo/watch_unwatch.tmpl Switches watch/unwatch to link-action + fetch sync update.
templates/repo/star_unstar.tmpl Switches star/unstar to link-action + fetch sync update.
templates/repo/view_list.tmpl Replaces htmx last-commit lazy loading with fetch-trigger + Idiomorph sync.
templates/repo/user_cards.tmpl Replaces htmx refresh trigger with fetch-reload marker for post-sync refresh.
templates/projects/view.tmpl Renames method attribute to data-fetch-action-method.
templates/base/head.tmpl Removes hx-ext="morph" from <body>.
templates/admin/system_status.tmpl Converts system status refresh to periodic fetch trigger + Idiomorph sync.
templates/admin/dashboard.tmpl Removes wrapper htmx refresh container; uses system_status template directly.
routers/web/web.go Changes /lastcommit/* route from POST to GET.
routers/web/repo/watch.go Removes HX-Trigger response header usage.
routers/web/repo/star.go Removes HX-Trigger response header usage.
routers/web/repo/view.go Adjusts debug helper for clearing commit info (now only clears half).
eslint.config.ts Removes restricted-import entry for idiomorph/htmx since it’s no longer globally loaded.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread web_src/js/features/common-fetch-action.ts
Comment thread web_src/js/features/common-fetch-action.ts
Comment thread web_src/js/features/common-fetch-action.ts Outdated
Comment thread web_src/js/features/common-fetch-action.ts
Comment thread web_src/js/features/common-fetch-action.ts Outdated
Comment thread routers/web/repo/view.go Outdated

This comment was marked as outdated.

This comment was marked as outdated.

This comment was marked as outdated.

@wxiaoguang wxiaoguang added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Apr 12, 2026
@wxiaoguang wxiaoguang force-pushed the refactor-htmx branch 5 times, most recently from 1c3a37a to 070c065 Compare April 13, 2026 07:06
Copy link
Copy Markdown
Member

@bircni bircni left a comment

Choose a reason for hiding this comment

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

Had a look at it 👍

@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 Apr 13, 2026
Comment thread types.d.ts
Comment thread web_src/css/repo/home-file-list.css
@silverwind
Copy link
Copy Markdown
Member

Should probably add some E2E tests for the high-value mechanisms affected here. If you like I can have a look at that.

Comment thread web_src/js/features/common-fetch-action.ts Outdated
@wxiaoguang
Copy link
Copy Markdown
Contributor Author

Should probably add some E2E tests for the high-value mechanisms affected here. If you like I can have a look at that.

There will be more changes. E2E is too early. It can be added after the htmx removal.

Comment thread web_src/js/features/common-fetch-action.ts Outdated
Copy link
Copy Markdown
Member

@silverwind silverwind left a comment

Choose a reason for hiding this comment

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

Big change surface. I hope it was all tested. Next PR should include some E2E tests to solidify no chances for regressions.

@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 Apr 13, 2026
@bircni bircni added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Apr 13, 2026
@wxiaoguang wxiaoguang enabled auto-merge (squash) April 13, 2026 18:07
@wxiaoguang wxiaoguang merged commit 6bcb666 into go-gitea:main Apr 13, 2026
26 checks passed
@GiteaBot GiteaBot added this to the 1.27.0 milestone Apr 13, 2026
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Apr 13, 2026
resp.WriteHeader(http.StatusBadRequest)
return
}
resp.Header().Add("Location", redirect)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

False positive.

Actually we have a real security problem to fix in "external render helper".

-> Add test for "fetch redirect", add CSS value validation for external render #37207

@wxiaoguang wxiaoguang deleted the refactor-htmx branch April 14, 2026 03:00
zjjhot added a commit to zjjhot/gitea that referenced this pull request Apr 14, 2026
* main:
  Add comment for the design of "user activity time" (go-gitea#37195)
  fix(api): handle missing base branch in PR commits API (go-gitea#37193)
  Refactor htmx and fetch-action related code (go-gitea#37186)
  Fix encoding for Matrix Webhooks (go-gitea#37190)
  Always show owner/repo name in compare page dropdowns (go-gitea#37172)
  fix(api): handle fork-only commits in compare API (go-gitea#37185)
  Improve Contributing docs and set a release schedule (go-gitea#37109)
  Update Nix flake (go-gitea#37183)
  Remove outdated RunUser logic (go-gitea#37180)
  Refactor flash message and remove SanitizeHTML template func (go-gitea#37179)
  Indicate form field readonly via background (go-gitea#37175)
  Remove dead CSS rules (go-gitea#37173)
  Fix flaky `TestCatFileBatch/QueryTerminated` test (go-gitea#37159)
  Implement logout redirection for reverse proxy auth setups (go-gitea#36085)
  Add missing `//nolint:depguard` (go-gitea#37162)
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. topic/code-linting type/refactoring Existing code has been cleaned up. There should be no new functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants