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

fix: break reference to state object #336

Merged
merged 1 commit into from
Jun 23, 2020
Merged

fix: break reference to state object #336

merged 1 commit into from
Jun 23, 2020

Conversation

DiskoPete
Copy link

I found and issue with rehydrating the InMemoryCache.

Since the state is retrieved as a reference here: https://github.com/nuxt-community/apollo-module/blob/master/lib/templates/plugin.js#L121

it is cleared with a call to reset there: https://github.com/nuxt-community/apollo-module/blob/master/lib/templates/plugin.js#L129

Thus also clearing the previously stored states on the nuxtState object.

I broke the reference by iterating the states and calling Object.assign on each of them, while assigning it back to the nuxtState.apollo object.

@kieusonlam kieusonlam merged commit e0035e7 into nuxt-modules:master Jun 23, 2020
@kieusonlam
Copy link
Collaborator

Thanks

@dneckel
Copy link

dneckel commented Aug 25, 2020

@kieusonlam This actually breaks SSR in Nuxt for me. I started getting "Mismatching childNodes vs. VNodes". After I rolled back to version v4.0.1-rc.1 it worked again. I determined this to be the root cause.

@maxstralka
Copy link

maxstralka commented Sep 26, 2020

@kieusonlam This actually breaks SSR in Nuxt for me. I started getting "Mismatching childNodes vs. VNodes". After I rolled back to version v4.0.1-rc.1 it worked again. I determined this to be the root cause.

OMG @dneckel thank you so much for this comment!! I was on "@nuxtjs/apollo": "4.0.1-rc.3" getting Mismatching childNodes vs. VNodes + apollo running the query a second time on client side and the side effect that all <nuxt-link> links would not work anymore.

I think I have seen the whole internet on the topic before finally finding your comment.

@DiskoPete
Copy link
Author

@dneckel sorry to hear that. Would it be possible for you to setup a small codepen/repo to reproduce the issue?

yannisgu pushed a commit to yannisgu/apollo-module that referenced this pull request Oct 15, 2020
In nuxt-modules#336 the server side rendering was broken.
The problem is that when assigning the apollo cache to the nuxt state,
in `beforeNuxtRender` the state is actually still empty.
It only works because a reference is assigned there, which is later populated.

In nuxt-modules#336  another problem was fixed: Before this fix everything which was populated in the cache before `beforeNuxtRender` was cleared.

To fix both issues I propose to remove the workaround introduced in nuxt-modules#274 for the case when the `cache` object is shared across requests.
Since the server is handling requests in parallel, its simply impossible to have a shared cache instance.
Users of `nuxtjs/apollo` need to make sure that the cache instance is not shared, there is no other way.

That's why I propose to delete this workaround code, to fix all issues at the same time.

Issue: nuxt-modules#352
@yannisgu
Copy link

@DiskoPete You can reproduce the issue by calling http://localhost:3000/normalQuery when running the normal fixture (npm run dev).

A proposal to fix it is here: #362

@farzadso
Copy link

This is still broken. Any updates on when it will be fixed?

@lustremedia
Copy link

@kieusonlam This actually breaks SSR in Nuxt for me. I started getting "Mismatching childNodes vs. VNodes". After I rolled back to version v4.0.1-rc.1 it worked again. I determined this to be the root cause.

I just rolled back to 4.0.1-rc.1 and I still have this issue!

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.

7 participants