Skip to content

feat: let a parent hold a child container weakly - #19

Merged
bebrasmell merged 1 commit into
mainfrom
feat/weak-parent-link
Aug 15, 2026
Merged

feat: let a parent hold a child container weakly#19
bebrasmell merged 1 commit into
mainfrom
feat/weak-parent-link

Conversation

@bebrasmell

Copy link
Copy Markdown
Contributor

A parent keeps a strong reference to every child it ever produced and releases it only when that child's destroy() runs. That is right by default, but wrong for a host that may build a container speculatively and then drop it without being told to — a React render that never commits retains one such container forever.

The new weakParentLink option reaches the child through a WeakRef and prunes the registration with a FinalizationRegistry once the child is collected. Reachable children are still destroyed by the parent cascade, so the default path is untouched. Needs both ES2021 primitives; where either is missing it warns once and keeps the strong link.

  • child() now takes container options, with parent always this container
  • pin the build to target es2015, the floor the README advertises: with no target esbuild emitted esnext, shipping ES2022 class static blocks and ES2021 logical assignment
  • state what that pin does not cover — module-scope globalThis (ES2020) and the JSR package, which ships src/ rather than the bundle

A parent keeps a strong reference to every child it ever produced and
releases it only when that child's destroy() runs. That is right by
default, but wrong for a host that may build a container speculatively
and then drop it without being told to — a React render that never
commits retains one such container forever.

The new `weakParentLink` option reaches the child through a WeakRef and
prunes the registration with a FinalizationRegistry once the child is
collected. Reachable children are still destroyed by the parent cascade,
so the default path is untouched. Needs both ES2021 primitives; where
either is missing it warns once and keeps the strong link.

- child() now takes container options, with `parent` always this container
- pin the build to target es2015, the floor the README advertises: with no
  target esbuild emitted esnext, shipping ES2022 class static blocks and
  ES2021 logical assignment
- state what that pin does not cover — module-scope globalThis (ES2020)
  and the JSR package, which ships src/ rather than the bundle
@bebrasmell
bebrasmell force-pushed the feat/weak-parent-link branch from 9ccd5d8 to eb4ccf6 Compare August 15, 2026 20:18

@bebrasmell bebrasmell left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, myself and I

@bebrasmell
bebrasmell merged commit 81833c3 into main Aug 15, 2026
2 checks passed
@bebrasmell
bebrasmell deleted the feat/weak-parent-link branch August 15, 2026 23:47
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.

1 participant