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

Sanity and Next.js 15 #7705

Open
elie222 opened this issue Oct 30, 2024 · 12 comments
Open

Sanity and Next.js 15 #7705

elie222 opened this issue Oct 30, 2024 · 12 comments

Comments

@elie222
Copy link

elie222 commented Oct 30, 2024

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/@[email protected]/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

Copy link
Member

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
Copy link

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
Copy link
Author

elie222 commented Nov 4, 2024

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

@elie222 elie222 closed this as completed Nov 4, 2024
Copy link
Member

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

@jordanl17 jordanl17 reopened this Nov 5, 2024
@paulmains-epam
Copy link

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

Yes I believe you're correct. Upon further investigation I had some peer dependency issues that weren't being highlighted. I'm not sure which package it was in hindsight, but it was pulling in v16 react types. I've re-setup the codebase a few different times since I first saw the issue. It's not happened again.

@Henkisch
Copy link

Henkisch commented Dec 9, 2024

This command solved it for me npm install react react-dom @types/react --save, I had this problem for months and it annoyed me so much, but now it finally seems gone.

@alexanderbnelson
Copy link

I still have this issue. Only version of @types/react is the latest. 19.0.1. Tried rm -rf modules and lock file. No luck.

@serge-0v
Copy link

I had the same issue with Next.15, React 19 and lucid icons. Worked good in React 19 RC. Then searched lucid icons issues and someone posted that adding "react": ["./node_modules/@types/react"] to tsconfig.json "path" solved it:

"paths": {
    "react": ["./node_modules/@types/react"]
},

And it worked for me.

@gadcam
Copy link

gadcam commented Dec 20, 2024

One reliable way to fix this is to add an overrides section like this in the package.json

  "overrides": {
    "@types/react": "^19.0.2",
    "@types/react-dom": "^19.0.2"
  }

with the same version you have installed above
Not directly related but note that overriding react-is version might also be helpful in this migration ;)

The packages causing the issue are

  • @sanity/block-tools
  • @sanity/export
  • @sanity/types

@serge-0v
Copy link

One reliable way to fix this is to add an overrides section like this in the package.json

  "overrides": {
    "@types/react": "^19.0.2",
    "@types/react-dom": "^19.0.2"
  }

with the same version you have installed above Not directly related but note that overriding react-is version might also be helpful in this migration ;)

The packages causing the issue are

  • @sanity/block-tools
  • @sanity/export
  • @sanity/types

Thanks, @gadcam. This worked for me.

@Iffti2000
Copy link

I had the same issue with Next.15, React 19 and lucid icons. Worked good in React 19 RC. Then searched lucid icons issues and someone posted that adding "react": ["./node_modules/@types/react"] to tsconfig.json "path" solved it:

"paths": {
    "react": ["./node_modules/@types/react"]
},

And it worked for me.

Thank you, It worked ❤️

@gadcam
Copy link

gadcam commented Dec 30, 2024

Might be fixed by #8121

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants