Skip to content

Drag handles don't appear until editor is clicked on some notes #74

@reddpy

Description

@reddpy

Description

On some notes (e.g. a freshly created "tester" note), the draggable block grip icons don't appear when hovering over blocks until the user clicks into the editor. On other notes with more content (e.g. "Product Roadmap"), they appear immediately on load.

Root Cause

In plugins.tsx, the DraggableBlockPlugin receives editorContainerRef.current as a prop:

const editorContainerRef = useRef<HTMLDivElement>(null)
// ...
<DraggableBlockPlugin anchorElem={editorContainerRef.current} />

On first render, useRef returns { current: null }. The ref isn't populated until React attaches it to the DOM after the render completes. Since editorContainerRef.current is read during render (not inside an effect), the plugin receives null and returns early:

if (!anchorElem) {
  return null
}

Notes that trigger additional re-renders on load (e.g. via content migration or complex state updates) cause the plugin to re-render with the now-populated ref, masking the bug.

Fix

Convert editorContainerRef from useRef to a callback ref with useState, so setting the DOM element triggers a re-render:

const [editorContainer, setEditorContainer] = useState<HTMLDivElement | null>(null)
// ...
<div ref={setEditorContainer} className="relative">
// ...
<DraggableBlockPlugin anchorElem={editorContainer} />

Files

  • src/components/editor/plugins.tsx

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions