Repository navigation
fix(signals): a removed row's cleanup can call an action during teardown (#5123) - #5124
Conversation
…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 detectedLatest commit: f757343 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
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 |
Merging this PR will degrade performance by 12.65%3 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
|
The CodSpeed flag on What the PR changes at run time. I built
The benchmark does not reach it. 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:
Its history on
|
Summary
Fixes #5123.
#4168 let a cleanup write during teardown: the owned-scope write guard (
setSignal,markRefresh, the store setter) stands down whiledisposalDepthis raised, because a cleanup is not part of whichever computation is disposing its owner. Theaction()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 threwACTION_CALLED_IN_OWNED_SCOPEin development, while the same cleanup under a branch, or in production, ran.packages/signals/src/core/action.ts: add!disposalDepthto the dev-only guard and extend its comment.packages/signals/tests/for-row-cleanup-action.test.ts: a removed row'sonCleanupand 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>, withonSettled(() => cleanup)andonCleanup, using an action that awaits before writing. Modeled onfor-row-cleanup-write-4165.spec.tsx.@solidjs/signalspatch.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 inrunWithOwner(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
count + 1from their cleanups end at 2 today and at 1 with no owner. It also leaves the held row above unchanged.onFlushhas the same guard shape (a warning) withoutdisposalDepth. I left it alone; happy to add it here.How did you test this change?
All on
mainat 99db9bc, afterpnpm iand building every package (native compiler in debug mode), with signals rebuilt before each run becausewebandsolid-jstest against itsdist.New tests, without and with the change in
action.ts:turbo run test test-types typecheck --filter=!test-integration --filter=!@solidjs/compiler --force --continue(thepnpm testtask list):@solidjs/signals@solidjs/websolid-jstest-types,typecheckBoth runs failed in two places for reasons in my checkout, not the change:
solid-js'scross-package-fields.spec.tsscanspackages/universal/dist, which my filtered build had not produced. After buildinguniversal,solid-jspassed 932 of 932 with the change (rerun separately).chat-client-example: its Vite config could not resolve@solidjs/signalsfrom the builtsolid-jshere; 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
oracleandcompiledrunners (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. Itsssr(Chromium) andtypesrunners were not run. None of its scenarios covers a list-row cleanup calling an action, so this shows only that nothing regressed.🤖 Generated with Claude Code