Back to Plate

DnD missing-context runtime guard

docs/plans/2026-04-10-dnd-missing-context-runtime-guard.md

53.0.52.2 KB
Original Source

DnD missing-context runtime guard

Goal

Prevent @platejs/dnd from throwing Expected drag drop context when a Plate surface renders without an active react-dnd manager, while keeping normal browser DnD behavior intact.

Findings

Plan

  1. Confirm the hook-level guard is the right durable fix.
  2. Run remaining verification for touched surfaces.
  3. State clearly whether the duplicate-deps hypothesis is supported by evidence.

Progress

  • Added a missing-context guard in useDragNode.ts and useDropNode.ts.
  • Switched the guard to import DndContext from react-dnd/dist/core/index.js because Bun did not reliably surface that export from the package root during tests.
  • Extended useDraggable.spec.tsx with a missing-context regression case.
  • Initial targeted Bun test hit the repo's known mixed .bun / .pnpm React invalid-hook-call failure mode; pnpm run reinstall cleared it.
  • Final verification passed:
    • pnpm --filter @platejs/dnd test -- useDraggable.spec.tsx
    • bun test packages/dnd/src/components/useDraggable.spec.tsx
    • pnpm turbo build --filter=./packages/dnd --filter=./apps/www
    • pnpm turbo typecheck --filter=./packages/dnd --filter=./apps/www
    • pnpm lint:fix
    • browser-use --connect http://127.0.0.1:9222 verification on / and /cn with no console errors, no page errors, and no Expected drag drop context crash text