Skip to content

Commit 34045fe

Browse files
authored
fix: cursor jumps to start of line unexpectedly (#745)
* fix: cursor jumps to start of line unexpectedly * wip
1 parent 53ce7ec commit 34045fe

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/playground/App.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import React, {
77
useCallback,
88
useRef,
99
} from "react";
10+
import { flushSync } from "react-dom";
1011
import Alert from "./components/Alert";
1112
import CrashAlert from "./components/CrashAlert";
1213
import Footer from "./components/Footer";
@@ -303,13 +304,18 @@ const App = () => {
303304
return () => mq.removeEventListener("change", ConfigToggler);
304305
}, []);
305306

307+
// Please do not remove `flushSync`: https://github.com/eslint/eslint.org/pull/745
306308
const debouncedOnUpdate = useMemo(
307309
() =>
308-
debounce(value => {
309-
setFix(false);
310-
setText(value);
311-
storeState({ newText: value });
312-
}, 400),
310+
debounce(
311+
value =>
312+
flushSync(() => {
313+
setFix(false);
314+
setText(value);
315+
storeState({ newText: value });
316+
}),
317+
400,
318+
),
313319
[storeState],
314320
);
315321

0 commit comments

Comments
 (0)