Skip to content

Commit 87498ca

Browse files
mathioclaude
andcommitted
fix: guard against undefined attach in setFragmentData
When domRange.cloneContents() returns an empty DocumentFragment (e.g. because React re-rendered the DOM between selection and copy event), attach is undefined and setAttribute crashes. Add an early return guard. Fixes REACT-AND-STIMULUS-1CRK (695 events, 471 users). Co-Authored-By: Claude Opus 4.6 via Claude Code <noreply@anthropic.com>
1 parent 878fbcd commit 87498ca

6 files changed

Lines changed: 24 additions & 5 deletions

File tree

dist/components/editable.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.es.js

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.es.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/editable.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,13 @@ const setFragmentData = (
10501050
}
10511051
})
10521052

1053+
// COMPAT: If the cloned contents are empty (e.g. because the DOM was
1054+
// re-rendered between the selection being set and the copy event firing),
1055+
// bail out to avoid a crash on setAttribute below.
1056+
if (!attach) {
1057+
return
1058+
}
1059+
10531060
// COMPAT: If the end node is a void node, we need to move the end of the
10541061
// range from the void node's spacer span, to the end of the void node's
10551062
// content, since the spacer is before void's content in the DOM.

0 commit comments

Comments
 (0)