fix: close #199 — remove Jaws.Replace and reject Replace/Remove broadcasts#211
Merged
Conversation
Jaws.Replace broadcast a what.Replace frame that swapped each matching DOM node for the supplied HTML but left the corresponding server-side Element registered. The replacement HTML normally carried no JaWS id attribute, so after replacement the Element stayed registered with no matching browser id and later commands targeting the same tag failed to locate their element. Element.Replace requires the replacement HTML to carry the element's own id= (validated), so it preserves DOM identity by construction. The broadcast form enforced no such contract and was a footgun, so remove it along with its two test callers. Element.Replace, the what.Replace wire command, and the client-side Replace handling are unaffected.
Removing the Jaws.Replace convenience helper did not close the underlying
identity desync: Jaws.Broadcast is public and handleBroadcast forwards
unrecognized commands verbatim to matching elements, so a caller could still
send wire.Message{What: what.Replace, ...} (or what.Remove) through raw
Broadcast and strand the server-side Element with no reachable DOM node.
Reject both what.Replace and what.Remove in Jaws.Broadcast, reporting
ErrReplaceNotBroadcastable / ErrRemoveNotBroadcastable via reportMisuse and
sending nothing.
- Replace swaps the whole node for HTML that must carry the element's own id,
and a single broadcast payload cannot preserve the distinct id of every
matched element. Element.Replace is the safe per-element form; it validates
that the replacement carries the id.
- Remove deletes a child node and requires the child's Element to be
unregistered server-side. The broadcast default path never calls
DeleteElement, and the client acks only the child's descendants, never the
child itself, so the child Element is stranded. Element.Remove is the safe
per-element form (it calls Request.DeleteElement) and Jaws.Delete is the
safe broadcast-level element removal (it stays in sync).
Element.Replace, Element.Remove, Jaws.Delete, the what.Replace and what.Remove
wire commands, and the client-side handling are unaffected. A table-driven
regression test exercises raw Jaws.Broadcast for both commands.
The [Element]s doc link rendered literally because the trailing s made it an invalid doc-link target. Rephrase as "matched [Element] values" so it links.
linkdata
added a commit
that referenced
this pull request
Jul 23, 2026
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.
What
Closes the #199 DOM/server identity desync at the source, in two commits:
Jaws.Replace(target, html)convenience helper and its two test callers.what.Replaceandwhat.RemoveinJaws.Broadcast— the public broadcast entry point — reporting the new sentinelsErrReplaceNotBroadcastable/ErrRemoveNotBroadcastableviareportMisuseand sending nothing.Why
Jaws.Broadcastis public andhandleBroadcastforwards unrecognized commands verbatim to every matching element. So removing theJaws.Replacehelper alone was not enough — a caller could still sendwire.Message{What: what.Replace, ...}(orwhat.Remove) through rawBroadcastand reproduce the same strand: the DOM node is mutated/removed while the server-sideElementstays registered with no reachable DOM node.Both commands mutate a specific element's node in a way a broadcast cannot keep in sync with the server-side registry:
id; one broadcast payload cannot preserve the distinctidof every matched element.Elementto be unregistered server-side. The broadcast default path never callsDeleteElement, and the client acks only the child's descendants, never the child itself (jawsRemovingusesquerySelectorAll, which excludes the node being removed) — so the childElementis stranded. This is precisely why the safe per-elementElement.RemovecallsRequest.DeleteElement(child)itself.Safe forms (unaffected)
Element.Replace— per-element, validates the replacement carries the element'sid.Element.Remove— per-element child removal, unregisters the child server-side.Jaws.Delete— broadcast-level element removal that stays in sync (itshandleBroadcastcase callsDeleteElement).what.Replace/what.Removewire commands and all client-side handling are untouched.Breaking change
Removes the exported
Jaws.Replacemethod (API break for any external caller; nothing in-repo used it outside tests).Jaws.Broadcastnow rejectswhat.Replace/what.Removemessages instead of forwarding them — these were never emitted by any in-repo helper.Verification
go build ./...,go vet ./...— cleango test -race ./...— all packages passgofumpt(touched files),staticcheck ./...,golangci-lint run ./...— clean / 0 issuesTestBroadcast_RejectsElementMutatingCommands— table-driven regression test exercising rawJaws.Broadcastfor bothReplaceandRemove, asserting the sentinel is reported and nothing reachesbcastCh(covers both the debug-panic and production-log branches).Noted, deliberately out of scope
what.SAttr/what.RAttrwithidis refused only client-side on the raw-broadcast path (the server-sideErrReservedAttributeguard lives in the attribute helpers). This does not strand — the id-bearing node survives — so it is not a Jaws.Replace leaves live server Elements without a DOM identity #199-class defect. Happy to follow up separately if you want the server-side guard extended to the broadcast path.