Skip to content

fix: stop the auto-refresh timer on unmount (it repaints over other plugins) - #2

Open
AJV009 wants to merge 1 commit into
strykereye2:mainfrom
AJV009:fix/clear-interval-on-unmount
Open

fix: stop the auto-refresh timer on unmount (it repaints over other plugins)#2
AJV009 wants to merge 1 commit into
strykereye2:mainfrom
AJV009:fix/clear-interval-on-unmount

Conversation

@AJV009

@AJV009 AJV009 commented Aug 27, 2026

Copy link
Copy Markdown

Problem

After visiting the Sessions tab, switching to any other plugin tab shows the Claude Sessions table again a few seconds later — the other plugin's UI is replaced by this one's.

Reproduced against the PRISM plugin:

  1. Open the Sessions tab
  2. Switch to PRISM
  3. PRISM renders correctly, then within 10s its panel is replaced by the Claude Sessions table

Uninstalling this plugin made PRISM render correctly and permanently, which isolated the source.

Cause

intervalId and stopAuto() are declared inside mount()'s closure:

export function mount(container, api) {
  let intervalId = null;
  ...
  function stopAuto() {
    if (intervalId) { clearInterval(intervalId); intervalId = null; }
  }

but unmount() is a separate top-level export with no access to that closure:

export function unmount(container) {
  container.innerHTML = '';
  const styles = document.getElementById('sm-styles');
  if (styles) styles.remove();
}

So clearInterval is never called. The 10s timer outlives unmount and keeps calling fetchSessions(), which re-renders into the container captured by the closure. CloudCLI reuses a single container for the active tab plugin, so the orphaned timer paints this plugin's table over whatever is mounted there now.

Fix

Hold the closure's stopAuto in a module-scoped activeStopAuto and invoke it from unmount(). Three lines plus a comment.

dist/index.js is a verbatim copy of src/index.js (no build step), so both files are updated identically.

Verification

Linux, Chrome, CloudCLI 1.37.2, with PRISM installed alongside:

  • Before: switch Sessions → PRISM, PRISM's panel is replaced by the session table within 10s
  • After: PRISM's panel is still intact 16s later (well past one timer period), and the Sessions tab itself still renders and auto-refreshes normally

🤖 Generated with Claude Code

https://claude.ai/code/session_011WfoF1z5anUFtH61ECn1ZF

`intervalId` and `stopAuto()` are declared inside `mount()`'s closure, but
`unmount()` is a separate top-level export with no access to them. It clears
the container's innerHTML and removes the injected styles, but never calls
`clearInterval`.

The 10s auto-refresh timer therefore survives unmount and keeps calling
fetchSessions(), which re-renders into the `container` element captured by
the closure. CloudCLI reuses one container for the active tab plugin, so a
few seconds after switching away from Sessions the timer repaints the
session table over whichever plugin is now mounted there.

Reproduced with the PRISM plugin: select Sessions, switch to PRISM, and
within 10s PRISM's panel is replaced by the Claude Sessions table. Removing
this plugin made PRISM render correctly again, confirming the source.

Fix: hold the closure's stopAuto in a module-scoped `activeStopAuto` and
invoke it from unmount(). dist/index.js is a verbatim copy of src/index.js
(no build step), so both are updated.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011WfoF1z5anUFtH61ECn1ZF
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.

1 participant