sanity-io / sanity

Sanity Studio – Rapidly configure content workspaces powered by structured content
https://www.sanity.io
MIT License
5.27k stars 427 forks source link

Sanity and Next.js 15 #7705

Open elie222 opened 1 week ago

elie222 commented 1 week ago

This code has a TypeScript error when updating to Next 15 (React 19):

import { TagIcon } from "@sanity/icons";
import { defineField, defineType } from "sanity";

export const categoryType = defineType({
  name: "category",
  title: "Category",
  type: "document",
  icon: TagIcon,
  fields: [
    defineField({
      name: "title",
      type: "string",
    }),
  ],
});

Error:

Type 'ForwardRefExoticComponent<Omit<SVGProps<SVGSVGElement>, "ref"> & RefAttributes<SVGSVGElement>>' is not assignable to type 'ReactNode | ComponentType'.
  Type 'ForwardRefExoticComponent<Omit<SVGProps<SVGSVGElement>, "ref"> & RefAttributes<SVGSVGElement>>' is not assignable to type 'FunctionComponent<{}>'.
    Type 'React.ReactNode' is not assignable to type 'import("..../node_modules/.pnpm/@types+react@18.3.12/node_modules/@types/react/index").ReactNode'.
      Type 'ReactElement<unknown, string | JSXElementConstructor<any>>' is not assignable to type 'ReactNode'.
        Property 'children' is missing in type 'ReactElement<unknown, string | JSXElementConstructor<any>>' but required in type 'ReactPortal'.ts(2322)

CleanShot 2024-10-30 at 15 49 24@2x

jordanl17 commented 3 days ago

Hi elie222 thank you for reporting.

Have you followed at all the details outlined here related to upgrading to React v19 - https://www.sanity.io/help/react-19

paulmains-epam commented 3 days ago

I can confirm I also have the same issue. I was playing around with this repo https://github.com/sanity-io/sanity-template-vercel-visual-editing upgrading it the newest versions. I followed the guidance in the react 19 upgrade page referenced. But the issue persists. I'm just commenting out all icons in the schemas currently.

elie222 commented 2 days ago

Sorry, I actually solved this. I think I hadn't updated on my packages.

jordanl17 commented 2 days ago

Thanks for joining this issue @paulmains-epam.

I have tried a fresh Next.js 15 and React 19 with embedded Sanity Studio and didn't encounter these issues.

We've narrowed this issue, at least in @elie222 case down to ReactPortal (https://github.com/tajo/react-portal#readme) which hasn't receive updates for many years and guarantees support only up to React 16. Perhaps you could look for an alternative. Because of this, it's quite likely there are multiple version of @types/react being used in your build? You could verify with npm ls @types/react to see if there's any use of a version <18.x.x