Repository navigation
Conversation
|
You can preview 84d287d at https://pr30977-84d287d.ngbuilds.io/. |
84d287d to
d7dab23
Compare
|
You can preview d7dab23 at https://pr30977-d7dab23.ngbuilds.io/. |
IgorMinar
left a comment
There was a problem hiding this comment.
Left a few comments but otherwise lgtm. Thanks!
There was a problem hiding this comment.
access is an odd name for this const
There was a problem hiding this comment.
I didn't change this bit (just removed the surrounding if block and adjusted the indentation).
But happy to change it so something else (view sounds like a good name).
There was a problem hiding this comment.
Isn't this going to cause non-200 opaque responses to be cached?
There was a problem hiding this comment.
Yes (if okToCacheOpaque is true, which is only the case when handling a DataGroup request with freshness (i.e. network first)).
With opaque responses, one can't tell if it was successful or not (res.status is 0, thus res.ok will always be false). So, what we do is that we cache opaque responses for DataGroup requests that are configured to fetch from the network first. So, if the client is online, the SW should fetch the response from the network anyway (and not use the cache), but if the client is offline, the SW will serve the cached response. There is little risk (other than the extra memory), because the request would have failed anyway when offline.
Jasmine natively supports returning promises from spec functions for quite some time now. We don't need special async helpers.
Previously, opaque responses where handled a little differently than other responses from the mock server. More specifically, they were not tracked (so no assertions could be made for them) and their [`Body` mixin][1] methods (such as `arrayBuffer()`, `json()`, `text()`) would throw an error due to `body` being `null`. This commit ensures opaque responses are also captured on the mock server and also changes `Body` mixin methods to better simulate the [spec'd behavior][2]. (These improvements will be necessary to test caching of opaque responses in a subsequent commit.) [1]: https://developer.mozilla.org/en-US/docs/Web/API/Body [2]: https://fetch.spec.whatwg.org/#concept-body-consume-body
This commit doesn't change the behavior wrt caching, but it makes it more explicit that only non-timed-out responses are cached. In case of a timeout, `res` would be set to a programmatically created 504 `Response`, so `cacheResponse()` (which checks for `res.ok`) would not have cached it anyway, but this makes change makes it more explicit (and more similar to the equivalent part in [handleFetchWithFreshness()][1]). [1]: https://github.com/angular/angular/blob/2b4d5c754/packages/service-worker/worker/src/data.ts#L379-L388
…hness` strategy Previously, (presummably due to a typo) the `okToCacheOpaque` argument of `DataGroup#cacheResponse()` was essentially never taken into account (since opaque responses have a non-200 status code and thus `res.ok` is always false). This commit fixes the typo, which allows opaque responses to be cached when `okToCacheOpaque` is true (i.e. in data groups using the `freshness` strategy). Fixes angular#30968
At this point, the response will have been cached (or scheduled to be cached) in other code paths, so caching it again is redundant.
d7dab23 to
b8b61c7
Compare
|
You can preview b8b61c7 at https://pr30977-b8b61c7.ngbuilds.io/. |
|
Even if this is theoretically a fix, the code never worked as intended (i.e. opaque responses were never cached), so this is a change in behavior. Therefore, I marked it for |
|
Changing to |
Jasmine natively supports returning promises from spec functions for quite some time now. We don't need special async helpers. PR Close #30977
Previously, opaque responses where handled a little differently than other responses from the mock server. More specifically, they were not tracked (so no assertions could be made for them) and their [`Body` mixin][1] methods (such as `arrayBuffer()`, `json()`, `text()`) would throw an error due to `body` being `null`. This commit ensures opaque responses are also captured on the mock server and also changes `Body` mixin methods to better simulate the [spec'd behavior][2]. (These improvements will be necessary to test caching of opaque responses in a subsequent commit.) [1]: https://developer.mozilla.org/en-US/docs/Web/API/Body [2]: https://fetch.spec.whatwg.org/#concept-body-consume-body PR Close #30977
…0977) This commit doesn't change the behavior wrt caching, but it makes it more explicit that only non-timed-out responses are cached. In case of a timeout, `res` would be set to a programmatically created 504 `Response`, so `cacheResponse()` (which checks for `res.ok`) would not have cached it anyway, but this makes change makes it more explicit (and more similar to the equivalent part in [handleFetchWithFreshness()][1]). [1]: https://github.com/angular/angular/blob/2b4d5c754/packages/service-worker/worker/src/data.ts#L379-L388 PR Close #30977
…hness` strategy (#30977) Previously, (presummably due to a typo) the `okToCacheOpaque` argument of `DataGroup#cacheResponse()` was essentially never taken into account (since opaque responses have a non-200 status code and thus `res.ok` is always false). This commit fixes the typo, which allows opaque responses to be cached when `okToCacheOpaque` is true (i.e. in data groups using the `freshness` strategy). Fixes #30968 PR Close #30977
At this point, the response will have been cached (or scheduled to be cached) in other code paths, so caching it again is redundant. PR Close #30977
Previously, opaque responses where handled a little differently than other responses from the mock server. More specifically, they were not tracked (so no assertions could be made for them) and their [`Body` mixin][1] methods (such as `arrayBuffer()`, `json()`, `text()`) would throw an error due to `body` being `null`. This commit ensures opaque responses are also captured on the mock server and also changes `Body` mixin methods to better simulate the [spec'd behavior][2]. (These improvements will be necessary to test caching of opaque responses in a subsequent commit.) [1]: https://developer.mozilla.org/en-US/docs/Web/API/Body [2]: https://fetch.spec.whatwg.org/#concept-body-consume-body PR Close #30977
…0977) This commit doesn't change the behavior wrt caching, but it makes it more explicit that only non-timed-out responses are cached. In case of a timeout, `res` would be set to a programmatically created 504 `Response`, so `cacheResponse()` (which checks for `res.ok`) would not have cached it anyway, but this makes change makes it more explicit (and more similar to the equivalent part in [handleFetchWithFreshness()][1]). [1]: https://github.com/angular/angular/blob/2b4d5c754/packages/service-worker/worker/src/data.ts#L379-L388 PR Close #30977
…hness` strategy (#30977) Previously, (presummably due to a typo) the `okToCacheOpaque` argument of `DataGroup#cacheResponse()` was essentially never taken into account (since opaque responses have a non-200 status code and thus `res.ok` is always false). This commit fixes the typo, which allows opaque responses to be cached when `okToCacheOpaque` is true (i.e. in data groups using the `freshness` strategy). Fixes #30968 PR Close #30977
At this point, the response will have been cached (or scheduled to be cached) in other code paths, so caching it again is redundant. PR Close #30977
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
freshnessstrategy.service-workertests.(See individual commits for details.)
Fixes #30968.