Error Reordering Page Builder Blocks in Live Preview while in Presentation Mode
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:
- Create a new Sanity Project using the blank template
- Follow CLI setup locally
- Import sample data
- Run
npm run dev - Open Sanity Studio
- Navigate to Presentation
- Navigate to the about page
- Drag a page builder section on the left live preivew to a new position
- 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
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
Can confirm I've having the same issue at my end.
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.