fix(app): read views after queued writes, reload on write failure

- Page and journal views read through the write queue after the previous
  view's pending saves, so they never load stale text.
- A failed write reloads the current view and shows a message instead of
  leaving blocks on temporary ids; inserts also trigger reconciliation.
- Completion replaces the query range, not up to the caret, and closes
  when the caret moves away.
- Renaming a page reloads it so rewritten links are not overwritten.
- Dropping below an expanded parent lands as its first child, where the
  indicator is drawn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Opus 5.5 committed 2026-10-21 04:08:36 +02:00
1 parent fce7526fcf
commit 5e25db3e24
9 files changed
+102 -29

No files matched your search

+18 -4
View File
@@ -34,8 +34,10 @@ class PageTarget extends AppRoute {
/// paying for itself; rebuilds are scoped with `ListenableBuilder`.
class AppState extends ChangeNotifier {
AppState(this.backend, {WriteQueue? queue})
: queue = queue ?? WriteQueue(onError: _logError),
refs = BlockRefCache(backend);
: refs = BlockRefCache(backend),
queue = queue ?? WriteQueue() {
this.queue.onError = _writeFailed;
}
final GraphBackend backend;
final WriteQueue queue;
@@ -50,15 +52,27 @@ class AppState extends ChangeNotifier {
/// Last page shown (for synapse reinforcement on navigation).
String? _lastPageId;
/// Bumped when an error makes views reload from the core.
/// Bumped to make the current view reload from the core (failed writes, renames).
int generation = 0;
/// Last write error, shown once by the shell.
String? writeError;
AppRoute get route => _route;
bool get canGoBack => _back.isNotEmpty;
bool get canGoForward => _forward.isNotEmpty;
static void _logError(Object e, StackTrace st) {
/// A failed write leaves the optimistic UI out of sync: reload the view from the core.
void _writeFailed(Object e, StackTrace st) {
debugPrint('graph write failed: $e\n$st');
writeError = '$e';
reload();
}
/// Rebuilds the current view from the core (after queued writes have run).
void reload() {
generation++;
notifyListeners();
}
void go(AppRoute r) {