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

Remove the service worker and ui.USE_SERVICE_WORKER option #11528

Closed
wants to merge 1 commit into from

Conversation

silverwind
Copy link
Member

We don't really gain anything from it except the client-side caching which is a problem better solved on HTTP level. Gitea is not a PWA and will not do anything useful in a offline scenario without having access to the server.

This should also resolve issues seen with the serviceworker interfering on SSE requests.

The only API we can not use without a service worker is push notifications while the "app" is closed but the more established HTML Notification API will be a alternative.

Fixes: #11092
Fixes: #8056
Fixes: #7372

We don't really gain anything from it except the client-side caching
which is a problem better solved on HTTP level. Gitea is not a PWA and
will not do anything useful in a offline scenario without having access
to the server.

This should also resolve issues seen with the serviceworker interfering
on SSE requests.

The only API we can not use without a service worker is push
notifications while the "app" is closed but the more established
HTML Notification API will be a alternative.

Fixes: go-gitea#11092
Fixes: go-gitea#8056
Fixes: go-gitea#7372
@GiteaBot GiteaBot added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label May 20, 2020
@zeripath
Copy link
Contributor

Probably this needs more than just two approvals

@CirnoT
Copy link
Contributor

CirnoT commented May 20, 2020

Might considering marking this as breaking; I'm sure people that actively use Gitea as PWA (as much as it isn't meant to be) would consider it as such.

@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 May 20, 2020
@jolheiser jolheiser added the pr/breaking Merging this PR means builds will break. Needs a description what exactly breaks, and how to fix it! label May 21, 2020
@jolheiser jolheiser added this to the 1.13.0 milestone May 21, 2020
Copy link
Member

@jolheiser jolheiser left a comment

Choose a reason for hiding this comment

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

I wonder if there is any way that this could be added back manually (without code change) for those that want it, through custom content or something similar.
I may try to play with it and add docs or contrib if this gets merged.

@6543
Copy link
Member

6543 commented May 21, 2020

plreace resolve conflict

@@ -1048,10 +1048,6 @@ func RegisterRoutes(m *macaron.Macaron) {
ctx.HTML(200, "pwa/manifest_json")
Copy link
Member

Choose a reason for hiding this comment

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

should we change this also?

@lunny
Copy link
Member

lunny commented May 21, 2020

Why not just change the default option to false?

@CirnoT
Copy link
Contributor

CirnoT commented May 21, 2020

Why not just change the default option to false?

That means we would still have and support a broken configuration; specifically with SSE request being killed by SW

@silverwind
Copy link
Member Author

I'm unsure whether to go ahead because SW cache may be more reliable than HTTP-based caches. It should have a performance advantage overall:

https://stackoverflow.com/a/47972445/808699
https://developers.google.com/web/showcase/2016/service-worker-perf

Regarding the SSE issue, I'm not sure if SW is really the source of the issues. We have it configured as a static list of resources to cache and non-matches should always hit the network.

@silverwind
Copy link
Member Author

I'll close this and follow up with a better approach to the SW (which in itselfs still seems valuable to keep for performance) using workbox with destination-based caching. This will also free us from the burden of having to manually keep that file up to date.

@silverwind silverwind closed this May 21, 2020
@CirnoT
Copy link
Contributor

CirnoT commented May 21, 2020

We have it configured as a static list of resources to cache and non-matches should always hit the network.

But the request that hits network is intercepted by SW, and SW are not supposed to be working forever; hence Firefox kills it after 30s, breaking SSE.
https://stackoverflow.com/questions/29741922/prevent-service-worker-from-automatically-stopping
https://bugzilla.mozilla.org/show_bug.cgi?id=1378587

There really should be some way to mark SSE connection so that it is never intercepted by SW in the first place, but it seems there isn't and SW dying closes SSE connection.

Do we really need to additionally burden Gitea with libraries designed for offline usage, such as workbox? They explicitly say

JavaScript Libraries for adding offline support to web apps

As far as I am concerned; and you confirmed, Gitea isn't such and won't be.

@silverwind
Copy link
Member Author

As discussed, the SSE issue should be because the SW unconditionally handled all requests. Should be fixed in #11538 which only intercepts a subset of requests.

@silverwind
Copy link
Member Author

Do we really need to additionally burden Gitea with libraries designed for offline usage, such as workbox

I'd say it's justified because when using serviceworkers, we can guarantee at least some degree of caching which is important for performance because we do have some large assets (monaco) that really benefit from it. The current workbox implementation is only 28kB, so very lightweight.

@silverwind silverwind deleted the rm-sw branch May 22, 2020 13:16
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
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. pr/breaking Merging this PR means builds will break. Needs a description what exactly breaks, and how to fix it!
Projects
None yet
8 participants