Skip to content

Commit

Permalink
fix: migrate breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Dec 7, 2023
1 parent 5a76951 commit 9980946
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 53 deletions.
36 changes: 36 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'tailwindcss/tailwind.css'

import { IBM_Plex_Mono, Inter, PT_Serif } from 'next/font/google'

const serif = PT_Serif({
variable: '--font-serif',
style: ['normal', 'italic'],
subsets: ['latin'],
weight: ['400', '700'],
})
const sans = Inter({
variable: '--font-sans',
subsets: ['latin'],
// @todo: understand why extrabold (800) isn't being respected when explicitly specified in this weight array
// weight: ['500', '700', '800'],
})
const mono = IBM_Plex_Mono({
variable: '--font-mono',
subsets: ['latin'],
weight: ['500', '700'],
})

export default async function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html
lang="en"
className={`${mono.variable} ${sans.variable} ${serif.variable}`}
>
<body>{children}</body>
</html>
)
}
17 changes: 17 additions & 0 deletions app/studio/[[...index]]/Studio.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use client'

import { NextStudio } from 'next-sanity/studio'
import config from 'sanity.config'

export default function Studio() {
return (
<NextStudio
config={config}
unstable_globalStyles
// This prop is for demo purposes on the deployment hosted by Sanity, you can safely delete it
unstable_noAuthBoundary={
process.env.NEXT_PUBLIC_UNSTABLE_NOAUTHBOUNDARY === 'true'
}
/>
)
}
19 changes: 19 additions & 0 deletions app/studio/[[...index]]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* This route is responsible for the built-in authoring environment using Sanity Studio v3.
* All routes under /studio will be handled by this file using Next.js' catch-all routes:
* https://nextjs.org/docs/routing/dynamic-routes#catch-all-routes
*
* You can learn more about the next-sanity package here:
* https://github.com/sanity-io/next-sanity
*/

import Studio from './Studio'

export const dynamic = 'force-static'

export { metadata } from 'next-sanity/studio/metadata'
export { viewport } from 'next-sanity/studio/viewport'

export default function StudioPage() {
return <Studio />
}
50 changes: 26 additions & 24 deletions lib/sanity.client.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
import { createClient } from '@sanity/client/stega'
import {
apiVersion,
basePath,
dataset,
projectId,
useCdn,
} from 'lib/sanity.api'
import { createClient, type SanityClient } from 'next-sanity'

export function getClient(preview?: { token: string }): SanityClient {
export function getClient(preview?: { token: string }) {
const client = createClient({
projectId,
dataset,
apiVersion,
useCdn,
perspective: 'published',
studioUrl: basePath,
logger: console,
encodeSourceMap: process.env.NEXT_PUBLIC_VERCEL_ENV !== 'production',
encodeSourceMapAtPath: (props) => {
if (typeof props.path.at(-1) === 'number') {
return false
}
if (
props.path.at(-2) === 'marks' &&
typeof props.path.at(-1) === 'number'
) {
return false
}
if (props.path.at(0) === 'duration') {
return false
}
switch (props.path.at(-1)) {
case 'href':
case 'listItem':
case 'site':
stega: {
enabled: process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview',
studioUrl: basePath,
logger: console,
filter: (props) => {
if (typeof props.sourcePath.at(-1) === 'number') {
return false
}
return props.filterDefault(props)
}
if (
props.sourcePath.at(-2) === 'marks' &&
typeof props.sourcePath.at(-1) === 'number'
) {
return false
}
if (props.sourcePath.at(0) === 'duration') {
return false
}
switch (props.sourcePath.at(-1)) {
case 'href':
case 'listItem':
case 'site':
return false
}
return props.filterDefault(props)
},
},
})
if (preview) {
Expand Down
4 changes: 0 additions & 4 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/** @type {import('next').NextConfig} */
const config = {
// @TODO turn swcMinify back on once the agressive dead code elimination bug that casues
// `ReferenceError: FieldPresenceWithOverlay is not defined` is fixed
swcMinify: false,

images: {
remotePatterns: [
{ hostname: 'cdn.sanity.io' },
Expand Down
2 changes: 1 addition & 1 deletion pages/api/draft.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createClient } from '@sanity/client'
import {
apiVersion,
dataset,
Expand All @@ -8,7 +9,6 @@ import {
} from 'lib/sanity.api'
import { resolveHref } from 'lib/sanity.links'
import type { NextApiRequest, NextApiResponse } from 'next'
import { createClient } from 'next-sanity'
import { getSecret } from 'plugins/productionUrl/utils'

function redirectToPreview(
Expand Down
24 changes: 0 additions & 24 deletions pages/studio/[[...index]].tsx

This file was deleted.

0 comments on commit 9980946

Please sign in to comment.