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

[nuxt] Could not access sanity. The only available runtime config keys on the client side are public and app. #1059

Open
simonhrogers opened this issue Sep 23, 2024 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@simonhrogers
Copy link

Hi there – apologies in advance, as I don’t think this is a high-quality question, but can’t find anything addressing it through the docs or issues here. I’m hoping its a relatively straightforward misunderstanding that I’m building with?

I’m seeing this warning wherever I call useSanity in my Nuxt 1.13.1 app. It’s also followed me through every version of Nuxt 3 I’ve had installed from 3.0.0 all the way up.

I’d like to try and resolve it, as I think it might be tied up with hydration issues I’m experiencing with aspects it affects further down the chain. The strange thing is, if I console.log the config returned by useSanity, it’s correct and exactly as I’d expect.

I’ve seen the warning referenced in other open issues e.g. #920, and while the url builder is one such area I get this warning, I’ve since managed to avoid it by calling useSanity outside of a plugin.

So here are two areas I know the warning arises:

– useSanity called within a plugin
– useSanityQuery called within a pinia store, e.g. stores/MainStore.js

The following starter could be used as a good indication of my setup, I will only have found ways to make Julian’s brilliant work dramatically worse :-)

https://github.com/jjjuulliiaann/sanity-nuxt-3-starter

[nuxt] Could not access `sanity`. The only available runtime config keys on the client side are `public` and `app`. See https://nuxt.com/docs/guide/going-further/runtime-config for more information.
@simonhrogers simonhrogers added the question Further information is requested label Sep 23, 2024
@rdunk rdunk self-assigned this Sep 28, 2024
@gluharry
Copy link

gluharry commented Oct 1, 2024

+1
I dont remember seeing this a couple weeks/months back. Its something new and as far as I understand, its happening because useSanityQuery tries to access runtimeConfig.sanity, which is not accessible during runtime, only .public is.

Im not sure why it was working before now that I think of it

@rdunk
Copy link
Collaborator

rdunk commented Oct 2, 2024

Looks like this warning was introduced in nuxt/nuxt#26441 and was released in v3.12.0.

Without re-familiarising myself too much, I assume it's because we run something like this in useSanity

const $config = useRuntimeConfig()
defu($config.sanity, $config.public.sanity)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants