The Wayback Machine - https://web.archive.org/web/20210908173304/https://github.com/angular/angular/pull/42607
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

fix(service-worker): correctly determine client ID on navigation requests #42607

Closed
wants to merge 2 commits into from

Conversation

@gkalpak
Copy link
Member

@gkalpak gkalpak commented Jun 19, 2021

The ServiceWorker assigns an app-version to a each client to ensure that all subsequent requests for a client are served using the same app-version. The assignment is done based on the client ID.

Previously, the ServiceWorker would only try to read the client's ID off of the FetchEvent's clientId property. However, for navigation requests the new client's ID will be set on resultingClientId, while clientId will either be empty or hold the ID of the client where the request initiated from. See also related discussions in w3c/ServiceWorker#870 and w3c/ServiceWorker#1266.

In theory, this could lead to the navigation request (i.e. index.html) being served from a different app-version than the subsequent sub-resource requests (i.e. assets). In practice, the likelihood of this happening is probably very low though, since it would require the latest app-version to be updated between the initial navigation request and the first sub-resource request, which should happen very shortly after the navigation request.

This commit ensures that the correct client ID is determined even for navigation requests by also taking the resultingClientId property into account.

@mary-poppins
Copy link

@mary-poppins mary-poppins commented Jun 19, 2021

@mary-poppins
Copy link

@mary-poppins mary-poppins commented Jun 19, 2021

@gkalpak gkalpak requested a review from IgorMinar Jun 19, 2021
@gkalpak gkalpak removed the request for review from IgorMinar Jun 22, 2021
gkalpak added 2 commits Jun 22, 2021
…ests

The ServiceWorker assigns an app-version to a each client to ensure that
all subsequent requests for a client are served using the same
app-version. The assignment is done based on the client ID.

Previously, the ServiceWorker would only try to read the client's ID off
of the `FetchEvent`'s `clientId` property. However, for navigation
requests the new client's ID will be set on [resultingClientId][1],
while `clientId` will either be empty or hold the ID of the client where
the request initiated from. See also related discussions in
w3c/ServiceWorker#870 and w3c/ServiceWorker#1266.

In theory, this could lead to the navigation request (i.e. `index.html`)
being served from a different app-version than the subsequent
sub-resource requests (i.e. assets). In practice, the likelihood of this
happening is probably very low though, since it would require the latest
app-version to be updated between the initial navigation request and the
first sub-resource request, which should happen very shortly after the
navigation request.

This commit ensures that the correct client ID is determined even for
navigation requests by also taking the `resultingClientId` property into
account.

[1]: https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/resultingClientId
@gkalpak gkalpak force-pushed the gkalpak:fix-sw-navigation-client-id branch from b18287d to fac611a Jun 22, 2021
@mary-poppins
Copy link

@mary-poppins mary-poppins commented Jun 22, 2021

@dylhunn dylhunn closed this in 9498da1 Jun 22, 2021
dylhunn added a commit that referenced this pull request Jun 22, 2021
…ests (#42607)

The ServiceWorker assigns an app-version to a each client to ensure that
all subsequent requests for a client are served using the same
app-version. The assignment is done based on the client ID.

Previously, the ServiceWorker would only try to read the client's ID off
of the `FetchEvent`'s `clientId` property. However, for navigation
requests the new client's ID will be set on [resultingClientId][1],
while `clientId` will either be empty or hold the ID of the client where
the request initiated from. See also related discussions in
w3c/ServiceWorker#870 and w3c/ServiceWorker#1266.

In theory, this could lead to the navigation request (i.e. `index.html`)
being served from a different app-version than the subsequent
sub-resource requests (i.e. assets). In practice, the likelihood of this
happening is probably very low though, since it would require the latest
app-version to be updated between the initial navigation request and the
first sub-resource request, which should happen very shortly after the
navigation request.

This commit ensures that the correct client ID is determined even for
navigation requests by also taking the `resultingClientId` property into
account.

[1]: https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/resultingClientId

PR Close #42607
@gkalpak gkalpak deleted the gkalpak:fix-sw-navigation-client-id branch Jun 22, 2021
gkalpak added a commit to gkalpak/angular that referenced this pull request Jul 5, 2021
Update `@angular/*` packages to latest 12.1.x versions (mainly to take
advantage of recent ServiceWorker improvements, such as angular#42607
and angular#42622).
gkalpak added a commit to gkalpak/angular that referenced this pull request Jul 5, 2021
Update `@angular/*` packages to latest 12.1.x versions (mainly to take
advantage of recent ServiceWorker improvements, such as angular#42607
and angular#42622).
gkalpak added a commit to gkalpak/angular that referenced this pull request Jul 7, 2021
Update `@angular/*` packages to latest 12.1.x versions (mainly to take
advantage of recent ServiceWorker improvements, such as angular#42607
and angular#42622).
atscott added a commit that referenced this pull request Jul 7, 2021
Update `@angular/*` packages to latest 12.1.x versions (mainly to take
advantage of recent ServiceWorker improvements, such as #42607
and #42622).

PR Close #42776
atscott added a commit that referenced this pull request Jul 7, 2021
Update `@angular/*` packages to latest 12.1.x versions (mainly to take
advantage of recent ServiceWorker improvements, such as #42607
and #42622).

PR Close #42776
@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Jul 23, 2021

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants