Skip to content

Enable drag-and-drop for visual editing sections#607

Open
thomasKn wants to merge 3 commits intomainfrom
feat/visual-editing-drag-and-drop
Open

Enable drag-and-drop for visual editing sections#607
thomasKn wants to merge 3 commits intomainfrom
feat/visual-editing-drag-and-drop

Conversation

@thomasKn
Copy link
Collaborator

@thomasKn thomasKn commented Mar 9, 2026

Summary

  • Add SectionsRenderer component that wraps sections rendering with drag-and-drop support for Sanity's Presentation tool
  • Uses useOptimistic from @sanity/visual-editing/react for instant reorder feedback when dragging sections
  • Uses createDataAttribute with .scope() to generate data-sanity attributes on both the parent container and individual section wrappers
  • Adds dataSanity prop to CmsSection/SectionWrapper to apply data-sanity on <section> elements
  • Updates page, product, and collection routes to use the new SectionsRenderer

All attributes are only applied when sanityPreviewMode is active — no impact on production rendering.

Test plan

  • Run pnpm typecheck — passes
  • Run pnpm build — passes
  • Open a page in Sanity Presentation preview and verify section overlays show drag handle icons
  • Drag a section to reorder — should update instantly (optimistic)
  • Verify the reorder persists after release
  • Test on page, product, and collection routes
  • Verify no layout changes in production (non-preview) mode

Add data-sanity attributes and optimistic state to support drag-and-drop
reordering of array-based sections in Sanity's Presentation tool.

- Create SectionsRenderer component with useOptimistic for instant
  reorder feedback and createDataAttribute for drag-and-drop overlays
- Add dataSanity prop to CmsSection/SectionWrapper for section-level
  data-sanity attributes
- Update page, product, and collection routes to use SectionsRenderer
@shopify
Copy link
Contributor

shopify bot commented Mar 9, 2026

Oxygen deployed a preview of your feat/visual-editing-drag-and-drop branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
Fluid demo ✅ Successful (Logs) Preview deployment Inspect deployment March 9, 2026 9:47 PM

Learn more about Hydrogen's GitHub integration.

thomasKn added 2 commits March 9, 2026 17:35
- Guard useOptimistic reducer with action.id === documentId to prevent
  cross-document mutation corruption
- Add className="contents" to wrapper div to preserve gap-y spacing
  from parent main element's flex layout
The raw document from useOptimistic actions contains unresolved
portable text fields ({_key, _type, value} objects) that crash React
when rendered. Use the reconciliation pattern from Sanity docs: apply
the new order from the mutation but keep the GROQ-projected data from
the current state by matching on _key.
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

Successfully merging this pull request may close these issues.

1 participant