Issue with portable text causing crashes in Sanity Studio 3.29.0

11 replies
Last updated: Feb 15, 2024
Hi, I have a problem with portable text in Sanity Studio 3.29.0. In Sanity Studio 3.24.1 I don’t encounter this issue.
Whenever I add a block array (copied and pasted from docs) my structure tool crashes. In fact, the document either does not load or returns this error:


Error: Maximum call stack size exceeded
RangeError: Maximum call stack size exceeded
    at getRandomValues (<http://localhost:3333/node_modules/.sanity/vite/deps/chunk-G7CAILKR.js?v=ca194635:107199:19>)
…
My schema looks like this:

export default {
  name: 'pageNotFound',
  title: '404',
  type: 'document',
  fields: [
    {
      title: 'Bild',
      name: 'image',
      type: 'image',
    },
    {
      title: 'Überschrift',
      name: 'headline',
      type: 'string',
    },
    {
      title: 'Absatz',
      name: 'paragraph',
      type: 'string',
    },
    {
      name: 'content',
      type: 'array',
      title: 'Content',
      of: [
        {
          type: 'block'
        }
      ]
    }
  ],
}
As soon as I remove the block array the document loads again and the error disappears. Does anybody know how to fix this?
AI Update

Good news! This was a known bug in Sanity Studio 3.29.0 that was quickly identified and fixed. The solution is to upgrade to version 3.29.1 or later.

This was a regression introduced in version 3.29.0 that caused a maximum call stack error when using portable text/block arrays. The error manifested as RangeError: Maximum call stack size exceeded at getRandomValues, and it would crash the Structure tool whenever you tried to open a document containing a block array field.

As you can see from the community thread I found, multiple developers reported this exact issue on February 14, 2024, and the Sanity team identified and released a fix the same day.

To fix this issue:

npm install sanity@latest
# or
yarn add sanity@latest

Then restart your dev server. The fix was released in version 3.29.1, so updating to that version or any later version will resolve the problem.

Your schema is perfectly fine - there's nothing wrong with how you've defined your block array:

{
  name: 'content',
  type: 'array',
  title: 'Content',
  of: [
    {
      type: 'block'
    }
  ]
}

This was purely a bug in that specific Studio version that affected all portable text implementations, regardless of configuration. The Sanity team was incredibly responsive, pushing out version 3.29.1 within hours of the reports coming in.

Hey I have the same issue for some reason – did you find a solution?
Can you share an example of the content you’re pasting in?
I've got this same issue too, just upgraded everything Sanity related to latest.
Block content defined like so in my schema...

...
defineField({
      name: 'byline',
      type: 'array',
      of: [
        {
          type: 'block',
          styles: [{title: 'Normal', value: 'normal'}],
          lists: [],
          marks: {
            decorators: [
              {title: 'Strong', value: 'strong'},
              {title: 'Emphasis', value: 'em'},
            ],
          },
        },
      ],
      title: 'Byline',
      description: 'Page introduction, appears below the title',
      group: 'settings',
    }),
...
Sanity packages...

"dependencies": {
    "@sanity/dashboard": "^3.1.6",
    "@sanity/ui": "^2.0.2",
    "@sanity/vision": "^3.29.0",
    "ndjson": "^2.0.0",
    "next-sanity": "^8.0.0",
    "ordinal": "^1.0.3",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-icons": "^5.0.1",
    "react-is": "^18.2.0",
    "recharts": "^2.12.0",
    "sanitize-html": "^2.11.0",
    "sanity": "^3.29.0",
    "sanity-plugin-dashboard-widget-document-list": "^1.0.1",
    "sanity-plugin-documents-pane": "^2.2.1",
    "sanity-plugin-media": "^2.2.5",
    "sanity-plugin-mux-input": "^2.2.4",
    "sanity-plugin-tags": "^2.0.1",
    "sanity-plugin-utils": "^1.6.4",
    "styled-components": "^6.1.8"
  },
  "devDependencies": {
    "@sanity/eslint-config-studio": "^3.0.1",
    "@types/react": "18.2.0",
    "@types/styled-components": "^5.1.34",
    "eslint": "^8.56.0",
    "prettier": "^3.2.5",
    "typescript": "^5.3.3"
  },
Error message...

Error: Maximum call stack size exceeded
RangeError: Maximum call stack size exceeded
    at getRandomValues (<http://localhost:3333/node_modules/.sanity/vite/deps/chunk-F33BQELL.js?v=64d014bb:41700:19>)
    at getRandomValues (<http://localhost:3333/node_modules/.sanity/vite/deps/chunk-F33BQELL.js?v=64d014bb:41704:10>)
    at getRandomValues (<http://localhost:3333/node_modules/.sanity/vite/deps/chunk-F33BQELL.js?v=64d014bb:41704:10>)
    at getRandomValues (<http://localhost:3333/node_modules/.sanity/vite/deps/chunk-F33BQELL.js?v=64d014bb:41704:10>)
    at getRandomValues (<http://localhost:3333/node_modules/.sanity/vite/deps/chunk-F33BQELL.js?v=64d014bb:41704:10>)
    at getRandomValues (<http://localhost:3333/node_modules/.sanity/vite/deps/chunk-F33BQELL.js?v=64d014bb:41704:10>)
    at getRandomValues (<http://localhost:3333/node_modules/.sanity/vite/deps/chunk-F33BQELL.js?v=64d014bb:41704:10>)
    at getRandomValues (<http://localhost:3333/node_modules/.sanity/vite/deps/chunk-F33BQELL.js?v=64d014bb:41704:10>)
    at getRandomValues (<http://localhost:3333/node_modules/.sanity/vite/deps/chunk-F33BQELL.js?v=64d014bb:41704:10>)
    at getRandomValues (<http://localhost:3333/node_modules/.sanity/vite/deps/chunk-F33BQELL.js?v=64d014bb:41704:10>)
I used:
export default {
	title: "Content",
	name: "normal",
	type: "array",
	of: [
		{
			type: "block",
			styles: [{ title: "Normal", value: "normal" }],
		},
	],
};
Made an ultra minimal repo for the issue:
https://github.com/j2is/sanity-portable-text-bug
Added it here if it helps, thanks so much
https://github.com/sanity-io/sanity/issues/5741
Experiencing the same issue over here with sanity
3.29.0
We’ve identified the issue and are working on a fix
The fix should be live!
Thanks for the fast fix! Just updated and its working again!

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?