fix rendering delay

This commit is contained in:
2025-10-13 03:19:31 +03:00
parent 0321d7f9d3
commit cbf7aa2a91
2 changed files with 29 additions and 2 deletions

View File

@@ -29,7 +29,13 @@ async function renderVisualization() {
// Debounced render function
function debouncedRender() {
clearTimeout(renderTimeout);
renderTimeout = setTimeout(renderVisualization, 1500); // 500ms delay
// If we're updating the editor programmatically, render immediately
if (window.isUpdatingEditor) {
renderVisualization();
} else {
renderTimeout = setTimeout(renderVisualization, 1500); // 1.5s delay for user edits
}
}
// Load Vega libraries dynamically with UMD builds

View File

@@ -377,6 +377,15 @@ function clearSelection() {
item.classList.remove('selected');
});
// Clear editor content
if (editor) {
window.isUpdatingEditor = true;
editor.setValue('{}');
setTimeout(() => {
window.isUpdatingEditor = false;
}, 50);
}
// Hide meta panel and show placeholder
const metaSection = document.getElementById('snippet-meta');
const placeholder = document.querySelector('.placeholder');
@@ -418,9 +427,13 @@ function selectSnippet(snippetId) {
});
document.querySelector(`[data-snippet-id="${snippetId}"]`).classList.add('selected');
// Load draft spec into editor
// Load draft spec into editor (prevent auto-save during update)
if (editor) {
window.isUpdatingEditor = true;
editor.setValue(JSON.stringify(snippet.draftSpec, null, 2));
setTimeout(() => {
window.isUpdatingEditor = false;
}, 50); // Small delay to ensure setValue completes
}
// Show and populate meta fields
@@ -453,6 +466,7 @@ function selectSnippet(snippetId) {
// Auto-save functionality
let autoSaveTimeout;
window.isUpdatingEditor = false; // Global flag to prevent auto-save/debounce during programmatic updates
// Save current editor content as draft for the selected snippet
function autoSaveDraft() {
@@ -473,6 +487,9 @@ function autoSaveDraft() {
// Debounced auto-save (triggered on editor changes)
function debouncedAutoSave() {
// Don't auto-save if we're programmatically updating the editor
if (window.isUpdatingEditor) return;
clearTimeout(autoSaveTimeout);
autoSaveTimeout = setTimeout(autoSaveDraft, 1000); // 1 second delay
}
@@ -608,7 +625,11 @@ function deleteSnippet(snippetId) {
if (window.currentSnippetId === snippetId) {
window.currentSnippetId = null;
if (editor) {
window.isUpdatingEditor = true;
editor.setValue('{}');
setTimeout(() => {
window.isUpdatingEditor = false;
}, 50);
}
// Hide comment field and show placeholder
const metaSection = document.getElementById('snippet-meta');