-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce htmx and use it to avoid full page load on Subscribe
and Follow
#28908
Conversation
…`Follow` This change introduces htmx with the hope we could use it to make Gitea more reactive while keeping our "HTML rendered on the server" approach. - Add `htmx.js` that imports `htmx.org` and initializes error toasts - Place `hx-headers='{"x-csrf-token": "{{.CsrfToken}}"}'` on the `<body>` tag so every request that htmx sends is authenticated ### Error toasts in action ![errors](https://github.com/go-gitea/gitea/assets/20454870/181a1beb-1cb8-4858-abe8-fa1fc3f5b8f3) ## Don't do a full page load when clicking the subscribe button - Refactor the form around the subscribe button into its own template - Use htmx to perform the form submission - `hx-boost="true"` to prevent the default form submission behavior of a full page load - `hx-sync="this:replace"` to replace the current request (in case the button is clicked again before the response is returned) - `hx-target="this"` to replace the form tag with the new form tag - `hx-push-url="false"` to disable a change to the URL - `hx-swap="show:no-scroll"` to preserve the scroll position - Change the backend response to return a `<form>` tag instead of a redirect to the issue page ### Before ![subscribe_before](https://github.com/go-gitea/gitea/assets/20454870/cb2439a2-c3c0-425c-8d3c-5d646b1cdc28) ### After Also shows a small request loading indicator (the indicator should be worked on further in a future change) ![subscribe_after](https://github.com/go-gitea/gitea/assets/20454870/5e71a43e-9500-42af-8118-9d6441e8dc42) ## Don't do a full page load when clicking the follow button - Use htmx to perform the button request - `hx-post="{{.ContextUser.HomeLink}}?action=follow"` to send a POST request to follow the user - `hx-target="#profile-avatar-card"` to target the card div for replacement - `hx-swap="outerHTML"` to replace the card (as opposed to its inner content) with the new card that shows the new follower count and button color - Change the backend response to return a `<div>` tag (the card) instead of a redirect to the user page ### Before ![follow_before](https://github.com/go-gitea/gitea/assets/20454870/a210b643-6e74-4ff9-8e61-d658c62edf1f) ### After ![follow_after](https://github.com/go-gitea/gitea/assets/20454870/5df04537-0dd9-4e26-a5f4-73ae11e6d976) Signed-off-by: Yarden Shoham <git@yardenshoham.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Requesting changes only so we can "block" while we gather feedback, overall I like it I think)
I like that the htmx-specific templates are also split out, it seems easier to reason about; similar to a component.
Signed-off-by: Yarden Shoham <git@yardenshoham.com>
Signed-off-by: Yarden Shoham <git@yardenshoham.com>
How to update multiple divs on one htmx request? |
|
Signed-off-by: Yarden Shoham <git@yardenshoham.com>
@jolheiser is anything else needed to remove your block? |
Feedback indicated a general interest in htmx
( #28908 (comment) ) |
Signed-off-by: Yarden Shoham <git@yardenshoham.com>
…`Follow` (go-gitea#28908) - Closes go-gitea#28880 This change introduces htmx with the hope we could use it to make Gitea more reactive while keeping our "HTML rendered on the server" approach. - Add `htmx.js` that imports `htmx.org` and initializes error toasts - Place `hx-headers='{"x-csrf-token": "{{.CsrfToken}}"}'` on the `<body>` tag so every request that htmx sends is authenticated - Place `hx-swap="outerHTML"` on the `<body>` tag so the response of each htmx request replaces the tag it targets (as opposed to its inner content) - Place `hx-push-url="false"` on the `<body>` tag so no changes to the URL happen in `<form>` tags - Add the `is-loading` class during request ### Error toasts in action ![errors](https://github.com/go-gitea/gitea/assets/20454870/181a1beb-1cb8-4858-abe8-fa1fc3f5b8f3) ## Don't do a full page load when clicking the subscribe button - Refactor the form around the subscribe button into its own template - Use htmx to perform the form submission - `hx-boost="true"` to prevent the default form submission behavior of a full page load - `hx-sync="this:replace"` to replace the current request (in case the button is clicked again before the response is returned) - `hx-target="this"` to replace the form tag with the new form tag - Change the backend response to return a `<form>` tag instead of a redirect to the issue page ### Before ![subscribe_before](https://github.com/go-gitea/gitea/assets/20454870/cb2439a2-c3c0-425c-8d3c-5d646b1cdc28) ### After ![subscribe_after](https://github.com/go-gitea/gitea/assets/20454870/6fcd77d8-7b11-40b0-af4f-b152aaad787c) ## Don't do a full page load when clicking the follow button - Use htmx to perform the button request - `hx-post="{{.ContextUser.HomeLink}}?action=follow"` to send a POST request to follow the user - `hx-target="#profile-avatar-card"` to target the card div for replacement - `hx-indicator="#profile-avatar-card"` to place the loading indicator on the card - Change the backend response to return a `<div>` tag (the card) instead of a redirect to the user page ### Before ![follow_before](https://github.com/go-gitea/gitea/assets/20454870/a210b643-6e74-4ff9-8e61-d658c62edf1f) ### After ![follow_after](https://github.com/go-gitea/gitea/assets/20454870/5bb19ae9-0d59-4ae3-b538-4c83334e4722) --------- Signed-off-by: Yarden Shoham <git@yardenshoham.com> Co-authored-by: 6543 <m.huber@kithara.com> Co-authored-by: Giteabot <teabot@gitea.io>
* origin/main: [skip ci] Updated translations via Crowdin Fix UI Spacing Errors in mirror settings (go-gitea#28990) Add htmx guidelines (go-gitea#28993) Some refactor for git http (go-gitea#28995) Fix an actions schedule bug (go-gitea#28942) Fix doc img path in profile readme (go-gitea#28994) Introduce htmx and use it to avoid full page load on `Subscribe` and `Follow` (go-gitea#28908) Fix joins in `db.Find(AndCount)` (go-gitea#28978) Update golang links to use https (go-gitea#28980) Fix google logo in security page (go-gitea#28982)
* giteaofficial/main: Revert "Speed up loading the dashboard on mysql/mariadb (go-gitea#28546)" (go-gitea#29006) Update dorny/paths-filter action (go-gitea#29003) [skip ci] Updated translations via Crowdin Fix UI Spacing Errors in mirror settings (go-gitea#28990) Add htmx guidelines (go-gitea#28993) Some refactor for git http (go-gitea#28995) Fix an actions schedule bug (go-gitea#28942) Fix doc img path in profile readme (go-gitea#28994) Introduce htmx and use it to avoid full page load on `Subscribe` and `Follow` (go-gitea#28908) Fix joins in `db.Find(AndCount)` (go-gitea#28978) Update golang links to use https (go-gitea#28980) Fix google logo in security page (go-gitea#28982) Also match weakly validated ETags (go-gitea#28957)
- following organization is broken from #28908 - add login check for the follow button in organization profile page
…`Follow` (go-gitea#28908) - Closes go-gitea#28880 This change introduces htmx with the hope we could use it to make Gitea more reactive while keeping our "HTML rendered on the server" approach. - Add `htmx.js` that imports `htmx.org` and initializes error toasts - Place `hx-headers='{"x-csrf-token": "{{.CsrfToken}}"}'` on the `<body>` tag so every request that htmx sends is authenticated - Place `hx-swap="outerHTML"` on the `<body>` tag so the response of each htmx request replaces the tag it targets (as opposed to its inner content) - Place `hx-push-url="false"` on the `<body>` tag so no changes to the URL happen in `<form>` tags - Add the `is-loading` class during request ### Error toasts in action ![errors](https://github.com/go-gitea/gitea/assets/20454870/181a1beb-1cb8-4858-abe8-fa1fc3f5b8f3) ## Don't do a full page load when clicking the subscribe button - Refactor the form around the subscribe button into its own template - Use htmx to perform the form submission - `hx-boost="true"` to prevent the default form submission behavior of a full page load - `hx-sync="this:replace"` to replace the current request (in case the button is clicked again before the response is returned) - `hx-target="this"` to replace the form tag with the new form tag - Change the backend response to return a `<form>` tag instead of a redirect to the issue page ### Before ![subscribe_before](https://github.com/go-gitea/gitea/assets/20454870/cb2439a2-c3c0-425c-8d3c-5d646b1cdc28) ### After ![subscribe_after](https://github.com/go-gitea/gitea/assets/20454870/6fcd77d8-7b11-40b0-af4f-b152aaad787c) ## Don't do a full page load when clicking the follow button - Use htmx to perform the button request - `hx-post="{{.ContextUser.HomeLink}}?action=follow"` to send a POST request to follow the user - `hx-target="#profile-avatar-card"` to target the card div for replacement - `hx-indicator="#profile-avatar-card"` to place the loading indicator on the card - Change the backend response to return a `<div>` tag (the card) instead of a redirect to the user page ### Before ![follow_before](https://github.com/go-gitea/gitea/assets/20454870/a210b643-6e74-4ff9-8e61-d658c62edf1f) ### After ![follow_after](https://github.com/go-gitea/gitea/assets/20454870/5bb19ae9-0d59-4ae3-b538-4c83334e4722) --------- Signed-off-by: Yarden Shoham <git@yardenshoham.com> Co-authored-by: 6543 <m.huber@kithara.com> Co-authored-by: Giteabot <teabot@gitea.io>
- following organization is broken from go-gitea#28908 - add login check for the follow button in organization profile page
- following organization is broken from go-gitea#28908 - add login check for the follow button in organization profile page (cherry picked from commit 6822799)
This change introduces htmx with the hope we could use it to make Gitea more reactive while keeping our "HTML rendered on the server" approach.
htmx.js
that importshtmx.org
and initializes error toastshx-headers='{"x-csrf-token": "{{.CsrfToken}}"}'
on the<body>
tag so every request that htmx sends is authenticatedhx-swap="outerHTML"
on the<body>
tag so the response of each htmx request replaces the tag it targets (as opposed to its inner content)hx-push-url="false"
on the<body>
tag so no changes to the URL happen in<form>
tagsis-loading
class during requestError toasts in action
Don't do a full page load when clicking the subscribe button
hx-boost="true"
to prevent the default form submission behavior of a full page loadhx-sync="this:replace"
to replace the current request (in case the button is clicked again before the response is returned)hx-target="this"
to replace the form tag with the new form tag<form>
tag instead of a redirect to the issue pageBefore
After
Don't do a full page load when clicking the follow button
hx-post="{{.ContextUser.HomeLink}}?action=follow"
to send a POST request to follow the userhx-target="#profile-avatar-card"
to target the card div for replacementhx-indicator="#profile-avatar-card"
to place the loading indicator on the card<div>
tag (the card) instead of a redirect to the user pageBefore
After