apollo icon indicating copy to clipboard operation
apollo copied to clipboard

Using Apollo-module in middleware cause HTML to grow up

Open LuXDAmore opened this issue 5 years ago • 12 comments

Version

v4.0.0-rc.12

Reproduction link

nuxt-apollo-middleware

Steps to reproduce

Install apollo-module for Nuxt; Use a query from 'apollo' in a middle-ware.

What is expected ?

The HTML doesn't not have to grow up on every navigation.

What is actually happening?

The HTML grow up since ~ 100 MB.

Additional comments?

Using apollo.cache.data.clear(); before the apollo.query() remove the issue. I've tried to remove the cache in the default-config, but without success.

(In my project i need in-cache-memory because i have some Fragments, but unfortunately i don't have a valid example for that.)

This bug report is available on Nuxt community (#c234)

LuXDAmore avatar Sep 04 '19 14:09 LuXDAmore

Can we test if this issue still exists?

kieusonlam avatar Oct 24 '19 13:10 kieusonlam

@kieusonlam I think this is related https://github.com/nuxt-community/apollo-module/issues/273

tarunmangukiya avatar Oct 25 '19 18:10 tarunmangukiya

I've seen clearing apollo cacahe app.apolloProvider.defaultClient.cache.data.clear() in nuxtServerInit, helps with this. @kieusonlam any idea about this?

Also, this issue seems there in the production, in development it's not there.

tarunmangukiya avatar Oct 28 '19 03:10 tarunmangukiya

Hey @LuXDAmore, can you check this bug with https://github.com/nuxt-community/apollo-module/pull/274 PR?

tarunmangukiya avatar Oct 28 '19 13:10 tarunmangukiya

I've made this comment in the review (after it was merged though):

Wouldn't it be better to configure InMemoryCache to not cache in the first place?

Author of the issue said:

I've tried to remove the cache in the default-config, but without success.

So I wonder what have you tried @LuXDAmore

rchl avatar Oct 30 '19 10:10 rchl

@rchl I'm using inMemoryCache, there's another thread here

@tarunmangukiya To keep page size small i've added apollo.cache.data.clear(); after every request in a middleware here.. So, your PR seems good! Thank you! 🚀

LuXDAmore avatar Oct 30 '19 11:10 LuXDAmore

@LuXDAmore I'm using configuration like this:

            defaultOptions: {
                query: {
                    fetchPolicy: 'no-cache',
                    errorPolicy: 'all',
                },
            },

and it works to disable cache. In you message you seem to use $query instead of query.

rchl avatar Oct 30 '19 12:10 rchl

@rchl I've read about it here.. But yes, i've tried without too.. Maybe it's something related to the fact that it's in a middle-ware 🤷‍♂

LuXDAmore avatar Oct 30 '19 12:10 LuXDAmore

Unfortunately, I can't reproduce the initial problem with your test repo (tried with yarn start in production, on Node 10) so I can't test it out myself and see if I could make it work. Reloading page doesn't make response size to grow...

I think it's wasteful to let apollo cache stuff if it's cleared anyway.

rchl avatar Oct 30 '19 12:10 rchl

I think changing fetchPolicy won't help much as we need to use caching in case of process.client.

Regarding, I think we're forcefully using InMemoryCache even if that's not defined in apollo-config.

I've tried to remove the cache in the default-config, but without success.

https://github.com/nuxt-community/apollo-module/blob/a8882162edbeaed9bdf8ca4db44b3d24e5a37f1d/lib/templates/plugin.js#L47

tarunmangukiya avatar Oct 30 '19 12:10 tarunmangukiya

But plugin runs on both client and server and configuration for each can differ

rchl avatar Oct 30 '19 12:10 rchl

Yes, we can do that manually, but I think that's not good idea. As it should be there in the package itself.

tarunmangukiya avatar Oct 30 '19 12:10 tarunmangukiya