fix: suppress local create watcher conflict

This commit is contained in:
lix-2026
2026-05-20 16:16:42 +08:00
parent 03173e2363
commit 0c532b2953
3 changed files with 123 additions and 1 deletions
@@ -1425,6 +1425,22 @@ pub(crate) fn render_editor_island_adapter_script() -> &'static str {
}
};
const shouldSuppressLocalFolderSelfChange = (documentId, eventKind) => {
const doc = String(documentId || '').trim();
if (!doc) return false;
const kind = String(eventKind || '');
if (!kind.includes('Create') && !kind.includes('Metadata')) return false;
const suppressions = window.__mnoteLocalFolderSelfChangeSuppressions;
if (!suppressions || typeof suppressions.get !== 'function') return false;
const expiresAt = Number(suppressions.get(doc) || 0);
if (!Number.isFinite(expiresAt) || expiresAt <= 0) return false;
if (Date.now() > expiresAt) {
if (typeof suppressions.delete === 'function') suppressions.delete(doc);
return false;
}
return true;
};
const normalizeSessionSourceKind = (bootstrap) => {
const value = typeof bootstrap?.sourceKind === 'string' ? bootstrap.sourceKind.trim() : '';
return value || 'convex_workspace';
@@ -2249,6 +2265,11 @@ pub(crate) fn render_editor_island_adapter_script() -> &'static str {
const mayAffectMissingDocument = eventKind.includes('Remove') || eventKind.includes('Name');
const targetsCurrentDocument = Boolean(documentId && documentId === targetSession.documentId);
if (documentId && !targetsCurrentDocument && !mayAffectMissingDocument) return;
if (targetsCurrentDocument && shouldSuppressLocalFolderSelfChange(documentId, eventKind)) {
targetSession.externalChangePending = false;
targetSession.lastSelfSaveSignalAt = Date.now();
return;
}
if (targetsCurrentDocument && targetSession.saving) {
targetSession.externalChangePending = false;
targetSession.lastSelfSaveSignalAt = Date.now();