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

Make packages compatible with next 15 and react 19 #98

Merged
merged 1 commit into from
Oct 22, 2024
Merged
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
8 changes: 8 additions & 0 deletions .changeset/shaggy-needles-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@tinloof/sanity-studio": minor
"@tinloof/sanity-web": minor
"vite-studio": minor
"next-non-embedded-studio": minor
---

Support Next 15 and React 19
13 changes: 9 additions & 4 deletions apps/next/app/(website)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
import { Metadata } from 'next'
import { draftMode } from 'next/headers'
import { VisualEditing } from 'next-sanity'
import { revalidatePath, revalidateTag } from 'next/cache'
import { draftMode } from 'next/headers'

import config from '@/config'

export const metadata: Metadata = {
title: `${config.siteName} - Website`,
}

export default function Layout({ children }: { children: React.ReactNode }) {
export default async function Layout({
children,
}: {
children: React.ReactNode
}) {
const isDraftModeEnabled = (await draftMode()).isEnabled
return (
<>
{children}
{draftMode().isEnabled && (
{isDraftModeEnabled && (
<VisualEditing
refresh={async (payload) => {
'use server'
if (!draftMode().isEnabled) {
if (!isDraftModeEnabled) {
console.debug(
'Skipped manual refresh because draft mode is not enabled',
)
Expand Down
4 changes: 2 additions & 2 deletions apps/next/app/api/disable-draft/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { draftMode } from 'next/headers'
import { NextRequest, NextResponse } from 'next/server'

export function GET(request: NextRequest) {
draftMode().disable()
export async function GET(request: NextRequest) {
;(await draftMode()).disable()
const url = new URL(request.nextUrl)
return NextResponse.redirect(new URL('/', url.origin))
}
2 changes: 1 addition & 1 deletion apps/next/app/api/draft/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function GET(request: Request) {
return new Response('Invalid secret', { status: 401 })
}

draftMode().enable()
;(await draftMode()).enable()

redirect(redirectTo)
}
6 changes: 3 additions & 3 deletions apps/next/data/sanity/loadQuery.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { QueryParams } from 'next-sanity'
import type { UnfilteredResponseQueryOptions } from '@sanity/client'
import type { QueryParams } from 'next-sanity'

import { draftMode } from 'next/headers'
import 'server-only'

import { client } from '@/data/sanity/client'
import config from '@/config'
import { client } from '@/data/sanity/client'

const DEFAULT_PARAMS = {} as QueryParams

Expand All @@ -16,7 +16,7 @@ export async function loadQuery<QueryResponse>({
query: string
params?: QueryParams
}): Promise<QueryResponse> {
const isDraftMode = draftMode().isEnabled
const isDraftMode = (await draftMode()).isEnabled
const token = config.sanity.token

if (isDraftMode && !token) {
Expand Down
14 changes: 7 additions & 7 deletions apps/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"scripts": {
"build": "next build",
"dev": "next -p 9999",
"dev": "next -p 9999 --turbo",
"format": "npx prettier --write . --ignore-path .gitignore",
"lint": "next lint -- --ignore-path .gitignore",
"lint:fix": "npm run format && npm run lint -- --fix",
Expand All @@ -26,14 +26,14 @@
"lucide-react": "^0.453.0",
"next": "15.0.0",
"next-sanity": "^9.7.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"sanity": "^3.61.0",
"react": "19.0.0-rc-65a56d0e-20241020",
"react-dom": "19.0.0-rc-65a56d0e-20241020",
"sanity": "^3.62.0",
"server-only": "0.0.1"
},
"devDependencies": {
"@types/react": "npm:types-react@19.0.0-rc.1",
"@types/react-dom": "npm:types-react-dom@19.0.0",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.1",
"autoprefixer": "10.4.20",
"eslint": "^8.57.0",
"eslint-config-next": "15.0.0",
Expand All @@ -47,5 +47,5 @@
"tailwindcss": "3.4.14",
"typescript": "^5.6.3"
},
"version": null
"version": "1.0.0"
}
3 changes: 2 additions & 1 deletion apps/studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-is": "^18.3.1",
"sanity": "^3.61.0",
"sanity": "^3.62.0",
"styled-components": "^6.1.13"
},
"devDependencies": {
"@sanity/eslint-config-studio": "^4.0.0",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.1",
"eslint": "^8.57.0",
"prettier": "^3.3.3",
"typescript": "^5.6.3"
Expand Down
13 changes: 9 additions & 4 deletions examples/hello-world/app/(website)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
import { Metadata } from 'next'
import { draftMode } from 'next/headers'
import { VisualEditing } from 'next-sanity'
import { revalidatePath, revalidateTag } from 'next/cache'
import { draftMode } from 'next/headers'

import config from '@/config'

export const metadata: Metadata = {
title: `${config.siteName} - Website`,
}

export default function Layout({ children }: { children: React.ReactNode }) {
export default async function Layout({
children,
}: {
children: React.ReactNode
}) {
const isDraftModeEnabled = (await draftMode()).isEnabled
return (
<>
{children}
{draftMode().isEnabled && (
{isDraftModeEnabled && (
<VisualEditing
refresh={async (payload) => {
'use server'
if (!draftMode().isEnabled) {
if (!isDraftModeEnabled) {
console.debug(
'Skipped manual refresh because draft mode is not enabled',
)
Expand Down
4 changes: 2 additions & 2 deletions examples/hello-world/app/api/disable-draft/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { draftMode } from 'next/headers'
import { NextRequest, NextResponse } from 'next/server'

export function GET(request: NextRequest) {
draftMode().disable()
export async function GET(request: NextRequest) {
;(await draftMode()).disable()
const url = new URL(request.nextUrl)
return NextResponse.redirect(new URL('/', url.origin))
}
2 changes: 1 addition & 1 deletion examples/hello-world/app/api/draft/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function GET(request: Request) {
return new Response('Invalid secret', { status: 401 })
}

draftMode().enable()
;(await draftMode()).enable()

redirect(redirectTo)
}
6 changes: 3 additions & 3 deletions examples/hello-world/data/sanity/loadQuery.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { QueryParams } from 'next-sanity'
import type { UnfilteredResponseQueryOptions } from '@sanity/client'
import type { QueryParams } from 'next-sanity'

import { draftMode } from 'next/headers'
import 'server-only'

import { client } from '@/data/sanity/client'
import config from '@/config'
import { client } from '@/data/sanity/client'

const DEFAULT_PARAMS = {} as QueryParams

Expand All @@ -16,7 +16,7 @@ export async function loadQuery<QueryResponse>({
query: string
params?: QueryParams
}): Promise<QueryResponse> {
const isDraftMode = draftMode().isEnabled
const isDraftMode = (await draftMode()).isEnabled
const token = config.sanity.token

if (isDraftMode && !token) {
Expand Down
8 changes: 4 additions & 4 deletions examples/hello-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"scripts": {
"build": "next build",
"dev": "next",
"dev": "next --turbo",
"format": "npx prettier --write . --ignore-path .gitignore",
"lint": "next lint -- --ignore-path .gitignore",
"lint:fix": "npm run format && npm run lint -- --fix",
Expand All @@ -26,12 +26,12 @@
"next-sanity": "^9.7.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"sanity": "^3.61.0",
"sanity": "^3.62.0",
"server-only": "0.0.1"
},
"devDependencies": {
"@types/react": "npm:types-react@19.0.0-rc.1",
"@types/react-dom": "npm:types-react-dom@19.0.0",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.1",
"autoprefixer": "10.4.20",
"eslint": "^8.57.0",
"eslint-config-next": "15.0.0",
Expand Down
1 change: 1 addition & 0 deletions examples/hello-world/sanity.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import schemas from '@/sanity/schemas'
import { visionTool } from '@sanity/vision'
import { pages } from '@tinloof/sanity-studio'
import { defineConfig } from 'sanity'

import { structureTool } from 'sanity/structure'
import StudioLogo from './components/StudioLogo'
import config from './config'
Expand Down
4 changes: 2 additions & 2 deletions examples/with-i18n/app/api/disable-draft/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { draftMode } from 'next/headers'
import { NextRequest, NextResponse } from 'next/server'

export function GET(request: NextRequest) {
draftMode().disable()
export async function GET(request: NextRequest) {
;(await draftMode()).disable()
const url = new URL(request.nextUrl)
return NextResponse.redirect(new URL('/', url.origin))
}
2 changes: 1 addition & 1 deletion examples/with-i18n/app/api/draft/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function GET(request: Request) {
return new Response('Invalid secret', { status: 401 })
}

draftMode().enable()
;(await draftMode()).enable()

redirect(redirectTo)
}
6 changes: 3 additions & 3 deletions examples/with-i18n/data/sanity/loadQuery.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { QueryParams } from 'next-sanity'
import type { UnfilteredResponseQueryOptions } from '@sanity/client'
import type { QueryParams } from 'next-sanity'

import { draftMode } from 'next/headers'
import 'server-only'

import { client } from '@/data/sanity/client'
import config from '@/config'
import { client } from '@/data/sanity/client'

const DEFAULT_PARAMS = {} as QueryParams

Expand All @@ -16,7 +16,7 @@ export async function loadQuery<QueryResponse>({
query: string
params?: QueryParams
}): Promise<QueryResponse> {
const isDraftMode = draftMode().isEnabled
const isDraftMode = (await draftMode()).isEnabled
const token = config.sanity.token

if (isDraftMode && !token) {
Expand Down
8 changes: 4 additions & 4 deletions examples/with-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"scripts": {
"build": "next build",
"dev": "next",
"dev": "next --turbo",
"format": "npx prettier --write . --ignore-path .gitignore",
"lint": "next lint -- --ignore-path .gitignore",
"lint:fix": "npm run format && npm run lint -- --fix",
Expand All @@ -26,12 +26,12 @@
"next-sanity": "^9.7.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"sanity": "^3.61.0",
"sanity": "^3.62.0",
"server-only": "0.0.1"
},
"devDependencies": {
"@types/react": "npm:types-react@19.0.0-rc.1",
"@types/react-dom": "npm:types-react-dom@19.0.0",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.1",
"autoprefixer": "10.4.20",
"eslint": "^8.57.0",
"eslint-config-next": "15.0.0",
Expand Down
13 changes: 9 additions & 4 deletions examples/with-sections/app/(website)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
import { Metadata } from 'next'
import { draftMode } from 'next/headers'
import { VisualEditing } from 'next-sanity'
import { revalidatePath, revalidateTag } from 'next/cache'
import { draftMode } from 'next/headers'

import config from '@/config'

export const metadata: Metadata = {
title: `${config.siteName} - Website`,
}

export default function Layout({ children }: { children: React.ReactNode }) {
export default async function Layout({
children,
}: {
children: React.ReactNode
}) {
const isDraftModeEnabled = (await draftMode()).isEnabled
return (
<>
{children}
{draftMode().isEnabled && (
{isDraftModeEnabled && (
<VisualEditing
refresh={async (payload) => {
'use server'
if (!draftMode().isEnabled) {
if (!isDraftModeEnabled) {
console.debug(
'Skipped manual refresh because draft mode is not enabled',
)
Expand Down
4 changes: 2 additions & 2 deletions examples/with-sections/app/api/disable-draft/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { draftMode } from 'next/headers'
import { NextRequest, NextResponse } from 'next/server'

export function GET(request: NextRequest) {
draftMode().disable()
export async function GET(request: NextRequest) {
;(await draftMode()).disable()
const url = new URL(request.nextUrl)
return NextResponse.redirect(new URL('/', url.origin))
}
2 changes: 1 addition & 1 deletion examples/with-sections/app/api/draft/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function GET(request: Request) {
return new Response('Invalid secret', { status: 401 })
}

draftMode().enable()
;(await draftMode()).enable()

redirect(redirectTo)
}
6 changes: 3 additions & 3 deletions examples/with-sections/data/sanity/loadQuery.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { QueryParams } from 'next-sanity'
import type { UnfilteredResponseQueryOptions } from '@sanity/client'
import type { QueryParams } from 'next-sanity'

import { draftMode } from 'next/headers'
import 'server-only'

import { client } from '@/data/sanity/client'
import config from '@/config'
import { client } from '@/data/sanity/client'

const DEFAULT_PARAMS = {} as QueryParams

Expand All @@ -16,7 +16,7 @@ export async function loadQuery<QueryResponse>({
query: string
params?: QueryParams
}): Promise<QueryResponse> {
const isDraftMode = draftMode().isEnabled
const isDraftMode = (await draftMode()).isEnabled
const token = config.sanity.token

if (isDraftMode && !token) {
Expand Down
Loading