You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
Due to a regression introduced in Chrome 127, clicking a button inside a void element that causes an input element to appear causes the selection to incorrectly revert to its previous location.
Click anywhere in block 1 to select it (indicated by grey background)
Click the button in block 2 (which is a void block element)
The selection incorrectly reverts to block 1
Expectation
Ordinarily, clicking a button inside a void element causes that void element to be selected. When clicking the button in block 2, block 2 should be selected, which is what happens in other browsers.
Environment
Slate Version: all versions
Operating System: tested in macOS, Windows and Android
The behaviour in Chrome 127 that causes this bug is that appending to the DOM an input element with a non-empty value causes a selectionchange event to be sent. However, the selection according to document.getSelection() remains the same as it was before the click. This confuses slate-react's selection change and click handling logic and causes the selection to revert incorrectly.
The text was updated successfully, but these errors were encountered:
Documenting this here in case anyone else needs to work around the bug before it's fixed in a stable release of Chrome.
Here's the specific sequence of events that causes the bug to occur:
The user clicks a button inside a void element that causes an input to appear
The click handler in editable.tsx calls Transforms.select to select the void element, setting editor.selection to the void element but leaving the DOM selection unchanged for now. (At this point, the DOM selection is still pointing to the previous editor.selection.)
Expected behaviour:
The useIsomorphicLayoutEffect in editable.tsx runs and the DOM selection is updated to match editor.selection
Actual behaviour in Chrome 127+:
Chrome fires the selectionchange event
The onDOMSelectionChange handler in editable.tsx updates editor.selection to match the DOM selection, inadvertently reverting editor.selection to its previous location
Since editor.selection now matches the DOM selection, nothing else happens and the selection remains at its location prior to the click
Thus, the simplest workaround is to add a click handler to the button that manually sets the DOM selection (not the Slate selection) to the correct void element.
Description
Due to a regression introduced in Chrome 127, clicking a button inside a void element that causes an input element to appear causes the selection to incorrectly revert to its previous location.
Recording
recording.mp4
Sandbox
https://codesandbox.io/p/sandbox/p553rr
Steps
To reproduce the behavior:
Expectation
Ordinarily, clicking a button inside a void element causes that void element to be selected. When clicking the button in block 2, block 2 should be selected, which is what happens in other browsers.
Environment
Context
I've reported this bug to the Chromium issue tracker: https://issues.chromium.org/issues/389368412
The behaviour in Chrome 127 that causes this bug is that appending to the DOM an input element with a non-empty value causes a
selectionchange
event to be sent. However, the selection according todocument.getSelection()
remains the same as it was before the click. This confuses slate-react's selection change and click handling logic and causes the selection to revert incorrectly.The text was updated successfully, but these errors were encountered: