Skip to content

fix(TextSelectionLayer): avoid reading destroyed ref box on document pointerdown - #2107

Merged
huntabyte merged 1 commit into
huntabyte:mainfrom
MathiasWP:fix/text-selection-layer-derived-inert
Aug 19, 2026
Merged

fix(TextSelectionLayer): avoid reading destroyed ref box on document pointerdown#2107
huntabyte merged 1 commit into
huntabyte:mainfrom
MathiasWP:fix/text-selection-layer-derived-inert

Conversation

@MathiasWP

Copy link
Copy Markdown
Contributor

TextSelectionLayerState.#pointerdown read this.opts.ref.current as its first statement, before the enabled check.

That box is a $derived owned by the Content component. When the document pointerdown listener outlives its component (reproducible by rapidly toggling a Dialog/Popover open/closed), every pointerdown anywhere in the document re-executes a destroyed derived and emits derived_inert — permanently, for any click target.

Fix: check the plain-boolean #enabledSnapshot first. Same logical condition; a leaked listener no longer touches the destroyed derived.

Notes

Related: #2080, #2105

…pointerdown

#pointerdown read this.opts.ref.current as its first statement, before the
enabled check. When the document listener outlives its component, that box is
a $derived owned by a destroyed effect, so every pointerdown anywhere in the
document re-executed it and emitted derived_inert, permanently.

Check the plain-boolean #enabledSnapshot first. Same logical condition, but a
leaked listener no longer touches the destroyed derived.
@changeset-bot

changeset-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9442b98

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

This PR includes changesets to release 1 package
Name Type
bits-ui 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

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor
built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
bits-ui ✅ Ready (View Log) Visit Preview 9442b98

@MathiasWP

Copy link
Copy Markdown
Contributor Author

CI red here is #2102's race, not this change — both failures are expectNotExists on outside-click dismissal (the click beats DismissibleLayer's deferred afterSleep(1) attach), and #2102 already patches both of these tests.

Local A/B on context-menu, 3 runs each: baseline 4/2/3 failures, with this change 3/3/4. Indistinguishable.

Should go green once #2102 lands; happy to rebase onto it instead if preferred.

@huntabyte huntabyte left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you!

@huntabyte
huntabyte merged commit aa0a18d into huntabyte:main Aug 19, 2026
6 of 7 checks passed
@github-actions github-actions Bot mentioned this pull request Aug 19, 2026
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 participants