Skip to content

fix(signals): a removed row's cleanup can call an action during teardown (#5123) - #5124

Merged
ryansolid merged 1 commit into
solidjs:mainfrom
cgaaf:fix/action-in-teardown-cleanup
Nov 20, 2026
Merged

ryansolid merged 1 commit into
solidjs:mainfrom
cgaaf:fix/action-in-teardown-cleanup

Conversation

@cgaaf

@cgaaf cgaaf commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #5123.

#4168 let a cleanup write during teardown: the owned-scope write guard (setSignal, markRefresh, the store setter) stands down while disposalDepth is raised, because a cleanup is not part of whichever computation is disposing its owner. The action() guard, whose comment calls it the "Same scope test as setSignal", did not get the exemption. So a keyed row whose cleanup invokes an action still threw ACTION_CALLED_IN_OWNED_SCOPE in development, while the same cleanup under a branch, or in production, ran.

  • packages/signals/src/core/action.ts: add !disposalDepth to the dev-only guard and extend its comment.
  • packages/signals/tests/for-row-cleanup-action.test.ts: a removed row's onCleanup and effect-returned cleanup can call an action. Two controls: a branch's cleanup can (it already could), and an action called in a row's mapping body is still rejected.
  • packages/web/test/for-row-cleanup-action.spec.tsx: the same through <For>, with onSettled(() => cleanup) and onCleanup, using an action that awaits before writing. Modeled on for-row-cleanup-write-4165.spec.tsx.
  • Changeset: @solidjs/signals patch.

Production builds are unchanged: the guard is __DEV__ only. Cleanups keep their owner, as #4168 decided.

Tradeoffs

Dev no longer flags a row removal that an awaiting cleanup action holds back. An action started from a removed row's cleanup joins the flush that is removing the row. If it awaits, the row stays rendered until the await settles; a <Show> that switches away is not held this way. That already happens in production, and with the cleanup wrapped in runWithOwner(null, …), because the action joins the running flush whatever the owner. Before this change the dev guard threw on this pattern, though because of the owner, not the hold, and it threw just the same for an action with no await. After it, development behaves as production does. Whether a teardown action should join that flush is a separate question; this change does not alter it.

No new loop risk compared with #4168. The guard partly exists so a computation can't loop on writes it tracks. A row cleanup that writes the list's own source behaves the same whether it uses a setter (allowed since #4168) or an action: the list shrinks one row per removal until empty, then stops.

Alternatives considered

  • Run cleanups with no owner. That would also stop the throw, but fix(signals): a removed row's cleanup can write during teardown (#4165) #4168 kept the owner and context in cleanups on purpose, and it changes production: an action's first step, run under the disposing owner, sees writes already pending in that flush, and with no owner it reads committed state. Two removed rows each running count + 1 from their cleanups end at 2 today and at 1 with no owner. It also leaves the held row above unchanged.
  • Keep the guard and document "no actions in cleanups". That keeps a dev signal for the held-row case, but it also rejects actions that never await, keeps setters and actions inconsistent in the same cleanup, and gives an error that names a component body or computation when the cause is a list removing a row.

onFlush has the same guard shape (a warning) without disposalDepth. I left it alone; happy to add it here.

How did you test this change?

All on main at 99db9bc, after pnpm i and building every package (native compiler in debug mode), with signals rebuilt before each run because web and solid-js test against its dist.

New tests, without and with the change in action.ts:

without:  signals  for-row-cleanup-action.test.ts    2 failed | 2 passed   (the 2 controls pass)
          web      for-row-cleanup-action.spec.tsx   2 failed              ACTION_CALLED_IN_OWNED_SCOPE
with:     signals  for-row-cleanup-action.test.ts    4 passed
          web      for-row-cleanup-action.spec.tsx   2 passed

turbo run test test-types typecheck --filter=!test-integration --filter=!@solidjs/compiler --force --continue (the pnpm test task list):

Package Without the change With the change
@solidjs/signals 7244 passed, 2 failed (the new test) 7246 passed, 17 expected fail, 2 skipped
@solidjs/web jsdom config: 2020 passed, 2 failed (the new spec); server and hydrate configs did not run, since the script stops at the first failure jsdom 2022, server 2215, hydrate 788 passed
solid-js 931 passed, 1 failed (environment, below) 931 passed, 1 failed (same)
every other package, test-types, typecheck passed passed

Both runs failed in two places for reasons in my checkout, not the change:

  • solid-js's cross-package-fields.spec.ts scans packages/universal/dist, which my filtered build had not produced. After building universal, solid-js passed 932 of 932 with the change (rerun separately).
  • chat-client-example: its Vite config could not resolve @solidjs/signals from the built solid-js here; the examples did not build in this checkout either.

