# Modal lifecycle contract

## Outcome

Add the next independently revertible Delivery 5 lifecycle slice to the canonical `Modal`: idempotent `mount()`, `update(next)`, and `destroy()` methods that preserve existing modal behavior.

## Status

DONE — Task D5-MODAL-01 review correction is committed locally as `d4230ba17`.

## Task IDs

- D5-MODAL-01 — Modal lifecycle slice

## Source request

Owner requested the next smallest independently shippable Delivery 5 lifecycle-convergence component after ProgressBar, with focused tests, lint, build, and a local commit. No delegation or external models.

## Acceptance criteria

- Current inventory ordering identifies Modal as the next stateful foundational component after ProgressBar.
- Existing constructor and public modal APIs remain compatible.
- `mount()`, `update(next)`, and `destroy()` are idempotent and do not duplicate DOM or listeners.
- `open()` is idempotent: repeated calls neither replace the return-focus element nor schedule an additional focus animation frame.
- A content-only modal moves focus to its close button when opened.
- Cleanup removes owned DOM, listeners, focus ownership, and body/document mutations; remount remains usable.
- Focused lifecycle tests, JavaScript lint, and production build pass cleanly.
- The implementation commit contains only Modal, focused tests, required generated assets, and this registry receipt.

## Preserved WIP/ref/path

- Worktree: `/home/user/Projects/Press.zone/wordpress/wp-content/.worktrees/ipz-search-delivery5b`.
- The current worktree is clean.
- ProgressBar lifecycle commit `4427866f6` is not an ancestor of this worktree; incorporate it before implementing this next slice so the sequence stays coherent.
- Preserve unrelated work and existing Modal callers.

## Constraints

- Follow `.claude/agents/expert.md` and `.claude/skills/frontend-javascript.md`.
- Keep the Delivery 5 lifecycle contract independently revertible.
- Do not delegate or use external models.
- Do not deploy or test dev1.

## Execution steps

1. Incorporate the completed ProgressBar lifecycle commit without changing its behavior.
2. Read Modal, its callers, and current test conventions.
3. Add focused failing lifecycle tests.
4. Implement the narrow idempotent lifecycle contract and cleanup.
5. Run focused tests, lint, and production build; address all output.
6. Commit the Modal slice and update this receipt and the plan index.

## Current receipt

Review correction complete: `open()` now returns immediately while the modal is already open, retaining the original focus-return element and its single pending focus frame. The scheduled focus target falls back to the close button when content has no interactive element. Two focused regressions cover both findings. Focused Modal tests passed (7 tests); admin lint and production build passed. The correction commit hash is recorded in the plan index after commit.

## Next executable action

No further action in this slice. The next Delivery 5 component is Toast, based on the foundational inventory ordering.
