Skip to content

Commit

Permalink
fix: Slate error on closing text component (#1510)
Browse files Browse the repository at this point in the history
  • Loading branch information
kswenson authored Sep 25, 2024
1 parent 95db58d commit 0ccaefc
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions v3/src/components/text/text-tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,21 @@ export const TextTile = observer(function TextTile({ tile }: ITileBaseProps) {
}, [initialValue])

useEffect(() => {
return tile && mstReaction(
let animationFrame: number
const disposer = tile && mstReaction(
() => isTileSelected() && tile?.transitionComplete,
isSelected => {
// RAF to delay focus request until after model processing completes
isSelected && requestAnimationFrame(() => ReactEditor.focus(editor))
if (isSelected) {
animationFrame = requestAnimationFrame(() => ReactEditor.focus(editor))
}
},
{ name: "FocusEditorOnTileSelect" }, tile
)
return () => {
if (animationFrame) cancelAnimationFrame(animationFrame)
disposer?.()
}
}, [editor, isTileSelected, tile])

const textTileRef = useRef<HTMLDivElement | null>(null)
Expand Down

0 comments on commit 0ccaefc

Please sign in to comment.