fix: simplify editor content loading to prevent infinite loops
- Use a simple contentLoaded flag to load content once when editor is ready - Remove complex change detection that was causing infinite update loops - Remove debug logging now that issue is resolved 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
922da5cf33
commit
75b61021a0
3 changed files with 7 additions and 47 deletions
|
|
@ -51,9 +51,6 @@
|
|||
})
|
||||
|
||||
function populateFormData(data: Project) {
|
||||
console.log('ProjectForm - populateFormData called with:', data);
|
||||
console.log('ProjectForm - caseStudyContent:', data.caseStudyContent);
|
||||
|
||||
formData = {
|
||||
title: data.title || '',
|
||||
subtitle: data.subtitle || '',
|
||||
|
|
@ -75,8 +72,6 @@
|
|||
content: [{ type: 'paragraph' }]
|
||||
}
|
||||
}
|
||||
|
||||
console.log('ProjectForm - formData.caseStudyContent after populate:', formData.caseStudyContent);
|
||||
isLoading = false
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -161,47 +161,23 @@
|
|||
}
|
||||
}
|
||||
|
||||
// Watch for external data changes and update editor
|
||||
let lastDataString = '';
|
||||
// Simple effect to load content once when editor is ready
|
||||
let contentLoaded = false;
|
||||
$effect(() => {
|
||||
if (editor && data && data.content) {
|
||||
console.log('ComposerCore effect - data received:', data);
|
||||
|
||||
// Validate content structure
|
||||
const isValidContent = data.type === 'doc' && Array.isArray(data.content);
|
||||
if (!isValidContent) {
|
||||
console.error('ComposerCore effect - invalid content structure:', data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (editor && data && !contentLoaded) {
|
||||
// Check if the data has actual content (not just empty doc)
|
||||
const hasContent = data.content.length > 0 &&
|
||||
const hasContent = data.content && data.content.length > 0 &&
|
||||
!(data.content.length === 1 && data.content[0].type === 'paragraph' && !data.content[0].content);
|
||||
|
||||
console.log('ComposerCore effect - hasContent:', hasContent);
|
||||
|
||||
if (hasContent) {
|
||||
// Compare with last known data to avoid unnecessary updates
|
||||
const currentDataString = JSON.stringify(data);
|
||||
|
||||
if (currentDataString !== lastDataString) {
|
||||
console.log('ComposerCore effect - updating editor with:', data);
|
||||
// Update the editor with new content
|
||||
try {
|
||||
// Set the content once
|
||||
editor.commands.setContent(data);
|
||||
lastDataString = currentDataString;
|
||||
console.log('ComposerCore effect - editor updated successfully');
|
||||
} catch (error) {
|
||||
console.error('ComposerCore effect - error updating editor:', error);
|
||||
}
|
||||
}
|
||||
contentLoaded = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
onMount(() => {
|
||||
console.log('ComposerCore onMount - initial data:', data);
|
||||
|
||||
// Get extensions with custom options
|
||||
const extensions = getEditorExtensions({
|
||||
showSlashCommands,
|
||||
|
|
@ -219,7 +195,6 @@
|
|||
{
|
||||
onCreate: () => {
|
||||
isLoading = false
|
||||
console.log('ComposerCore - editor created');
|
||||
},
|
||||
onUpdate: handleUpdate,
|
||||
editable,
|
||||
|
|
|
|||
|
|
@ -32,16 +32,6 @@ export const initiateEditor = (
|
|||
options?: Partial<EditorOptions>,
|
||||
placeholder?: string
|
||||
): Editor => {
|
||||
console.log('initiateEditor called with:', {
|
||||
element,
|
||||
content,
|
||||
contentType: typeof content,
|
||||
limit,
|
||||
hasExtensions: !!extensions,
|
||||
hasOptions: !!options,
|
||||
placeholder
|
||||
});
|
||||
|
||||
const editor = new Editor({
|
||||
element: element,
|
||||
content: content,
|
||||
|
|
|
|||
Loading…
Reference in a new issue