Prettier passes on the changed files.

ReactiveScript, which compiles to Solid 2, pins Solid at 2105ffb (2.0.0-rc.21) and builds it from source. With the same one-condition change applied there, its oracle and compiled runners (scenarios lowered onto Solid, and compiled modules run on it) each pass 130 of 130 scenarios, the same per-scenario results as without the change, and its interpreter runner passes. Its ssr (Chromium) and types runners were not run. None of its scenarios covers a list-row cleanup calling an action, so this shows only that nothing regressed.


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 this change and both tests, and ran the before/after tests, the Solid suite, and ReactiveScript's interpreter, oracle and compiled runners. Claude Fable 5.2 independently reviewed the report and verified the same fix against more disposers. Gemini 4 Carbon (in the Antigravity CLI) independently reviewed the report against the source and raised the held-row question, which Claude Opus 5.5 then measured.

🤖 Generated with Claude Code

…own (solidjs#5123)

solidjs#4168 let a cleanup write during teardown by standing the owned-scope write
guard down while disposalDepth is raised. The action() guard, which its
comment calls the same scope test as setSignal, did not get the exemption, so
a keyed row whose cleanup invokes an action threw ACTION_CALLED_IN_OWNED_SCOPE
in development while production ran it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Nov 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f757343

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@solidjs/signals Patch
@solidjs/web Patch
@solidjs/diagnostics Patch
solid-js Patch
@solidjs/universal Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codspeed

codspeed Bot commented Nov 20, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 12.65%

3 warnings

⚠️ Upgrade your CodSpeed plugin for Node.js 24

@codspeed/* 5.4.0 is only tested on Node.js 18, 20, and 22, so your Node.js 24 measurements may be inaccurate. Upgrade your @codspeed/* packages to 6.0.0 or later.

See affected benchmarks

⚠️ 2 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 1 benchmark with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

❌ 1 regressed benchmark
✅ 200 untouched benchmarks
⏩ 5 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ arrow in template 10.9 ms 12.5 ms -12.65%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing cgaaf:fix/action-in-teardown-cleanup (f757343) with main (99db9bc)

Open in CodSpeed

Footnotes

  1. 5 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@cgaaf

cgaaf commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

The CodSpeed flag on arrow in template does not come from this change. The benchmark never runs the code this PR touches.

What the PR changes at run time. I built @solidjs/signals at main (99db9bc) and at this branch (f757343) and compared dist:

  • dist/prod and dist/observe are byte-identical.
  • dist/dev.js differs in one place: the extra !disposalDepth && in the action() guard (and its comment). Everything else in the diff of dev.js, dev.attribution.js and dev-shared.js is re-lettered import/export aliases between the chunks.

The benchmark does not reach it. bench:server loads dist/dev.js. With a marker on the first line of action() in that file, non-ascii-template.bench.tsx ran both benchmarks without printing it once, so the guard, which sits in the function action() returns, never runs there. CodSpeed's flame graph for the head run shows the same thing: renderToString → For → mapArray → ssr, with no action frame.

The same flag appears on PRs that cannot affect this benchmark. CodSpeed marks this benchmark, and only this one, as having "ran on different hardware" between base and head. Recent PRs got the same benchmark flagged by about the same amount, with the same warning:

PR Touches arrow in template
#5079 packages/html 10.9 ms → 12.6 ms, -13.12%
#5074 packages/h 10.9 ms → 12.6 ms, -12.91%
#5055 packages/signals, packages/solid 11 ms → 12.4 ms, -11.14%
#5052 packages/web, docs 11.1 ms → 12.4 ms, -10.51%
#5085 packages/signals, packages/web 11.2 ms → 12.6 ms, -11.37%
#4660 packages/web (docs label) 11 ms → 12.4 ms, -11.19%
this PR packages/signals (dev-only guard) 10.9 ms → 12.5 ms, -12.65%

Its history on next shows the same two levels, about 10.9 ms and about 12.5 ms, alternating over the past month. I have not established why this benchmark is sensitive to the runner while its ascii only twin (-2% here) is not.


Investigated with Claude Fable 5.2 (in Claude Code), which built both commits, compared the bundles and ran the marker check locally. GPT 6.2 Astra (in Codex) and Gemini 4 Carbon (in the Antigravity CLI) each traced the benchmark's path independently and reached the same conclusion.

@ryansolid
ryansolid merged commit 83d42ba into solidjs:main Nov 20, 2026
13 of 14 checks passed
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.

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

2 participants