-
Notifications
You must be signed in to change notification settings - Fork 320
Navigation preload #983
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
Navigation preload #983
Conversation
docs/index.bs
Outdated
| text: append to header list; url: concept-header-list-append | ||
| text: basic filtered response; url: concept-filtered-response-basic | ||
| text: cancel a ReadableStream; url: concept-cancel-readablestream | ||
| text: cloning the request; url: concept-request-clone |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get the feeling this is the wrong way to do this, but I'm not sure what the right way is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is. You want <a for=request>clone</a> and don't add this link at all. This whole list of terms seems basically wrong...
docs/index.bs
Outdated
| <p><a>Fetch</a> <var>preloadRequest</var>.</p> | ||
| <p>To <a>process response</a> for <var>preloadResponse</var>, run these substeps:</p> | ||
| <ol> | ||
| <li><p>If <var>preloadResponse</var>'s <a>type</a> is "<code>error</code>", reject <var>navigationPreload</var> with a <code>TypeError</code> and terminate these substeps.</li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type isn't linking up properly, but I'm not sure what the right way to do this is.
docs/index.bs
Outdated
| <li>Set <var>registration</var> to the result of running <a href="#scope-match-algorithm">Match Service Worker Registration</a> algorithm passing <var>request</var>'s <a for="request">url</a> as the argument.</li> | ||
| <li>If <var>registration</var> is null or <var>registration</var>'s <a href="#dfn-active-worker">active worker</a> is null, return null.</li> | ||
| <li>Set <var>client</var>'s <a href="#dfn-service-worker-client-active-worker">active worker</a> to <var>registration</var>'s <a href="#dfn-active-worker">active worker</a>.</li> | ||
| <li>If <var>request</var> is a <a>navigation request</a> and <var>registration</var>'s <a>navigation preload enabled flag</a> is set, and <var>request</var>'s <a>method</a> is `<code>GET</code>`, then: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@annevk this is the section I'm least confident in - it's fetch for the preload. I don't think redirects are a problem since the mode will be manual. When the redirect is sent back to the navigate algorithm it'll be associated with the original request, which won't have the header.
Having said that, that may be unexpected for same-origin redirects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's likely not a problem. Should we prefix the header so that it cannot be set through script?
docs/index.bs
Outdated
| <pre class="idl" id="navigation-preload-state"> | ||
| dictionary NavigationPreloadState { | ||
| boolean enabled = false; | ||
| DOMString headerValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be ByteString? The Fetch and XHR specs are using ByteString for HTTP header values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, it should be
docs/index.bs
Outdated
| <ol> | ||
| <li> | ||
| <p><a>Fetch</a> <var>preloadRequest</var>.</p> | ||
| <p>To <a>process response</a> for <var>navigationPreloadResponse</var>, run these substeps:</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable seems to come out of nowhere...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was using https://fetch.spec.whatwg.org/#fetch-method has a guide, and response seems to come out of nowhere there too. What's the right thing to do here, and why is fetch right to do it this way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, I guess this is fine. I should refactor this at some point to make it more clear...
docs/index.bs
Outdated
| [Constructor(DOMString type, FetchEventInit eventInitDict), Exposed=ServiceWorker] | ||
| interface FetchEvent : ExtendableEvent { | ||
| [SameObject] readonly attribute Request request; | ||
| readonly attribute Promise<Response?> preloadResponse; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong if you want to resolve it with undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to show that preloadResponse is a promise that resolves with a response or undefined. What's the right IDL in this case? "any" seems less informative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any is the only correct option here. I recommend complaining in the IDL repository. Perhaps someone can up priority of fixing that.
docs/index.bs
Outdated
| <pre class="idl" id="fetch-event-init-dictionary"> | ||
| dictionary FetchEventInit : ExtendableEventInit { | ||
| required Request request; | ||
| required Promise<Response?> preloadResponse; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would you allow null as a value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again the intent is for this to be a promise that resolves with a response or undefined.
e185219 to
adc38d8
Compare
|
@jungkees I'm happy with this now. Could you review? |
jungkees
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jakearchibald, great! Please see my comments.
|
|
||
| <section algorithm> | ||
| <h4 id="navigation-preload-manager-setheadervalue"><dfn>{{NavigationPreloadManager/setHeaderValue(value)}}</dfn></h4> | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/[=a new promise=]/a new [=promise=]/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the same, but it's "a new promise".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah.. That's right. I got it.
|
|
||
| <section algorithm> | ||
| <h4 id="navigation-preload-manager-getstate"><dfn>{{NavigationPreloadManager/getState()}}</dfn></h4> | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/[=a new promise=]/a new [=promise=]/
docs/index.bs
Outdated
| 1. Set |registration| to the result of running <a>Match Service Worker Registration</a> algorithm passing |request|'s [=request/url=] as the argument. | ||
| 1. If |registration| is null or |registration|'s <a>active worker</a> is null, return null. | ||
| 1. If |request|'s [=request/destination=] is not {{RequestDestination/"report"}}, set |reservedClient|'s <a>active service worker</a> to |registration|'s <a>active worker</a>. | ||
| 1. If |request| is a [=navigation request=] and |registration|'s [=navigation preload enabled flag=] is set, and |request|'s [=request/method=] is "`GET`", then: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
request's method is a byte sequence, so \`<code>GET</code>\` would be better.
docs/index.bs
Outdated
| 1. If |registration| is null or |registration|'s <a>active worker</a> is null, return null. | ||
| 1. If |request|'s [=request/destination=] is not {{RequestDestination/"report"}}, set |reservedClient|'s <a>active service worker</a> to |registration|'s <a>active worker</a>. | ||
| 1. If |request| is a [=navigation request=] and |registration|'s [=navigation preload enabled flag=] is set, and |request|'s [=request/method=] is "`GET`", then: | ||
| 1. Let |preloadRequest| be the result of [=request/cloning=] the request |request| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A period is missing.
docs/index.bs
Outdated
| 1. If |request|'s [=request/destination=] is not {{RequestDestination/"report"}}, set |reservedClient|'s <a>active service worker</a> to |registration|'s <a>active worker</a>. | ||
| 1. If |request| is a [=navigation request=] and |registration|'s [=navigation preload enabled flag=] is set, and |request|'s [=request/method=] is "`GET`", then: | ||
| 1. Let |preloadRequest| be the result of [=request/cloning=] the request |request| | ||
| 1. Let |preloadRequestHeaders| be |preloadRequest|'s [=request/header list=] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A period is missing.
docs/index.bs
Outdated
| 1. If |request| is a [=navigation request=] and |registration|'s [=navigation preload enabled flag=] is set, and |request|'s [=request/method=] is "`GET`", then: | ||
| 1. Let |preloadRequest| be the result of [=request/cloning=] the request |request| | ||
| 1. Let |preloadRequestHeaders| be |preloadRequest|'s [=request/header list=] | ||
| 1. Let |preloadResponseObject| be a new {{Response}} object and a new associated {{Headers}} object whose [=guard=] is "`immutable`" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be ".. new {{Response}} object associated with a new associated {{Headers}} object ..".
Please add missing periods in this algorithm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one hasn't been addressed yet? I missed that the value of the guard is just a string, so it seems it should be "<code>immutable</code>".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jakearchibald, I was confused with the markdown syntax here. If "`immutable`" works fine, that'd be good as-is.
docs/index.bs
Outdated
| 1. Let |preloadRequestHeaders| be |preloadRequest|'s [=request/header list=] | ||
| 1. Let |preloadResponseObject| be a new {{Response}} object and a new associated {{Headers}} object whose [=guard=] is "`immutable`" | ||
| 1. [=header list/Append=] to |preloadRequestHeaders| a new [=header=] whose [=header/name=] is "`Service-Worker-Navigation-Preload`" and [=header/value=] is |registration|'s [=navigation preload header value=] | ||
| 1. Set |preloadRequest|'s [=skip-service-worker flag=] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may need changes after #1025 and whatwg/fetch#435.
docs/index.bs
Outdated
| 1. Let |preloadRequest| be the result of [=request/cloning=] the request |request| | ||
| 1. Let |preloadRequestHeaders| be |preloadRequest|'s [=request/header list=] | ||
| 1. Let |preloadResponseObject| be a new {{Response}} object and a new associated {{Headers}} object whose [=guard=] is "`immutable`" | ||
| 1. [=header list/Append=] to |preloadRequestHeaders| a new [=header=] whose [=header/name=] is "`Service-Worker-Navigation-Preload`" and [=header/value=] is |registration|'s [=navigation preload header value=] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs/index.bs
Outdated
|
|
||
| A [=/service worker registration=] has an associated <dfn export>navigation preload enabled flag</dfn>. It is initially unset. | ||
|
|
||
| A [=/service worker registration=] has an associated <dfn export>navigation preload header value</dfn>, which is a DOMString. It is initially set to "<code>true</code>". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the type should be a byte sequence instead of a DOMString here. Also the initial value should be \`<code>true</code>\`.
| [SecureContext, Exposed=(Window,Worker)] | ||
| interface NavigationPreloadManager { | ||
| Promise<void> enable(); | ||
| Promise<void> disable(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The param type should be ByteString instead of DOMString.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damnit it @mattto mentioned this too - sorry for forgetting
|
|
||
| 1. Let |registration| be the [=context object=]'s associated [=/service worker registration=]. | ||
| 1. If |registration|'s [=active worker=] is null, [=reject=] |promise| with an "{{InvalidStateError}}" exception, and abort these steps. | ||
| 1. Set |registration|'s [=navigation preload enabled flag=]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should resolve with undefined I guess.
|
@jungkees excellent review, thank you. I've updated the branch. |
|
@jakearchibald, LGTM with the following points!
Please include the corresponding html file when you merge it. Thank you! |
|
@jungkees the guard setting is correct I think. "`foo`" is markdown shorthand for I'll revert the "service-workers mode" change before I merge. |
4194b32 to
d284f4c
Compare
|
@jakearchibald, with the first bullet point in the previous comment, I tried to say the following sentence might have to be changed, |
|
@jakearchibald, sorry I found some places that need editorial changes just now. Noticed them through reviewing the html output. Addressed them with this follow-up commit: a6f6a32. |
Needs review.