Repository navigation
fix(service-worker): some fixes for real-world apps - #19519
Conversation
|
You can preview a09ae1f at https://pr19519-a09ae1f.ngbuilds.io/. |
|
You can preview 83ba832 at https://pr19519-83ba832.ngbuilds.io/. |
gkalpak
left a comment
There was a problem hiding this comment.
The public API needs some changes.
(Also, how come there are no tests for the changes? 😕)
There was a problem hiding this comment.
OOC, what is the purpose of this?
There was a problem hiding this comment.
If this is supposed to only exclude /, then escaping is not necessary (since you are inside a character group): [^/]+.
There was a problem hiding this comment.
Good point. I don't mind being explicit about it though :)
There was a problem hiding this comment.
Not directly related to this PR, but is it intentional that the generated RegExp will happily match a path as long as it can match a sub-path in it. For example, the RegExp for glob /foo/**/bar.js will match /baz/foo/qux/bar.js and /foo/qux/bar.jsx.
There was a problem hiding this comment.
Yes, this is intentional. ** means "0 or more directories", * means "1 directory".
There was a problem hiding this comment.
I was referring to the fact the two example paths (/baz/foo/qux/bar.js and /foo/qux/bar.jsx) would normally not be matched by the glob; the former because of the /baz prefix and the latter because of the x suffix (in .jsx). In both paths /foo/qux/bar.js would be matched, but it will only be a substring of the whole path.
There was a problem hiding this comment.
Oh. Yes, that's expected. The expression is wrapped in^ and $ before being compiled. This function doesn't include those matchers because patterns need to be encoded into the manifest in an unwrapped state.
There was a problem hiding this comment.
Are there other glob features supported that might need escaping (e.g. {...}, [...], ^)?
There was a problem hiding this comment.
Those are intentionally not handled for now. Long-term, I'd like to switch to use a glob-to-regex library that already exists.
There was a problem hiding this comment.
Why do we need two of theses sha1 files? Is it for bundling purposes?
There was a problem hiding this comment.
Yeah, it's for build purposes. There's also a copy in Angular itself. :(
I want to extract it into a separate library at some point.
There was a problem hiding this comment.
Doesn't this need the this.bodyUsed = true; line?
There was a problem hiding this comment.
The res.url !== '' part is redundant 😁
There was a problem hiding this comment.
I am a little confused with req.url vs getConfigUrl(req.url) 😕
For example, should line 450 below use url instead? Or what kind of URLs are used when initializing an AppVersion's hashTable (and if not "parsed" URLs, why not)?
There was a problem hiding this comment.
The issue is that the config generator has no knowledge of which origin it will be running on. The SW knows its origin, but not whether requests will be made via HTTP or HTTPS.
Therefore there are two types of URLs tracked in the hashTable and other internal structures - fully qualified (with protocol, domain, and path for everything known at build time) and relative to the domain root (everything loaded from the same origin as the SW, and so not known at build time).
The URLs that come in Requests are always fully qualified. getConfigUrl will convert that fully-qualified URL to a domain-root-relative URL if the origin is the same as the SW. In other words, it determines for a given URL how it would be listed in the manifest.
In this case, it probably should use the config URL.
|
You can preview f83e2e6 at https://pr19519-f83e2e6.ngbuilds.io/. |
|
You can preview 99c7768 at https://pr19519-99c7768.ngbuilds.io/. |
|
You can preview d639ad0 at https://pr19519-d639ad0.ngbuilds.io/. |
|
You can preview 5b3ca03 at https://pr19519-5b3ca03.ngbuilds.io/. |
There was a problem hiding this comment.
a Response, an error orundefined --> a Response or undefined (right?)
There was a problem hiding this comment.
There is intentionally no await here, right?
There was a problem hiding this comment.
Correct. return foo; and return await foo; are identical.
There was a problem hiding this comment.
I don't think they are identical if this.scope.fetch(...) rejects 😕
There was a problem hiding this comment.
Is origin guaranteed to end with a /? If not, then url would end up with a a double //.
There was a problem hiding this comment.
Since this is testing code, yes it is :)
There was a problem hiding this comment.
Is this intentionally inside the while loop?
There was a problem hiding this comment.
Good point. It's only used for tests anyway - fixed.
|
You can preview 86454df at https://pr19519-86454df.ngbuilds.io/. |
5839d90 to
9be4f1d
Compare
|
You can preview 5839d90 at https://pr19519-5839d90.ngbuilds.io/. |
|
You can preview 9be4f1d at https://pr19519-9be4f1d.ngbuilds.io/. |
There was a problem hiding this comment.
can't you console.error here?
There was a problem hiding this comment.
I try to avoid console logging for the SW - it's occasionally difficult to get to the SW debugging window. I prefer to expose debugging info via a special /ngsw/* URL namespace.
IgorMinar
left a comment
There was a problem hiding this comment.
lgmt for api changes. please add tests as discussed in person.
This commit fixes several issues discovered through use in real apps. * The sha1() function operated on text content, causing issues for binary-format files. A sha1Binary() function which operates on unparsed data now avoids any encoding issues. * The characters '?' and '+' were not escaped in Glob-to-regex conversion previously, but are now. * URLs from the browser contain the full origin, but were checked against the table of hashes from the manifest which only has the path for URLs from the same origin. Now the origin is checked and URLs are relativized to the domain root before comparison if appropriate. * ngsw: prefix was missing from data groups, is now added. * Occasionally servers will return a redirected response for an asset, and caching it could cause errors for navigation requests. The SW now handles this by detecting such responses and following the redirect manually, to avoid caching a redirected response. * The request for known assets is now created from scratch from the URL before fetching from the network, in order to sanitize it and avoid carrying any special modes or headers that might result in opaque responses. * Debugging log for troubleshooting. * Avoid creating errors by returning 504 responses on error. * Fix bug where idle queue doesn't run in some circumstances. * Add tests for the above.
|
You can preview bdeb92b at https://pr19519-bdeb92b.ngbuilds.io/. |
|
|
||
| private async safeFetch(req: Request): Promise<Response> { | ||
| try { | ||
| return this.scope.fetch(req); |
There was a problem hiding this comment.
AFAICT, this should also be return await this.scope.fetch(req).
|
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. |
No description provided.