-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Revert "fix: solve issue with Cache-Control header deletion (#6991)" #7811
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
Conversation
🦋 Changeset detectedLatest commit: a6968af The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
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 |
thanks @maiieul , can we add a test for that please? (just to make sure we are not dealing with regressions in the future) |
👌 I added 4 tests. 2 for the core logic and 2 bonus ones :). |
built with Refined Cloudflare Pages Action⚡ Cloudflare Pages Deployment
|
commit: |
This reverts commit dea36be. From this PR: https://github.com/QwikDev/qwik/pull/6991/files.
What is it?
Description
fixes #7742.
Reminder of the issue – I have a repro with 3 cache layers:
/
->maxAge: 300
/one/
->maxAge: 200
/one/two/
->maxAge: 100
current issue === screenshot 1 === version 1.10 and above -> the
/one/
route with athrow redirect(...)
is cached when it hits the redirect with it's closest parent Cache-Control (in this case 300 defined in/
).previous behavior === screenshot 2 === version 1.9.1 and below (about 1 year ago) -> the
/one/
gets aCache-Control
value ofno store
because redirects are not cached by default.On all versions, the redirect target (
/one/two/
) get its properCache-Control
inherited from the closest parent.So current behavior (screenshot 1) is not good because now a
if(token) throw redirect(...)
in a middleware/routeLoader$ will always redirect when cached and token istrue
. This can lead to broken e2e tests that test redirect logic, and can also break end user experiences (user B might get cached redirect from user A if it's a server side cache).The current workaround is to add a
when you don't want to cache redirects. This is not good either because the default behavior should be
"no-store"
whereas currently it is set to the closest parentCache-Control
value and this is far from being intuitive.The problem with
(introduced in the problematic PR), is that Cache-Control will inherit the value of the closest parent, so
headers.get('Cache-Control')
will always hold aChache-Control
value from the closest parent unless told otherwise (e.g. in screenshot 1, themaxAge: 300
applied to/one/
). As the comment suggests, theCache-Control
will be set tono-store
if there is noCache-Control
at all in all the parent layouts (which is rare!). And we can't go the other way around (applyno-store
by default and aCache-Control
only if defined on the route, because (1) the route might use its ownCache-Control
that shouldn't be applied to theredirect
, (2) we can't differentiate it with the layout, and (3) I'm not even sure qwik-city can be refactored to do this because routeLoaders need to be hoisted – and that would probably be a huge refactor either way.Besides, caching a redirect doesn't seem to boost performance that much because the html is not rendered when the server hits a redirect. The only use-case we could think of was to give redirects a TTL (time to live) even after being removed from the code, but that's also a bad idea. Better change the code exactly when you want to stop the redirect ^^.
Last point: I doubt even 0.01% of qwik apps leverage redirect caching. I tagged @nelsonProusa who made the problematic PR but he has not replied to my issue. And reverting won't break E2Es or end-user experiences since it will just prevent cached redirects.
So I propose we revert for now because it was a regression in terms of E2E tests and end-user experiences. We can then work on an RFC if there is more demand for this feature. This will give us more time to get this right, also considering the
eTag
logic for V2 routeLoaders.Ideas for a proposal:
Checklist
pnpm change