fix(state): keep token registries across a root reconnect (#273) - #277
Merged
Merged
Conversation
Disconnecting the root <wcs-state> threw away the command-token and event-token registries. $on subscribes only when the state is set and a command.<method>: binding subscribes only when its value is applied, so after re-attaching the element every event and every $command emit reached a fresh token with no subscribers, silently. Keep both registries on disconnect, as $streams and $watch already keep theirs. Nothing fires while disconnected: an element event finds no state tree, and $command cannot create the state. clearCommandTokenRegistry lost its only caller and is removed. Closes #273 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <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.
Closes #273.
What was wrong
Re-attaching the root
<wcs-state>—host.remove(); document.body.appendChild(host), or any move of it in the DOM — silently stopped$onhandlers,onscans and command-token subscriptions. There was no error and no warning.disconnectedCallbackthrew away the command-token and event-token registries.$on(and anonscan) subscribes only in the_statesetter, which a reconnect does not run.command.<method>:binding subscribes only when its value is applied, which a reconnect does not do either.Fix
$streamsand$watchalready use (stop firing, keep the registry).No state tree found on this root for eventToken handler), and$commandcannot be read because the state cannot be created (State rootNode is not available.). Both are pinned in tests.$onsubscriptions.clearCommandTokenRegistrylost its only caller and is removed.Tests
integration.tokenReconnect.test.tsgoes from real binding strings to dispatch and emit. It covers$onafter a reconnect, repeated reconnects (still one subscription), a re-set after a reconnect, events while disconnected,command.<method>:with$commandemit,onclick: $command.<name>, and emit while disconnected.DEFECT(#273)test inscan.on.test.tsis flipped.Docs
onscans are removed from the README,docs/scan(.ja).mdandCHANGELOG.md.docs/state-scan-design.mdD8 and §5-3 record the fix.Verification
npm run test:coveragenpm run lint,npx tsc --noEmite2e runs in CI.
🤖 Generated with Claude Code