Repository navigation
Description
Describe the bug
The usage documented in the README:
import { createForm } from "@solid-primitives/form";
export default function Form() {
const form = createForm({ fields: { email: { initial: "" } } });
return (
<form ref={form.ref}>
<input ref={form.bind("email")} />
<button type="submit">Submit</button>
</form>
);
}Expected
Refs attach, the submit listener intercepts the native submit, and the form hydrates normally (as in Solid 1.x).
Actual
Dev build throws from the ref callback:
Error in a Solid app
Error: [CLEANUP_IN_FORBIDDEN_SCOPE] Cannot use onCleanup inside a ref callback; register it in the factory that returns the ref (the component body)
- Page:
/register
Stack
- … 9 frames in dependencies:
@solidjs/signals,@solid-primitives/utils,@solid-primitives/event-listener,@solid-primitives/form,@solidjs/web ref={form.ref}at/src/components/auth-form.tsx:99:43
Source
/src/components/auth-form.tsx:99:43
96 | </p>
97 | </div>
98 |
> 99 | <form class="flex flex-col gap-4" ref={form.ref}>
| ^
100 | <Show when={!isLogin()}>
101 | <Field data-invalid={form.fields.name.error() ? "true" : undefined}>
102 | <FieldLabel for="name">Name</FieldLabel>The throw aborts hydration of the rest of the tree. In an SSR + hydrate app the form's submit handler is never attached, so pressing submit performs a native GET submission — the fields, including the password, end up in the URL query string. The console also reports Hydration completed with N unclaimed server-rendered node(s) for the form's elements.
Root cause
packages/form/src/form.ts:
- ref calls makeEventListener(el, "submit", ...)
- bind calls makeEventListener(el, "input"|"change", ...) and makeEventListener(el, "blur", ...)
makeEventListener registers its removal with tryOnCleanup → onCleanup synchronously inside the ref callback. Solid 2 forbids cleanup registration there by design (dev throws; production strips the throw but the cleanup has no owner and never runs, leaking listeners). The Solid 2 contract is that a ref callback may only return its cleanup.
Activity
[-]form.ref / form.bind throw CLEANUP_IN_FORBIDDEN_SCOPE on Solid 2 and break form hydration[/-][+]@solid-primitives/form CLEANUP_IN_FORBIDDEN_SCOPE[/+]davedbase commentedon Nov 27, 2026
@akawahuynh let me know if the PR fully resolves the issue for you. I'll merge it as soon as you do.
akawahuynh commentedon Nov 27, 2026
All functions related to
makeEventListenerandtryOnCleanupforrefencounter the same issue—for example,focus():solid-primitives/packages/active-element/src/index.ts
Line 58 in a452f32
Or:
solid-primitives/packages/pagination/src/index.ts
Line 573 in a452f32
fix: don't use onCleanup or create primitives inside ref callbacks (a…
davedbase commentedon Nov 27, 2026
@akawahuynh good point I didn't think of it. I had an agent go through and identify the other call sites that are impacted (mediastream, lifecycle, active-element, cursor, mutation-observer and event-listener).
fix(form): don't use onCleanup or create primitives inside ref callbacks