fix: cache mechanism for request with different headers - #8754
Rich-Harris merged 14 commits into
Conversation
🦋 Changeset detectedLatest commit: a885a67 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
You would need to update Also, I think we could probably have just a single hash computed from a combination of the headers and body |
|
Thanks! Note that const headers = new Headers();
headers.append('Authorization', `Bearer ${token}`);
fetch('/blah', { headers });...the hash will be all wrong because if (opts?.headers) {
- const headers = JSON.stringify(opts.headers);
+ const headers = [...new Headers(opts.headers)].join(',');
selector += `[data-headers-hash="${hash(headers)}"]`;
} |
| // by the time JS has run, hydration will have nuked these scripts | ||
| const script_contents_a = await page.innerHTML( | ||
| 'script[data-sveltekit-fetched][data-url="/load/serialization-post.json"][data-hash="3t25"]' | ||
| 'script[data-sveltekit-fetched][data-url="/load/serialization-post.json"][data-hash="4jrjph"]' |
There was a problem hiding this comment.
I still didn't figure out why this test is failing. I updated the hash to consider headers but it seems that the hash now it's different than the test above so maybe there is some header that I'm not considering when I hash manually.
There was a problem hiding this comment.
I found the issue, I was concatenating an ArrayBufferView + string.
To achieve this single hash computation I will need to update the hash function, I don't know if you want to do that. The other option is to concatenate the two hashes hash(headers) + hash(body)
|
thank you! |
- support caching of responses with `Vary` header (possible without any changes on the client because since #8754 we're taking headers into account for the cache key) - fix browser caching of adjacent pages/endpoints fixes #9780 --------- Co-authored-by: S. Elliott Johnson <sejohnson@torchcloudconsulting.com>
closes #8752
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.