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) {
|
function populateFormData(data: Project) {
|
||||||
console.log('ProjectForm - populateFormData called with:', data);
|
|
||||||
console.log('ProjectForm - caseStudyContent:', data.caseStudyContent);
|
|
||||||
|
|
||||||
formData = {
|
formData = {
|
||||||
title: data.title || '',
|
title: data.title || '',
|
||||||
subtitle: data.subtitle || '',
|
subtitle: data.subtitle || '',
|
||||||
|
|
@ -75,8 +72,6 @@
|
||||||
content: [{ type: 'paragraph' }]
|
content: [{ type: 'paragraph' }]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('ProjectForm - formData.caseStudyContent after populate:', formData.caseStudyContent);
|
|
||||||
isLoading = false
|
isLoading = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -161,47 +161,23 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Watch for external data changes and update editor
|
// Simple effect to load content once when editor is ready
|
||||||
let lastDataString = '';
|
let contentLoaded = false;
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (editor && data && data.content) {
|
if (editor && data && !contentLoaded) {
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the data has actual content (not just empty doc)
|
// 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);
|
!(data.content.length === 1 && data.content[0].type === 'paragraph' && !data.content[0].content);
|
||||||
|
|
||||||
console.log('ComposerCore effect - hasContent:', hasContent);
|
|
||||||
|
|
||||||
if (hasContent) {
|
if (hasContent) {
|
||||||
// Compare with last known data to avoid unnecessary updates
|
// Set the content once
|
||||||
const currentDataString = JSON.stringify(data);
|
editor.commands.setContent(data);
|
||||||
|
contentLoaded = true;
|
||||||
if (currentDataString !== lastDataString) {
|
|
||||||
console.log('ComposerCore effect - updating editor with:', data);
|
|
||||||
// Update the editor with new content
|
|
||||||
try {
|
|
||||||
editor.commands.setContent(data);
|
|
||||||
lastDataString = currentDataString;
|
|
||||||
console.log('ComposerCore effect - editor updated successfully');
|
|
||||||
} catch (error) {
|
|
||||||
console.error('ComposerCore effect - error updating editor:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
console.log('ComposerCore onMount - initial data:', data);
|
|
||||||
|
|
||||||
// Get extensions with custom options
|
// Get extensions with custom options
|
||||||
const extensions = getEditorExtensions({
|
const extensions = getEditorExtensions({
|
||||||
showSlashCommands,
|
showSlashCommands,
|
||||||
|
|
@ -219,7 +195,6 @@
|
||||||
{
|
{
|
||||||
onCreate: () => {
|
onCreate: () => {
|
||||||
isLoading = false
|
isLoading = false
|
||||||
console.log('ComposerCore - editor created');
|
|
||||||
},
|
},
|
||||||
onUpdate: handleUpdate,
|
onUpdate: handleUpdate,
|
||||||
editable,
|
editable,
|
||||||
|
|
|
||||||
|
|
@ -32,16 +32,6 @@ export const initiateEditor = (
|
||||||
options?: Partial<EditorOptions>,
|
options?: Partial<EditorOptions>,
|
||||||
placeholder?: string
|
placeholder?: string
|
||||||
): Editor => {
|
): Editor => {
|
||||||
console.log('initiateEditor called with:', {
|
|
||||||
element,
|
|
||||||
content,
|
|
||||||
contentType: typeof content,
|
|
||||||
limit,
|
|
||||||
hasExtensions: !!extensions,
|
|
||||||
hasOptions: !!options,
|
|
||||||
placeholder
|
|
||||||
});
|
|
||||||
|
|
||||||
const editor = new Editor({
|
const editor = new Editor({
|
||||||
element: element,
|
element: element,
|
||||||
content: content,
|
content: content,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue