sanity-template-nextjs-clean icon indicating copy to clipboard operation
sanity-template-nextjs-clean copied to clipboard

Error Reordering Page Builder Blocks in Live Preview while in Presentation Mode

Open edolyne opened this issue 4 months ago • 2 comments

Describe the bug

When dragging a page builder section to a new position Sanity Studio in the Presentation window, two errors are triggered:

Do not call Hooks inside useEffect(...), useMemo(...), or other built-in Hooks. You can only call Hooks at the top level of your React function. For more information, see https://react.dev/link/rules-of-hooks

and

A function wrapped in useEffectEvent can't be called during rendering.

The errors originate from app/components/PageBuilder.tsx (86:43) @ PageBuilder within useOptimistic

This error only happens when dragging a section, within the live preview, and not if you change the order in the studio portion to the right.

To Reproduce

Steps to reproduce the behavior:

  1. Create a new Sanity Project using the blank template
  2. Follow CLI setup locally
  3. Import sample data
  4. Run npm run dev
  5. Open Sanity Studio
  6. Navigate to Presentation
  7. Navigate to the about page
  8. Drag a page builder section on the left live preivew to a new position
  9. Error presents itself.

Expected behavior

When dragging a section to a new position on page, the page renders without issue in the new order.

Screenshots

Image Image

Which versions of Sanity are you using?

@sanity/cli (global) 3.93.0 (latest: 4.4.0) @sanity/assist 4.4.7 (latest: 5.0.0) @sanity/eslint-config-studio 5.0.2 (up to date) @sanity/icons 3.7.4 (up to date) @sanity/vision 4.3.0 (latest: 4.4.0) sanity 4.3.0 (latest: 4.4.0)

What operating system are you using?

MacOS Sequoia 15.5

Which versions of Node.js / npm are you running?

npm: 11.5.1 node: v24.5.0

edolyne avatar Aug 14 '25 03:08 edolyne

Can confirm I've having the same issue at my end.

nettum avatar Sep 12 '25 13:09 nettum

Hi 👋 Bumping your version of next-sanity to ^10.0.12. should fix this. You don't need update to version 11, as there are breaking changes. We will be merging in updates soon for next-sanity v11 soon.

kenjonespizza avatar Sep 18 '25 18:09 kenjonespizza