Skip to content

[2.0.3] A removed row's cleanup that calls an action throws ACTION_CALLED_IN_OWNED_SCOPE (#4165 covered writes, not actions) #5123

Closed

Description

@cgaaf

Describe the bug

Removing a keyed row runs the row's cleanups inside the list's pass (updateKeyedMap → runWithOwner(this._owner, …)). #4165 / #4168 made the owned-scope write guard stand down while cleanups run, so a setter in a row's cleanup works. The action guard did not get the same exemption: if the cleanup invokes an action, development throws ACTION_CALLED_IN_OWNED_SCOPE and the action never runs.

The same cleanup runs without error when a <Show> / <Switch> branch disposes it (those park their children and dispose them at commit, with no owner), and in production the action runs and its write lands. The dev guard is the only thing that differs.

The guard, in packages/signals/src/core/action.ts (main at 99db9bc):

if (owner && !(owner._config & CONFIG_CHILDREN_FORBIDDEN) && !inRefCallback()) {

Its comment calls it the "Same scope test as setSignal", but setSignal, markRefresh and the store setter have also checked !disposalDepth since #4168.

Your Example Website or App

https://github.com/cgaaf/solid-action-in-row-cleanup

Steps to Reproduce the Bug or Issue

  1. Clone the example repo and run npm install.
  2. Run npm start (node --conditions=browser --conditions=development repro.mjs). Both conditions are needed: without browser, solid-js resolves to its server build.
  3. See flush() throw ACTION_CALLED_IN_OWNED_SCOPE and the action not run, while the same cleanup's plain write works.
  4. Run npm run prod (--conditions=browser only): the action runs.

repro.mjs:

import { action, createRoot, createSignal, flush, mapArray, onCleanup, createRenderEffect } from "solid-js";

function run(label, release) {
  const [rows, setRows] = createSignal([1, 2]);
  createRoot(() => {
    const mapped = mapArray(rows, r => {
      onCleanup(release);
      return r;
    });
    createRenderEffect(mapped, () => {});
  });
  flush();
  setRows([2]);
  try {
    flush();
  } catch (e) {
    console.log(`${label}: flush() threw ${e.message.slice(0, 60)}…`);
  }
}

const [count, setCount] = createSignal(0);
run("write", () => setCount(n => n + 1)); // allowed since #4165
flush();
console.log("write:  count =", count());

const [acted, setActed] = createSignal(0);
const release = action(function* () {
  yield Promise.resolve(); // e.g. tell the server
  setActed(n => n + 1);
});
run("action", () => void release());
await new Promise(r => setTimeout(r, 0));
flush();
console.log("action: acted =", acted());

Development:

write:  count = 1
action: flush() threw [ACTION_CALLED_IN_OWNED_SCOPE] Calling an action inside an o…
action: acted = 0

Production (--conditions=browser only):

write:  count = 1
action: acted = 1

The same happens with an effect's returned cleanup and with onSettled(() => () => …). Which teardowns hit it, on 2.0.3:

Teardown Owner in cleanup Development
mapArray / <For> drops a row (effect-returned cleanup or onCleanup) the list's owner throws
mapArray to [] the list's owner throws
mapArray with keyed: false, repeat, <Repeat> shrinking the list's owner throws
root.dispose() inside a memo's compute, or under runWithOwner(parent) the caller's owner throws
<Show>, <Switch>/<Match>, a branch memo none (disposed at commit) runs
Effect re-run (previous cleanup), top-level root.dispose() none runs

In production every row runs.

Expected behavior

Development matches production: the action runs. A cleanup is teardown, not part of the list computation disposing it, which is the reasoning #4168 applied to writes.

The error is collected by runCleanup and rethrown when the flush ends, so the list itself still reconciles. What breaks is the lost action and the throw out of flush(). The rethrow can also land on an unrelated node: in our ReactiveScript reproduction, the flush that removed the row was the one watchAsyncTail ran to deliver an async read's answer, so its try { asyncWrite(v) } catch (e) { handleError(e) } recorded the cleanup's error as that read's error.

Screenshots or Videos

None; output above.

Platform

  • OS: macOS
  • Browser: none; Node 26.13.1 (the bug is in @solidjs/signals, so no DOM is needed)
  • Version: solid-js 2.0.3 (latest); also reproduced on main at 99db9bc

Additional context

Proposed fix. Add !disposalDepth to the action guard, as #4168 did for the write guards. PR: #5124, with tests in signals and web that fail without the change and pass with it. On main with the change, all 20 cases in our disposer matrix (the rows above and their variants) behave the same in development as in production, and the signals, solid-js and web suites pass.

Two related things the PR leaves alone:

  • onFlush has the same guard shape without disposalDepth (ON_FLUSH_IN_OWNED_SCOPE, a warning). Not tested from a cleanup.
  • An action that awaits holds the list update that removed the row. If the action's yield waits on a pending promise, the removed row stays rendered until that promise settles; a <Show> that switches away is not held. This already happens in production on 2.0.3, and with the cleanup wrapped in runWithOwner(null, …), because the action joins the running flush's transaction regardless of owner. The fix does not change it. Whether a teardown action should join that flush may be worth a separate look.

How we hit it. Through ReactiveScript, which compiles to Solid 2. Its components can only update a parent's state through an action the parent passes down, so a part that registers an id with its parent on mount unregisters it from an effect cleanup by calling that action. Inside a keyed list, refreshing the list's data throws in development.


AI disclosure. GPT 6.2 Astra (in Codex) first hit this error in a ReactiveScript component library. Claude Opus 5.5 (in Claude Code) traced it to the action() guard, wrote the reproductions and ran them on published 2.0.3, and wrote and tested the fix on main at 99db9bc. Claude Fable 5.2 independently reviewed the report, reran the reproductions and built the disposer matrix. Gemini 4 Carbon (in the Antigravity CLI) independently reviewed the report against the 2.0.3 source without running code; it identified the held-row interaction above, which Claude Opus 5.5 then confirmed by running it. Claude Opus 5.5 reran every reproduction and the matrix before posting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions