Repository navigation
perf(splittext): detect a lost split with a sentinel element instead of a MutationObserver - #387
Closed
ameerf-wix wants to merge 1 commit into
Closed
ameerf-wix wants to merge 1 commit into
ameerf-wix wants to merge 1 commit into
Conversation
…utationObserver The plugin appends a hidden `<splittext-sentinel>` custom element to each split container. The browser calls its `disconnectedCallback` when it leaves the document, whether the container or an ancestor was removed or the container's children were replaced, so nothing runs until then. It also leaves on the plugin's own `autoSplit` re-splits, which the plugin follows through `onSplit` with a new sentinel, and on moves. So the check waits a microtask, and only a split still out of the document refreshes, once for all of the plugin's containers. The cleanup stops the watchers before it reverts. Also covers a re-render that keeps the container and replaces its children, which the ancestor observer missed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #386, and targets its branch. A prototype for comparison, not ready to merge.
Why
#386 detects a replaced split container with a
MutationObserverthat watcheschildListon each ancestor from the container's parent up to the root. This PR tries a way that needs no observer at all, and also catches one more case.Change
<splittext-sentinel hidden aria-hidden="true">, to each split container.disconnectedCallbackwhenever it leaves the document. That happens when the container is removed, when any ancestor between it and the root is removed, or when the container's children are replaced. Nothing runs until one of those happens.autoSplitre-splits rebuild the container and remove the sentinel. The plugin wrapsonSplitto put a new sentinel back after every split. It keeps calling a caller's ownonSplit.refresh()once.customElements.get()is checked first, so every copy of the plugin on a page shares one definition. Each copy only setsonDisconnecton its own sentinels.refresh): the plugin splits without watching.Trade-offs
[data-splittext-wrapper], so selectors such as:last-childor:emptyon the container's children see it. The README says so.splittext-sentinel.Benchmark
Chromium, 400 split containers, each three levels below the root. Medians of 7 runs, in ms; the spread between three separate runs was about ±3 ms.
subtreeobserver (#386's first commit)The root
subtreeobserver is measurably slower on unrelated churn. The ancestor observer and the sentinel are both within noise of no detection. So performance alone doesn't decide between them; the coverage and the extra node do.Verification
tscpasses for splittext and the demo app, and eslint andprettier --checkpass repo-wide.autoSplitre-splits;onSplitstill runs for each split.MutationObserver.MutationObserver" fail.🤖 Generated with Claude Code