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

Data cache not functioning since 3.3.1 #75

Open
maciej-baruch opened this issue Sep 26, 2024 · 3 comments
Open

Data cache not functioning since 3.3.1 #75

maciej-baruch opened this issue Sep 26, 2024 · 3 comments

Comments

@maciej-baruch
Copy link

maciej-baruch commented Sep 26, 2024

Hey.
I noticed that my data cache stopped functioning ever since I upgraded to 3.3.3 (from 3.2). I went through the code, debugged some, did some testing by myself and I feel like I found an issue.
When an event is extended in the 'request' nitro hook, any changes introduced to the event are lost, only event.context changes persist:
image

FYI - I am doing SSR in SWR mode (no pregenaration).

Apparently Nitro might create new events through lifecycle and it won't be able to copy over keys that it is not aware of.
This might also happen in middlewares.

Would you welcome a PR that puts stuff on event.context instead of just event?

@maciej-baruch maciej-baruch changed the title Data cache not functioning since 3.3 Data cache not functioning since 3.3.1 Sep 26, 2024
@dulnan
Copy link
Owner

dulnan commented Oct 18, 2024

I was under the impression that whenever a new event is created (for example when using $fetch in a component to get some data from a server handler) that the hooks that add the cache context are also called again. But I could be wrong here.

Originally, the context was actually set on event.context but I changed this in #65, because it was leaking across the lifecycle. For example, when using useRouteCache() inside a server handler that is called from within a page component, you would actually set the cacheability for both the server route and the page itself, since it's a single context object that is now shared in both cases.

Could you tell me in what scenario exactly the data cache was not working? I assume it's not generally not working, right? The data cache feature is covered by several E2E tests; I would be quite shocked if it works in tests but doesn't work in actual installations.

@dulnan
Copy link
Owner

dulnan commented Oct 19, 2024

I updated to the latest Nuxt version in the module and ran the tests; and indeed a ton of tests started to fail, including one's for the data cache. So the data cache (and likely all caches) are broken. Not sure if its related to event.context, but I will investigate and hopefully find a fix.

Turns out this was just a configuration error in the module's tests. After fixing, all tests are green.

I assume it has to do with using the swr route rule. I will try this out now.

@dulnan
Copy link
Owner

dulnan commented Oct 19, 2024

I can reproduce the issue by using swr: true on a route that uses the data cache. Let's see if there's a way to fix this without breaking non-swr behaviour...

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

No branches or pull requests

2 participants