Snippet naming: content-derived on publish, frozen on explicit rename

This commit is contained in:
2026-06-13 10:13:57 +03:00
parent 92bfe888b5
commit 4e5108f434
14 changed files with 508 additions and 16 deletions
+14
View File
@@ -165,6 +165,20 @@ const active = useSnippetStore(selectActiveSnippet);
> Rule: if you can compute it, do not store it. Add a new state field only for a
> value that is _input_ the app receives, not output it derives.
### Editing buffers — the sanctioned duplication, and its sync rule
A text field with debounced auto-save (the metadata panel's Name/Comment, the editor
buffer) legitimately mirrors a store fact into local component state: the local copy is
the user's in-progress text, the store holds the saved value. This duplication carries an
obligation the moment the store fact has **another writer** (publish's content-derived
renaming, import, any store-side mutation): the component must **adopt** a store change it
didn't make, or its debounced save will write the stale local copy back — silently undoing
the other writer. The pattern (see `SnippetLibrary`'s `SnippetMeta`): track the last store
value seen in a ref; when the store value changes, adopt it into local state **unless the
user has diverged** (local ≠ previous store value) — in-progress typing always wins.
Keying the component by entity id handles switching entities; this rule handles the same
entity changing underneath.
---
## 3. Where State Lives: Central vs. Per-Feature Stores