Skip to content

feat: auto-clean Story.on() handlers on restart (#128)#130

Merged
rohal12 merged 3 commits into
mainfrom
worktree-feat+auto-clean-runtime-handlers
Mar 26, 2026
Merged

feat: auto-clean Story.on() handlers on restart (#128)#130
rohal12 merged 3 commits into
mainfrom
worktree-feat+auto-clean-runtime-handlers

Conversation

@rohal12

@rohal12 rohal12 commented Mar 26, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add runtime phase tracking (trackRuntimeUnsub, enterRuntimePhase) to store.ts — handlers registered via Story.on() after executeStoryInit() are automatically unsubscribed when restart() runs
  • Wire all 5 event branches in Story.on() (navigate, beforerestart, storyinit, actionsChanged, variableChanged) to call trackRuntimeUnsub
  • Call enterRuntimePhase() before executeStoryInit() in both boot (index.tsx) and restart (store.ts) paths

Fixes #128

Design

Handlers registered during :storystartup (startup phase) survive restarts. Handlers registered from executeStoryInit() onwards (runtime phase) are auto-cleaned on restart, after fireBeforeRestart() fires but before state resets. This prevents duplicate handler accumulation when host apps re-register during storyinit.

Test plan

  • trackRuntimeUnsub is a no-op before enterRuntimePhase
  • Tracked unsubs are called on restart
  • Startup-phase handlers survive restart
  • Unsubs cleared after restart (not called twice)
  • Navigate handler cleaned on restart via Story.on()
  • beforerestart handler fires before being cleaned
  • No duplicate handlers after multiple restart cycles
  • Manual unsub + double-call is safe

🤖 Generated with Claude Code

clem and others added 3 commits March 26, 2026 23:17
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Every event branch in Story.on() now captures the unsub function and
passes it to trackRuntimeUnsub() so handlers registered during the
runtime phase are automatically cleaned on restart.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Release preview: merging this PR will publish v0.40.0 (minor bump from v0.39.1)

@github-actions

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 77.71% 2751 / 3540
🔵 Statements 76.8% 3013 / 3923
🔵 Functions 68.79% 507 / 737
🔵 Branches 73.96% 1506 / 2036
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/index.tsx 0% 0% 0% 0% 21-219
src/store.ts 80.55% 72.72% 73.19% 82.31% 90, 124, 348-349, 412, 421-424, 455-460, 552, 607, 630-633, 647, 651-654, 666-738
src/story-api.ts 26.21% 14.06% 25% 27.09% 167-176, 186-190, 198-282, 295-373, 402-453, 480-485, 512-547
Generated in workflow #199 for commit f3ea200 by the Vitest Coverage Report Action

@rohal12 rohal12 enabled auto-merge March 26, 2026 15:35
@rohal12 rohal12 merged commit fa19765 into main Mar 26, 2026
5 checks passed
@rohal12 rohal12 deleted the worktree-feat+auto-clean-runtime-handlers branch March 26, 2026 15:36
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.

Auto-clean Story.on() handlers registered after storyinit on restart

1 participant