nuxt-modules / nuxt-modules/sanity

Set privateRuntimeConfig for cdn use

Open
#69 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
265
Forks
43
Avg merge
11h
Merged PRs (30d)
18

Description

When using Nuxt in SPR mode, like …

export default {
	ssr: true,
	target: 'static',
	…
}

(in nuxt.config.js)

… and using Sanity with useCdn: true, content is not immediately updated, when running/triggering nuxt generate/npm run generate.

Fyi: At the Sanity dashboard you can configure web hooks, that are triggered when content changes. So usually you would trigger nuxt generate at this place.

The problem is: When using useCdn: true, we’ll get a cached response, that is not up to date. This is why we need to achieve useCdn being set to false while generating.

Overriding useCdn inside privateRuntimeConfig will solve the problem.

sanity: {
	projectId: process.env.SANITY_PROJECT_ID,
	dataset: 'production',
	useCdn: true,
},

privateRuntimeConfig: {
	sanity: {
		useCdn: false,
	},
},

(in nuxt.config.js)

So I was wondering why this isn’t the default behaviour?
Or at least add this to the docs?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Nuxt configuration shown in nuxt.config.js and trace how privateRuntimeConfig is applied during nuxt generate or npm run generate. Check how the Sanity useCdn setting is resolved for static generation, then verify that generation uses useCdn: false while normal runtime use remains unchanged; if that is not appropriate, document the required configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxtjs, typescript
Domain
build-system
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.