fix: ensure editor placeholder shows on initial page load

- Always initialize editor with content to create paragraph node
- Remove logic that prevented setting empty paragraph content
- Remove unused initialized variable
- This ensures the placeholder is visible when editor first loads

The issue was that the editor needs at least one paragraph node
for the placeholder to display, but the previous logic prevented
this from happening on initial load.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Justin Edmund 2025-06-26 14:17:03 -04:00
parent 64bb0d991e
commit e36f70d8c2

View file

@ -71,7 +71,6 @@
let editor = $state<Editor | undefined>() let editor = $state<Editor | undefined>()
let element = $state<HTMLElement>() let element = $state<HTMLElement>()
let isLoading = $state(true) let isLoading = $state(true)
let initialized = false
const mediaSelectionState = $derived($mediaSelectionStore) const mediaSelectionState = $derived($mediaSelectionStore)
// Toolbar component ref // Toolbar component ref
@ -142,12 +141,6 @@
// Update content when editor changes // Update content when editor changes
function handleUpdate({ editor: updatedEditor, transaction }: any) { function handleUpdate({ editor: updatedEditor, transaction }: any) {
// Skip the first update to avoid circular updates
if (!initialized) {
initialized = true
return
}
// Dismiss link menus on typing // Dismiss link menus on typing
linkManagerRef?.dismissOnTyping(transaction) linkManagerRef?.dismissOnTyping(transaction)
@ -162,25 +155,14 @@
} }
} }
// Simple effect to load content once when editor is ready // Effect to set initial content when editor is first created
let contentLoaded = false let isEditorInitialized = false
$effect(() => { $effect(() => {
if (editor && data && !contentLoaded) { if (editor && !isEditorInitialized) {
// Check if the data has actual content (not just empty doc) // Set initial content to ensure proper initialization
const hasContent = // This ensures the editor has at least an empty paragraph for placeholder
data.content && editor.commands.setContent(data)
data.content.length > 0 && isEditorInitialized = true
!(
data.content.length === 1 &&
data.content[0].type === 'paragraph' &&
!data.content[0].content
)
if (hasContent) {
// Set the content once
editor.commands.setContent(data)
contentLoaded = true
}
} }
}) })