Skip to content

[BUG] WordPress Post Editor Crashes - 'Unexpected Error' Prevents Draft Saving #5

@loomster321

Description

@loomster321

Summary

When attempting to save a draft of a blog post with AI-generated content, the WordPress editor crashes with an 'unexpected error' message, preventing users from saving their work.

Screenshot

The error displays: 'The editor has encountered an unexpected error' with options to 'Copy Post Text' or 'Copy Error'
Location: /home/timl/dev/WP_ContentFlow/tmp/Screenshot 2025-09-11 061421.png

WordPress Environment

  • WordPress Version: 6.0+
  • PHP Version: 8.1+
  • Browser: Chrome/Edge (latest)
  • Plugin Version: 1.0.0
  • Theme: Default WordPress theme

Steps to Reproduce

  1. Log into WordPress admin dashboard
  2. Navigate to Posts → Add New
  3. Add the AI Text Generator block to the post
  4. Generate content using the AI block
  5. Attempt to save the post as a draft
  6. Editor crashes with 'The editor has encountered an unexpected error'

Expected Behavior

  • Post should save successfully as a draft
  • AI-generated content should be preserved
  • Editor should remain stable and functional

Actual Behavior

  • Editor crashes with unexpected error
  • Post cannot be saved
  • User loses all work if page is refreshed
  • Error appears immediately upon save attempt

Technical Analysis

Potential causes:

  1. Block Validation Error: The AI Text Generator block may be producing invalid HTML that breaks Gutenberg's validation
  2. JavaScript Conflict: Async state updates in the block may be conflicting with WordPress save process
  3. REST API Error: The save request may be failing due to malformed data from the AI block
  4. React State Issue: The block's React state may be corrupted during content generation

Impact

  • Critical: Users cannot save any posts containing AI-generated content
  • Data Loss: Users lose all work when editor crashes
  • Workflow Blocking: Core functionality of the plugin is broken

Acceptance Criteria

  • Posts with AI-generated content can be saved as drafts without errors
  • Editor remains stable during and after AI content generation
  • No JavaScript errors in browser console during save
  • Block validation passes for all generated content
  • Error recovery allows users to save their work

Testing Requirements

  1. Unit Tests: Validate block output structure
  2. Integration Tests: Test save process with AI content
  3. E2E Tests: Full workflow from content generation to draft save
  4. Browser Testing: Verify across Chrome, Firefox, Safari, Edge

Priority

P1 - Critical: This is a complete blocker for the plugin's core functionality. Users cannot use the plugin if they cannot save posts.

Related Components

  • blocks/ai-text-generator/index.js - Block implementation
  • assets/js/blocks.js - Block registration and state management
  • WordPress Gutenberg block editor
  • WordPress REST API save endpoint

Suggested Fix Approach

  1. Add proper error boundaries to the React component
  2. Validate generated HTML before setting block attributes
  3. Implement proper cleanup in useEffect hooks
  4. Add defensive checks for undefined/null values in save function
  5. Test with WordPress debug mode enabled to capture detailed errors

Next Steps for Developer

  1. Click 'Copy Error' button in the screenshot to get full stack trace
  2. Check browser console for JavaScript errors
  3. Enable WordPress debug logging (WP_DEBUG, WP_DEBUG_LOG)
  4. Test with minimal plugin setup to isolate conflict
  5. Review block's save() function for serialization issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    human-qaReady for human testing

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions