Skip to content

Avoid Service Worker update issues on localhost #1209

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

Merged
merged 1 commit into from
Apr 8, 2024

Conversation

brandonpayton
Copy link
Member

What problem is it solving?

This PR fixes #1180 - Playground on localhost sometimes fails to load due to failed service worker updates from "localhost".

How is the problem addressed?

By switching from "localhost" to the explicit loopback address "127.0.0.1". This avoids the case where "localhost" does not directly resolve to a loopback address.

For reference:
https://w3c.github.io/webappsec-secure-contexts/#localhost

Section 6.3 of [RFC6761] lays out the resolution of localhost. and names falling within .localhost. as special, and suggests that local resolvers SHOULD/MAY treat them specially. For better or worse, resolvers often ignore these suggestions, and will send localhost to the network for resolution in a number of circumstances.

Given that uncertainty, user agents MAY treat localhost names as having potentially trustworthy origins if and only if they also adhere to the localhost name resolution rules spelled out in [let-localhost-be-localhost] (which boil down to ensuring that localhost never resolves to a non-loopback address).

Testing Instructions

Run npm run dev and confirm the new dev server URL is http://127.0.0.1:5400/website-server/ and that local Playground loads successfully in your browser.

@brandonpayton brandonpayton requested a review from a team April 6, 2024 03:46
@brandonpayton
Copy link
Member Author

Note: I do not know what remoteDevServerHost is used for, but since it seems to also be used by npm run dev, I went ahead and changed that to "127.0.0.1" as well.

@adamziel
Copy link
Collaborator

adamziel commented Apr 8, 2024

Good fix @brandonpayton!

Note: I do not know what remoteDevServerHost is used for, but since it seems to also be used by npm run dev, I went ahead and changed that to "127.0.0.1" as well.

It's used for remote.html URLs.

@adamziel adamziel merged commit 6a743a2 into trunk Apr 8, 2024
5 checks passed
@adamziel adamziel deleted the avoid-local-service-worker-update-issue branch April 8, 2024 08:25
@adamziel
Copy link
Collaborator

@brandonpayton I ran into that issue again on 127.0.0.1 – could be related to a stale service worker or could be an actual problem. Nothing actionable yet. Let's keep an eye on this.

CleanShot 2024-04-11 at 13 51 07@2x

@brandonpayton
Copy link
Member Author

@adamziel I ran into the same yesterday. I thought maybe it had something to do with a stale worker originally registered under "localhost". Unregistering the service worker and reloading the page fixed the issue, which seemed different than @mho22's experience here:
#1180 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ServiceWorker cannot be started
3 participants