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

Pinia throws obj.hasOwnProperty is not a function when combined with apollo #2872

Open
kyurkchyan opened this issue Jan 5, 2025 · 8 comments
Labels
need repro This issue couldn't be reproduced

Comments

@kyurkchyan
Copy link

Reproduction

https://github.com/kyurkchyan/pinia-apollo-pnpm

Steps to reproduce the bug

  1. Clone the repro repository
  2. install the dependencies using pnpm i
  3. run the project using pnpm dev
  4. observe that the main page load fails with 500 internal server error obj.hasOwnProperty is not a function

Expected behavior

The app should load successfully

Actual behavior

App load fails with obj.hasOwnProperty is not a function error

Additional information

If you switch to the without-pinia branch and try the same steps everything works

You don't even have to use any pinia store for this issue to happen. As soon as you install the pinia nuxt plugin everything breaks.

Further, if you downgrade the version of pinia to 0.5.5 everything starts working again. You can check that out inside the working-pinia branch

I've tried all of the versions that were released after 0.5.5 none of them work.

@kyurkchyan
Copy link
Author

Seems to be related with #2837

@posva
Copy link
Member

posva commented Jan 5, 2025

Can you repro without Apollo? Where is an object with null as the prototype being passed to pinia?
#2867 Should fix this

@kyurkchyan
Copy link
Author

@posva this only happens with the apollo project sample. I am not sure how else I can reproduce the issue

@octoper
Copy link

octoper commented Jan 5, 2025

I have been able to reproduce it outside of Apollo project with the following

export const useWithNullObjectStore = defineStore('with-null-object', () => {
  return {
    text: ref(Object.create(null)),
  }
})

Copy link
Member

posva commented Jan 5, 2025

Yes, and my goal is to understand why such an object in included in pinia state by Apollo.

@posva posva added the need repro This issue couldn't be reproduced label Jan 6, 2025
@octoper
Copy link

octoper commented Jan 6, 2025

I've investigated a bit and seems that's caused by how Apollo stores data in StoreWriter (ref) used in InMemoryCache, not sure exactly how everything works but it always produces a result that contains null objects.

@octoper
Copy link

octoper commented Jan 6, 2025

Also found this issue in the apollo-client repo apollographql/apollo-client#12199

@foodticket-developer
Copy link

having the same issue on my end, also using "@pinia/nuxt": "0.9.0" and "pinia": "2.3.0" + "@nuxtjs/apollo": "5.0.0-alpha.14

this was not the case with "@pinia/nuxt": "0.5.5" and "pinia": "2.2.5"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need repro This issue couldn't be reproduced
Projects
None yet
Development

No branches or pull requests

4 participants