|
@@ -36,25 +36,26 @@ function AutoExpandingTextArea({
|
|
|
...rest
|
|
...rest
|
|
|
}: AutoExpandingTextAreaProps) {
|
|
}: AutoExpandingTextAreaProps) {
|
|
|
const ref = useRef<HTMLTextAreaElement>(null)
|
|
const ref = useRef<HTMLTextAreaElement>(null)
|
|
|
|
|
+ const isFirstResizeRef = useRef(true)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
if (!ref.current || !onResize || !('ResizeObserver' in window)) {
|
|
if (!ref.current || !onResize || !('ResizeObserver' in window)) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- let isFirstResize = true
|
|
|
|
|
-
|
|
|
|
|
const resizeObserver = new ResizeObserver(() => {
|
|
const resizeObserver = new ResizeObserver(() => {
|
|
|
// Ignore the resize that is triggered when the element is first
|
|
// Ignore the resize that is triggered when the element is first
|
|
|
// inserted into the DOM
|
|
// inserted into the DOM
|
|
|
- if (isFirstResize) {
|
|
|
|
|
- isFirstResize = false
|
|
|
|
|
|
|
+ if (isFirstResizeRef.current) {
|
|
|
|
|
+ isFirstResizeRef.current = false
|
|
|
} else {
|
|
} else {
|
|
|
// Prevent errors like "ResizeObserver loop completed with undelivered
|
|
// Prevent errors like "ResizeObserver loop completed with undelivered
|
|
|
// notifications" that occur if onResize does something complicated.
|
|
// notifications" that occur if onResize does something complicated.
|
|
|
// The cost of this is that onResize lags one frame behind, but it's
|
|
// The cost of this is that onResize lags one frame behind, but it's
|
|
|
// unlikely to matter.
|
|
// unlikely to matter.
|
|
|
- window.requestAnimationFrame(onResize)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // Wrap onResize to prevent extra parameters being passed
|
|
|
|
|
+ window.requestAnimationFrame(() => onResize())
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
|