Skip to content

fix: redundant rebuild trigger on every keystroke in editor containers #779

@23harshitkumar

Description

@23harshitkumar

Bug Report 🐛

Current Behavior

All the three editor containers (ie TemplateMarkdown, TemplateModel, AgreementData) call the main state setter twice per keystroke. The useUndoRedo hook already calls onSync (the rebuild triggering function) internally but then the handleChange function calls it again via setTemplateMarkdown(val) which is a redundancy issue causing two rebuilds per change/keystroke.

Understanding the flow of execution:

  1. User types or makes a change in an editor (say TemplateMarkdown)
  2. handleChange() is triggered inside that component
  3. setValue(val) inside useUndoRedo hook runs
  4. onSync() is called and rebuild() is triggered automatically via setTemplateMarkdown as it was passed as argument in onSync
  5. handleChange() again causes another rebuild for that same keystroke
const handleChange = (val: string | undefined) => {
  if (val !== undefined) {
    updateEditorActivity("markdown");  
    setValue(val);                     
    void setTemplateMarkdown(val);     
  }
};

Expected Behavior

Each keystroke should trigger only one rebuild, not two.

Possible Solution

Remove the redundant explicit setter calls from handleChange() in:

  • TemplateMarkdown.tsx
  • TemplateModel.tsx
  • AgreementData.tsx

Impact:

This will eliminate unnecessary duplicate rebuilds on every keystroke and reduce redundant Zustand state updates!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions