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

Don't set fetchOptions when request.mode is 'navigate' #1862

Merged
merged 1 commit into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/workbox-core/_private/fetchWrapper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,8 @@ const wrappedFetch = async ({
let fetchResponse;

// See https://github.com/GoogleChrome/workbox/issues/1796
if (request.mode === 'navigate' && fetchOptions &&
Object.keys(fetchOptions).length > 0) {
pluginFilteredRequest = new Request(request, {mode: 'same-origin'});
fetchResponse = await fetch(pluginFilteredRequest, fetchOptions);
if (request.mode === 'navigate') {
fetchResponse = await fetch(request);
} else {
fetchResponse = await fetch(request, fetchOptions);
}
Expand Down
7 changes: 4 additions & 3 deletions test/workbox-core/node/_private/test-fetchWrapper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ describe(`workbox-core fetchWrapper`, function() {
expect(fetchOptions).to.deep.equal(exampleOptions);
});

it(`should convert 'navigate' requests to 'same-origin' when fetchOptions is used`, async function() {
it(`should ignore fetchOptions when request.mode === 'navigate'`, async function() {
// See https://github.com/GoogleChrome/workbox/issues/1796
const fetchStub = sandbox.stub(global, 'fetch').resolves(new Response());

const fetchOptions = {
Expand All @@ -90,8 +91,8 @@ describe(`workbox-core fetchWrapper`, function() {
expect(fetchStub.calledOnce).to.be.true;
expect(fetchStub.firstCall.args[0]).to.be.instanceOf(Request);
expect(fetchStub.firstCall.args[0].url).to.eql(request.url);
expect(fetchStub.firstCall.args[0].mode).to.eql('same-origin');
expect(fetchStub.firstCall.args[1]).to.eql(fetchOptions);
expect(fetchStub.firstCall.args[0].mode).to.eql('navigate');
expect(fetchStub.firstCall.args[1]).not.to.exist;
});

it(`should call requestWillFetch method in plugins and use the returned request`, async function() {
Expand Down