Skip to content

useSanityQuery does not handle sanity not returning any data #1344

@nomve

Description

@nomve

Hi,

since the update to v2 and nuxt v4, we see some entries in sentry like

undefined is not an object (evaluating 'g.data.value.data')

coming from this line
https://github.com/nuxt-modules/sanity/blob/main/src/runtime/composables/useSanityQuery.ts#L166

It happens when client.fetch for whatever reason fails, so there is no value.data.value, and we can't catch it because it happens in result.then.

Anyway it happens rarely, but it would be nice if it would not crash.

Version

module: 2.0.0
nuxt: 4.2.0

Reproduction

just block the sanity domain in dev tools, and try to load another page client side

What is expected?

the error handled or at least passed to the caller

What is actually happening?

error thrown

useSanityQuery.js:114 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'data')
    at useSanityQuery.js:114:35

Steps to reproduce

Additional information

Checklist

  • I have tested with the latest Nuxt version and the issue still occurs
  • I have tested with the latest module version and the issue still occurs
  • I have searched the issue tracker and this issue hasn't been reported yet

Steps to reproduce

  1. open a nuxt page
  2. block sanity domain on the network tab of dev tools
  3. try to access another page
  4. observe the error thrown and there's not much you can do it about it

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions