Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/better-forks-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"next-sanity": major
---

Remove `type DraftPerspective`, `type DraftEnvironment` and `type ClientPerspective` from `import 'next-sanity/hooks'`
5 changes: 5 additions & 0 deletions .changeset/bright-jokes-stay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"next-sanity": major
---

Remove the experimental `<SanityLiveStream>` API
5 changes: 5 additions & 0 deletions .changeset/fair-rats-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"next-sanity": patch
---

Add temp debug function
5 changes: 5 additions & 0 deletions .changeset/four-jobs-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"next-sanity": major
---

Merge `next-sanity/experimental/live` export into `next-sanity/live`
5 changes: 5 additions & 0 deletions .changeset/free-hoops-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"next-sanity": patch
---

Fix missing server action
5 changes: 5 additions & 0 deletions .changeset/heavy-doors-ask.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"next-sanity": minor
---

Add `import {sanity} from 'next-sanity/cache-life'`
5 changes: 5 additions & 0 deletions .changeset/moody-news-stay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"next-sanity": patch
---

Remove `next-sanity/debug`
22 changes: 22 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"mode": "pre",
"tag": "cache-components",
"initialVersions": {
"next-sanity": "12.0.3"
},
"changesets": [
"better-forks-ring",
"bright-jokes-stay",
"fair-rats-sell",
"four-jobs-type",
"free-hoops-marry",
"heavy-doors-ask",
"moody-news-stay",
"some-towns-rush",
"tall-flies-sing",
"tender-parents-mix",
"true-dragons-wink",
"twelve-moose-work",
"yummy-bears-juggle"
]
}
5 changes: 5 additions & 0 deletions .changeset/some-towns-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"next-sanity": major
---

`sanityFetch` and `SanityLive` are replaced by `fetch` and `SanityLive`
5 changes: 5 additions & 0 deletions .changeset/tall-flies-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"next-sanity": patch
---

Dedupe `resolvePerspectiveFromCookies`
6 changes: 6 additions & 0 deletions .changeset/tender-parents-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"next-sanity": patch
---

Test pre release

5 changes: 5 additions & 0 deletions .changeset/true-dragons-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"next-sanity": patch
---

Use private import for `#isCorsOriginError`
5 changes: 5 additions & 0 deletions .changeset/twelve-moose-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"next-sanity": major
---

Removed `type DefineSanityLiveOptions`, `type DefinedSanityFetchType` and `type DefinedSanityLiveProps` type exports
5 changes: 5 additions & 0 deletions .changeset/yummy-bears-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"next-sanity": minor
---

Add `resolvePerspectiveFromCookies` export
2 changes: 1 addition & 1 deletion apps/mvp/app/(website)/PostsLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type PostsLayoutProps = {
}

