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

Switching to node-fetch to avoid caching bugs in make-fetch-happen #2171

Merged
merged 4 commits into from Apr 13, 2020

Conversation

joeldenning
Copy link
Collaborator

I have created npm/make-fetch-happen#28 to see if there's something that can be done within make-fetch-happen to fix this. In the meantime, this workaround seems to be fine. Setting cache to reload will force a normal request and then populate the cache with the new response.

@github-actions
Copy link

github-actions bot commented Apr 10, 2020

core

File by file impact

File Transform Diff master http-304 Event
dist/system-node.cjs none -1,196,671 1,397,278 200,607 changed
gzip -410,526 461,894 51,368
brotli -264,699 308,037 43,338
extras

File by file impact

Pull request have no impact on extras files.

Generated by github pull request filesize impact

@joeldenning joeldenning changed the title Workaround from caching problem within make-fetch-happen for 304s. Workaround for caching problem within make-fetch-happen for 304s. Apr 10, 2020
return fetch(url);
return fetch(url).then(function (res) {
// Workaround for https://github.com/npm/make-fetch-happen/issues/28
return res.status === 304 ? fetch(url, { cache: 'reload' }) : res;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this effectively turns every "revalidate" into a double latency request since it will first send the revaldiation request, then immediately send a new request to get a 200. As a result it's double latency by default, which isn't ideal.

In addition, the only remaining cache case with this change is the case of there being no revalidation request - but even then I assume the headers won't be available either? That is we might still have an error case there.

Overall it seems the best approach for now might be just to revert back to node-fetch until this header caching is solved.

@@ -23,8 +23,6 @@ export function applyImportMap(loader, newMap, mapBase) {
loader[IMPORT_MAP_PROMISE] = Promise.resolve();
}

export { clearFetchCache } from './features/node-fetch.js';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this is technically a breaking change. However, I seriously doubt people will have already started using this.

If we want to avoid the breaking change, we could make this be a no-op function for now.

@joeldenning
Copy link
Collaborator Author

I have updated this to use node-fetch instead of make-fetch-happen.

Copy link
Member

@guybedford guybedford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, a break made early is not a break :)

@joeldenning joeldenning changed the title Workaround for caching problem within make-fetch-happen for 304s. Switching to node-fetch to avoid caching bugs in make-fetch-happen Apr 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants