Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 5, 2026

The subscribe callback was executing enforceBlockNesting, enforceBlockSelection, and lockFormBlock on every editor state change, causing performance issues during editing.

Changes

  • State tracking: Added tracking for root block IDs, selected block ID, and lock status to detect actual changes
  • Conditional execution: Operations now only run when their relevant state changes:
    • enforceBlockNesting - only when root blocks are added, removed, or reordered
    • enforceBlockSelection - only when selection changes
    • lockFormBlock - only once, verified by checking lock attributes directly

Before/After

Before:

if (isCurrentPostTypeJetpackForm) {
  locateFormBlock();
  enforceBlockNesting();      // Every state change
  enforceBlockSelection();    // Every state change
  lockFormBlock();            // Every state change
}

After:

if (isCurrentPostTypeJetpackForm) {
  if (!formBlockClientId) locateFormBlock();
  
  const currentRootBlockIds = JSON.stringify(rootBlocks.map(b => b.clientId));
  if (currentRootBlockIds !== lastRootBlockIds) {
    enforceBlockNesting();    // Only when root blocks change
  }
  
  if (currentSelectedBlockId !== lastSelectedBlockId) {
    enforceBlockSelection();  // Only when selection changes
  }
  
  if (!isFormBlockLocked && formBlockClientId) {
    lockFormBlock();          // Only once
    // Verify via attributes
  }
}

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Address feedback on form editor implementation Optimize form editor subscribe callback to prevent unnecessary operations Jan 6, 2026
Copilot AI requested a review from enejb January 6, 2026 00:06
@enejb enejb closed this Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants