Skip to content

Commit a4ab913

Browse files
committed
docs: user-facing createOwner doc, list createScopeOwner in internal.ts, scope the changeset
Review nits on #4508, comment-only: the public `createOwner` shows a user-facing doc comment instead of the maintainer note, the `solid-js/internal` header lists `createScopeOwner`, and the changeset no longer says "again" (a detached `getOwner().dispose` on other owner kinds still throws; out of #4444's scope). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent 0753ed9 commit a4ab913

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

‎.changeset/owner-detached-dispose-4444.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
"@solidjs/web": patch
55
---
66

7-
`createOwner()`'s `dispose` can be passed around as a plain function again — `queueMicrotask(o.dispose)`, `setTimeout(o.dispose)` — instead of throwing `TypeError: Cannot read properties of undefined (reading '_flags')` (#4444). The method was a shared function reading its owner from `this`, which a detached call leaves undefined; the exported `createOwner` now binds it, as `createRoot`'s dispose already was. Internal owners (`mapArray` rows, boundaries) keep the shared method, so they pay no allocation. `NoHydration`, `Portal` and a frame's fill use the unbound owner too, through `solid-js/internal`, so apps that never call `createOwner` pay nothing.
7+
`createOwner()`'s `dispose` can be passed around as a plain function — `queueMicrotask(o.dispose)`, `setTimeout(o.dispose)` — instead of throwing `TypeError: Cannot read properties of undefined (reading '_flags')` (#4444). The method was a shared function reading its owner from `this`, which a detached call leaves undefined; the exported `createOwner` now binds it, as `createRoot`'s dispose already was. Internal owners (`mapArray` rows, boundaries) keep the shared method, so they pay no allocation. `NoHydration`, `Portal` and a frame's fill use the unbound owner too, through `solid-js/internal`, so apps that never call `createOwner` pay nothing.

‎packages/signals/src/core/owner.ts‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -444,15 +444,18 @@ export function createOwner(options?: { id?: string; transparent?: boolean }) {
444444
return owner;
445445
}
446446

447+
// The exported `createOwner` (the internal one is above): its `dispose` is
448+
// bound to the owner, so it can be handed around as a plain function, as
449+
// `createRoot`'s dispose can (#4444). Internal owners (a `mapArray` row, a
450+
// boundary) keep the shared `this`-reading method: they are only ever disposed
451+
// as `o.dispose()`, and a bound function per row would be an allocation per row.
447452
/**
448-
* The exported `createOwner` (see `createOwner` above): its `dispose` is bound
449-
* to the owner, so it can be handed around as a plain function —
450-
* `queueMicrotask(o.dispose)`, `setTimeout(o.dispose)` — as `createRoot`'s
451-
* dispose can (#4444). Internal owners (a `mapArray` row, a boundary) keep the
452-
* shared `this`-reading method: they are only ever disposed as `o.dispose()`,
453-
* and a bound function per row would be an allocation per row.
454-
*
455-
* @internal
453+
* Creates a fresh owner attached as a child of the current owner (or as a
454+
* detached root if there is none), to group cleanups and context under one
455+
* scope. Its `dispose()` tears that scope down and is bound to the owner, so it
456+
* can be passed around as a plain function: `queueMicrotask(owner.dispose)`.
457+
* To host a reactive scope outside a component, prefer `createRoot()`; to
458+
* re-enter a captured owner, use `runWithOwner()`.
456459
*/
457460
export function createPublicOwner(options?: { id?: string; transparent?: boolean }) {
458461
const owner = createOwner(options);

‎packages/solid/src/internal.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
* build boundaries without the components, and so are `sharedConfig`
2828
* (the hydration/SSR coordination object) and the `$DEVCOMP` brand.
2929
*
30+
* Also re-exported from `@solidjs/signals`: `createScopeOwner`, the owner the
31+
* runtimes create for their own scopes (`NoHydration`, `Portal`, a frame's
32+
* fill). It keeps the shared `this`-reading `dispose`, where the public
33+
* `createOwner` binds it per owner (#4444).
34+
*
3035
* Not here: the container-trace materializer. It lives in its own entry,
3136
* `solid-js/internal/container-trace`, so the store engine it builds on can
3237
* be a lazy chunk — a re-export from this (eagerly imported) module would

0 commit comments

Comments
 (0)