Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[editable] Fix Memory Leak when switching between focused editables #5542

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/slate-react/src/components/editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import React, {
useCallback,
useEffect,
useLayoutEffect,
useMemo,
useReducer,
useRef,
Expand Down Expand Up @@ -176,6 +177,21 @@
[]
)

useLayoutEffect(() => {
return () => {
if (state == null) {
return
}
// Avoid leaking DOM nodes when this component is unmounted.
if (state.latestElement != null) {
state.latestElement.remove()
}
if (state.latestElement != null) {
state.latestElement = null
}
}
}, [])

Check warning on line 193 in packages/slate-react/src/components/editable.tsx

View workflow job for this annotation

GitHub Actions / lint:eslint

React Hook useLayoutEffect has a missing dependency: 'state'. Either include it or remove the dependency array

// The autoFocus TextareaHTMLAttribute doesn't do anything on a div, so it
// needs to be manually focused.
useEffect(() => {
Expand Down
Loading