fix: open editor immediately when clicking suggested property slots

Previously, clicking a suggested property slot (Status, Date, URL) would add
an empty property to frontmatter but fail to open the editor. This was due
to a race condition where:

1. handleSuggestedAdd() called onAddProperty() which is async
2. The useEffect tried to detect when the property appeared in frontmatter
3. But frontmatter updates asynchronously after onAddProperty resolves
4. By the time frontmatter is updated, the useEffect had already run

The fix is to directly set the editing key immediately when clicking a
suggested slot, rather than relying on the useEffect to detect the property
being added. This is more reliable because we know we're adding the property
- we don't need to wait for it to appear in frontmatter.
This commit is contained in:
Test
2026-04-07 11:03:50 +02:00
parent 132618ebd3
commit e486e863ce
30 changed files with 149 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
---
type: Project
type: Note
status: Active
---

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,5 @@
---
type: Note
status: Active
---
My Custom H1 Heading

View File

@@ -0,0 +1,7 @@
---
type: Note
status: Active
---
[[2024-03|March 2024]]
[[2024-03|March 2024]]

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,7 @@
---
type: Project
status: Active
---
Appended by raw editor test

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,4 @@
---
type: Note
status: Active
---

View File

@@ -0,0 +1,7 @@
---
type: Note
status: Active
---
[[2024-03|March 2024]]
[[2024-03|March 2024]]

View File

@@ -0,0 +1,15 @@
---
type: Project
status: Active
---
## Objective
## Key Results
## Notes

View File

@@ -0,0 +1,15 @@
---
type: Project
status: Active
---
## Objective
## Key Results
## Notes

View File

@@ -1,4 +1,4 @@
import { useMemo, useCallback, useRef, useEffect } from 'react'
import { useMemo, useCallback } from 'react'
import type { VaultEntry } from '../types'
import type { FrontmatterValue } from './Inspector'
import type { ParsedFrontmatter } from '../utils/frontmatter'
@@ -113,20 +113,12 @@ export function DynamicPropertiesPanel({
? SUGGESTED_PROPERTIES.filter(p => !existingKeys.has(p.toLowerCase()))
: []
const pendingEditKeyRef = useRef<string | null>(null)
useEffect(() => {
if (pendingEditKeyRef.current && propertyEntries.some(([k]) => k === pendingEditKeyRef.current)) {
setEditingKey(pendingEditKeyRef.current)
pendingEditKeyRef.current = null
}
}, [propertyEntries, setEditingKey])
const handleSuggestedAdd = useCallback((key: string) => {
if (!onAddProperty) return
pendingEditKeyRef.current = key
// Open the editor immediately - no need to wait for frontmatter to update
setEditingKey(key)
onAddProperty(key, '')
}, [onAddProperty])
}, [onAddProperty, setEditingKey])
return (
<div className="flex flex-col gap-3">