fix(word-addin): stop the workflow editor from losing edits or resurrecting stale views

↗ view on GitHub · Amal · 2026-08-12 · 48d18fe4

WHY THIS MATTERS
The prompt editor auto-saves on an 800ms debounce. Three lifecycle bugs
hid in that convenience:
1. Navigating away inside the debounce window cleared the timer without
   firing it -- the user's typed instructions silently vanished.
2. If an updateWorkflow call was in flight when the user deselected,
   its .then called onSelectedWorkflowChange, which the App wires
   straight into page navigation -- re-opening the detail view for a
   workflow the user had just left.
3. The "Saved -> idle" status timer was never tracked, so it could
   stamp "idle" over a newer "Saving..." and fire after unmount.

WHAT IS A DEBOUNCE FLUSH
A debounce trades latency for batching, which is only safe while the
component lives. At any teardown boundary (unmount, deselect, switch)
the pending work must either flush or be knowingly discarded; silently
dropping it turns an optimization into data loss.

HOW IT WORKS
- pendingSaveRef holds the latest unsaved edit; flushPendingSave()
  fires it (fire-and-forget) from the effect cleanup, which runs on
  deselect, workflow switch, and unmount.
- selectedIdRef is nulled in cleanup and re-set synchronously by the
  next effect run; the save's .then/.catch check it, so a late
  resolution for a departed workflow can no longer navigate or write
  status.
- The status-reset timer lives in statusResetTimerRef and is cleared
  on every new edit and in cleanup.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015U1iPxsADQ2yuksNmDuvvW
Repository open-legal-products/mike
Author Amal <mamalanand3@gmail.com>
Authored
Committed
Parents daf680f3
Stats 1 file changed , +64 , -3
Part of Bring the Word add-in chat experience in line with the web app

Capture this commit into my fork

Download a Markdown prompt that tells Claude how to port this exact commit into your working tree. Run it via claude -p < capture-commit-48d18fe4.md from inside the repo you want the change in.

⬇ Download capture-commit-48d18fe4.md