Skip to content

Error When Using @nuxt/pinia v0.6.0+ with Nuxt Apollo Composables #2837

@carlosgrossi

Description

@carlosgrossi

Reproduction

https://stackblitz.com/edit/nuxt-starter-5sgmex

Steps to reproduce the bug

As soon as the server is up, on the first SSR run the "ERROR [nuxt] [request error] [unhandled] [500] obj.hasOwnProperty is not a function" will appear in the terminal and the page will display "500 internal server error"

Expected behavior

App.vue page should load with sample data retrieved from https://spacex-production.up.railway.app

Actual behavior

The browser displays an "Error 500 internal server error" message:

Screenshot 2024-11-18 at 17 14 31

The terminal shows a message "ERROR [nuxt] [request error] [unhandled] [500] obj.hasOwnProperty is not a function"

Screenshot 2024-11-18 at 17 14 58

Additional information

The error occurs when @nuxt/pinia version 0.6.0 upwards is used in conjunction with Nuxt Apollo, when one of its composables is used in <script setup> the error occurs right after receiving the queried data from the server.

I could trace the error back to the definePayloadPlugin [packages/nuxt/src/runtime/payload-plugin.ts]. This plugin calls the shouldHydrate function [packages/pinia/src/store.ts]. When used in conjunction with Nuxt Apollo’s composables, such as useAsyncQuery, the result of the query is received by the payload reducer and passed to the shouldHydrate function. ShouldHydrate then calls hasOwnProperty on the object received and the error is triggered and handled by Nuxt downstream.

Screenshot 2024-11-18 at 17 34 09

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions