Skip to content

fix: add disconnect() cleanup to Stimulus controllers#4249

Merged
Paul-Bob merged 1 commit intoavo-hq:mainfrom
rickychilcott:fix/stimulus-controller-disconnect-cleanup
Feb 10, 2026
Merged

fix: add disconnect() cleanup to Stimulus controllers#4249
Paul-Bob merged 1 commit intoavo-hq:mainfrom
rickychilcott:fix/stimulus-controller-disconnect-cleanup

Conversation

@rickychilcott
Copy link
Contributor

@rickychilcott rickychilcott commented Feb 6, 2026

Summary

  • Fixes TypeError: Cannot read properties of null (reading 'scrollTop')) and similar errors caused by Stimulus controllers not cleaning up in disconnect()
  • Adds disconnect() to 7 controllers: tags_field, easy_mde, tippy, preview, table_row, media_library_attach, search
  • Fixes broken removeEventListener in record_selector (.bind() created non-matching refs so removal was a no-op)

Test plan

  • Visit an Avo page with tag fields, navigate away via Turbo, confirm no console errors
  • Test EasyMDE markdown fields across Turbo navigations
  • Test tooltip (tippy) fields across Turbo navigations
  • Test shift-click multi-select on index tables (record_selector) — previously accumulated duplicate listeners on each shift-click
  • Test global search keyboard shortcut (Cmd+K / Ctrl+K) works after Turbo navigation
  • Test media library file upload after Turbo navigation (no duplicate file inputs)

@github-actions github-actions bot added the Fix label Feb 6, 2026
…ation

Several Stimulus controllers initialize third-party libraries and event
listeners in connect() without tearing them down in disconnect(). During
Turbo navigation, this causes null reference errors (e.g. Honeybadger

Changes:
- tags_field: destroy Tagify instance
- easy_mde: call toTextArea() to restore textarea
- tippy + preview: destroy Tippy instances
- table_row: store bound handler refs for proper removal
- record_selector: fix broken removeEventListener (bind() created
  non-matching refs) and inconsistent keydown/keyup removal
- search: unbind Mousetrap keyboard shortcuts
- media_library_attach: remove programmatic file input to prevent
  duplicates on reconnect
@rickychilcott rickychilcott force-pushed the fix/stimulus-controller-disconnect-cleanup branch from daf79d9 to 35110cf Compare February 8, 2026 11:48
@rickychilcott rickychilcott marked this pull request as ready for review February 8, 2026 11:48
@rickychilcott
Copy link
Contributor Author

I noticed some of these errors over the years, but finally got motivated to fix them. Claude found some other issues along the way. I've tested all myself manually in my app, except for the EasyMDE fix but it seems pretty benign.

Hope this helps!

Copy link
Contributor

@Paul-Bob Paul-Bob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Thank you @rickychilcott for this contribution!

@Paul-Bob Paul-Bob merged commit 43cfec4 into avo-hq:main Feb 10, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants