Skip to content
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

Add fetch wrappers, ignore network errors in actions view #26985

Merged
merged 17 commits into from
Sep 11, 2023

Conversation

silverwind
Copy link
Member

@silverwind silverwind commented Sep 9, 2023

  1. Introduce lightweight fetch wrapper functions that automatically sets csfr token, content-type and use it in RepoActionView.vue.
  2. Fix a specific issue on RepoActionView.vue where a fetch network error is shortly visible during page reload sometimes. It can be reproduced by F5-in in quick succession on the actions view page and was also producing a red error box on the page.

Once approved, we can replace all current fetch uses in UI with this in another PR.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Sep 9, 2023
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 9, 2023
@github-actions github-actions bot added the topic/ui Change the appearance of the Gitea UI label Sep 9, 2023
@silverwind silverwind added type/refactoring Existing code has been cleaned up. There should be no new functionality. skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. labels Sep 9, 2023
@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 9, 2023
@silverwind
Copy link
Member Author

silverwind commented Sep 9, 2023

I rewrote these fetches to be parallel, so the actions page will also load like 60ms+ faster now:

image

@github-actions github-actions bot added the type/docs This PR mainly updates/creates documentation label Sep 9, 2023
contentType = 'multipart/form-data';
body = data;
} else if (data instanceof URLSearchParams) {
contentType = 'application/x-www-form-urlencoded';
Copy link
Contributor

@wxiaoguang wxiaoguang Sep 10, 2023

Choose a reason for hiding this comment

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

multipart/form-data could be always the correct content type (well, without a file, application/x-www-form-urlencoded might be simpler)

While I do not see why it should support URLSearchParams, the URLSearchParams should mainly used for URL query string, but not a POST request.

(not blocker)

Copy link
Member Author

@silverwind silverwind Sep 11, 2023

Choose a reason for hiding this comment

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

Does the backend actually support both encodings interchangbly? Normal form behaviour is application/x-www-form-urlencoded for forms not containing a file, and I think the cleanest way for these is to encode them as URLSearchParams which ensures escaping is correct etc:

https://stackoverflow.com/questions/35325370/how-do-i-post-a-x-www-form-urlencoded-request-using-fetch

@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 Sep 10, 2023
@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 Sep 11, 2023
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Sep 11, 2023
@silverwind silverwind merged commit 6d96f0b into go-gitea:main Sep 11, 2023
@GiteaBot GiteaBot added this to the 1.22.0 milestone Sep 11, 2023
@silverwind silverwind deleted the fetch branch September 11, 2023 08:25
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Sep 11, 2023
zjjhot added a commit to zjjhot/gitea that referenced this pull request Sep 12, 2023
* upstream/main:
  Add more package registry paths to the labeler (go-gitea#27032)
  Extract auth middleware from service (go-gitea#27028)
  S3: log human readable error on connection failure (go-gitea#26856)
  [skip ci] Updated translations via Crowdin
  Fix "delete" modal dialog for issue/PR (go-gitea#27015)
  Fix context cache bug & enable context cache for dashabord commits' authors (go-gitea#26991)
  fix: typo (go-gitea#27009)
  Use secure cookie for HTTPS sites (go-gitea#26999)
  Add fetch wrappers, ignore network errors in actions view (go-gitea#26985)
### Fetching data

To fetch data, use the wrapper functions `GET`, `POST` etc. from `modules/fetch.js`. They
accept a `data` option for the content, will automatically set CSFR token and return a
Copy link
Member

Choose a reason for hiding this comment

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

CSRF

Copy link
Member Author

Choose a reason for hiding this comment

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

Will fix this in followup #27026.


return fetch(url, {
headers: {
'x-csrf-token': csrfToken,
Copy link
Member

Choose a reason for hiding this comment

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

Are headers case-insensitive?
I've only seen them be called X-Csrf-Token yet…

Copy link
Member Author

@silverwind silverwind Sep 13, 2023

Choose a reason for hiding this comment

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

Yes, HTTP headers by definition are to be treated case-insensitive while reading them and in fact we should lowercase them all everywhere.

In HTTP2 the common headers are transferred via a mapping table that outputs lowercase: https://datatracker.ietf.org/doc/html/rfc7541#appendix-A

@delvh delvh modified the milestones: 1.22.0, 1.21.0 Sep 13, 2023
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Dec 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. topic/ui Change the appearance of the Gitea UI type/docs This PR mainly updates/creates documentation 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