export default async function Posts(props: PostsLayoutProps) {
'use cache: remote'
'use cache'

const posts = postsQuery.parse(props.data)
// oxlint-disable-next-line no-console
Expand Down
53 changes: 45 additions & 8 deletions apps/mvp/app/(website)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
'use cache'

import '../globals.css'
import {
// cookies,
draftMode,
} from 'next/headers'
import {resolvePerspectiveFromCookies, type LivePerspective} from 'next-sanity/live'
import {VisualEditing} from 'next-sanity/visual-editing'
import {refresh, updateTag} from 'next/cache'
import {cookies, draftMode} from 'next/headers'
import {Suspense} from 'react'

import {DebugStatus} from './DebugStatus'
import {FormStatusLabel} from './FormStatus'
import {SanityLive} from './live'
import {Live} from './live'
import {RefreshButton} from './RefreshButton'
// import {resolvePerspectiveFromCookies} from 'next-sanity/experimental/live'
// import {Suspense} from 'react'

async function toggleDraftMode() {
'use server'
Expand All @@ -26,13 +24,50 @@ async function toggleDraftMode() {
}
}

async function SanityLive() {
let perspective: LivePerspective = 'published'
const isDraftMode = (await draftMode()).isEnabled
if (isDraftMode) {
perspective = await resolvePerspectiveFromCookies({cookies: await cookies()})
}

return <Live perspective={perspective} />
}

export default async function RootLayout({children}: {children: React.ReactNode}) {
const isDraftMode = (await draftMode()).isEnabled
return (
<html lang="en">
<head />
<body className="px-8">
<div className="mt-8 mb-4 border p-4">
<p>Debug: {JSON.stringify({env: 'unknown'})}</p>
<form
action={async () => {
'use server'
updateTag('sanity:debug')
}}
>
<button type="submit">updateTag</button>
</form>
<form
action={async () => {
'use server'
refresh()
}}
>
<button type="submit">refresh</button>
</form>
<form
action={async () => {
'use server'
updateTag('sanity:debug')
refresh()
}}
>
<button type="submit">updateTag + refresh</button>
</form>

<p>Draft mode: {isDraftMode ? 'On' : 'Off'}</p>
{isDraftMode && <DebugStatus />}
<form action={toggleDraftMode}>
Expand All @@ -44,7 +79,9 @@ export default async function RootLayout({children}: {children: React.ReactNode}
{children}
<RefreshButton />
{isDraftMode && <VisualEditing />}
<SanityLive />
<Suspense>
<SanityLive />
</Suspense>
</body>
</html>
)
Expand Down
4 changes: 2 additions & 2 deletions apps/mvp/app/(website)/live.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {defineLive} from 'next-sanity/experimental/live'
import {defineLive} from 'next-sanity/live'

import {client} from '@/app/sanity.client'

const token = process.env.SANITY_API_READ_TOKEN!

export const {sanityFetch, SanityLive} = defineLive({
export const {fetch, Live} = defineLive({
client,
serverToken: token,
browserToken: token,
Expand Down
22 changes: 15 additions & 7 deletions apps/mvp/app/(website)/no-resolve-perspective/page.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
'use cache'

import {unstable__adapter, unstable__environment} from 'next-sanity'
import {cacheLife} from 'next/cache'
import {draftMode} from 'next/headers'
import Link from 'next/link'

import PostsLayout, {postsQuery} from '@/app/(website)/PostsLayout'

import {sanityFetch} from '../live'
import {fetch as sanityFetch} from '../live'

async function getPosts(perspective: 'drafts' | 'published') {
'use cache: remote'

cacheLife('sanity')

export default async function IndexPage() {
const isDraftMode = (await draftMode()).isEnabled
const {data} = await sanityFetch({
query: postsQuery.query,
perspective: isDraftMode ? 'drafts' : 'published',
stega: isDraftMode,
perspective,
stega: perspective !== 'published',
})
return data
}

export default async function IndexPage() {
const isDraftMode = (await draftMode()).isEnabled
const data = await getPosts(isDraftMode ? 'drafts' : 'published')

return (
<>
Expand Down
16 changes: 12 additions & 4 deletions apps/mvp/app/(website)/only-production/page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
'use cache'

import {unstable__adapter, unstable__environment} from 'next-sanity'
import {cacheLife} from 'next/cache'
import Link from 'next/link'

import PostsLayout, {postsQuery} from '@/app/(website)/PostsLayout'

import {sanityFetch} from '../live'
import {fetch as sanityFetch} from '../live'

async function getPosts() {
'use cache: remote'

cacheLife('sanity')

export default async function IndexPage() {
const {data} = await sanityFetch({
query: postsQuery.query,
perspective: 'published',
stega: false,
})
return data
}

export default async function IndexPage() {
const data = await getPosts()

return (
<>
Expand Down
28 changes: 20 additions & 8 deletions apps/mvp/app/(website)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
import {unstable__adapter, unstable__environment} from 'next-sanity'
import {resolvePerspectiveFromCookies} from 'next-sanity/experimental/live'
import {resolvePerspectiveFromCookies, type LivePerspective} from 'next-sanity/live'
import {cacheLife} from 'next/cache'
import {cookies, draftMode} from 'next/headers'
import Link from 'next/link'

import PostsLayout, {postsQuery} from '@/app/(website)/PostsLayout'

import {sanityFetch} from './live'
import {fetch as sanityFetch} from './live'

async function getPosts(perspective: LivePerspective) {
'use cache: remote'

cacheLife('sanity')

export default async function IndexPage() {
const isDraftMode = (await draftMode()).isEnabled
const perspective = isDraftMode
? await resolvePerspectiveFromCookies({cookies: await cookies()})
: 'published'
const {data, tags} = await sanityFetch({
query: postsQuery.query,
perspective,
stega: isDraftMode,
stega: perspective !== 'published',
})
return {data, tags}
}

export default async function IndexPage() {
let perspective: LivePerspective = 'published'
const isDraftMode = (await draftMode()).isEnabled
if (isDraftMode) {
perspective = await resolvePerspectiveFromCookies({cookies: await cookies()})
}

const {data, tags} = await getPosts(perspective)

return (
<>
Expand Down
32 changes: 0 additions & 32 deletions apps/mvp/app/api/revalidate-tag/route.ts

This file was deleted.

3 changes: 3 additions & 0 deletions apps/mvp/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type {NextConfig} from 'next'

import {sanity} from 'next-sanity/cache-life'

const nextConfig: NextConfig = {
// basePath: process.env.NEXT_PUBLIC_TEST_BASE_PATH,
// trailingSlash: true,
cacheComponents: true,
cacheLife: {sanity},
logging: {
fetches: {
fullUrl: false,
Expand Down
2 changes: 1 addition & 1 deletion fixtures/fail/server-only-live/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {NextConfig} from 'next'

const nextConfig: NextConfig = {
cacheComponents: true,
cacheComponents: false,
}

export default nextConfig
2 changes: 1 addition & 1 deletion fixtures/pass/server-only-live/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {NextConfig} from 'next'

const nextConfig: NextConfig = {
cacheComponents: true,
cacheComponents: false,
}

export default nextConfig
Loading