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

fix: timeoutId type #2735

Merged
merged 5 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 5 additions & 5 deletions packages/lexical-playground/src/hooks/useReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ const getElement = (): HTMLElement => {
return element;
};

export default function useReport(): (arg0: string) => NodeJS.Timeout {
const timer = useRef<NodeJS.Timeout | null>(null);
export default function useReport(): (arg0: string) => number {
const timer = useRef<number | null>(null);
const cleanup = useCallback(() => {
if (timer !== null) {
clearTimeout(timer.current as NodeJS.Timeout);
clearTimeout(timer.current as number);
}

if (document.body) {
Expand All @@ -52,9 +52,9 @@ export default function useReport(): (arg0: string) => NodeJS.Timeout {
// eslint-disable-next-line no-console
console.log(content);
const element = getElement();
clearTimeout(timer.current as NodeJS.Timeout);
clearTimeout(timer.current as number);
element.innerHTML = content;
timer.current = setTimeout(cleanup, 1000);
timer.current = window.setTimeout(cleanup, 1000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not use the window. prefix (here and other occurrences, especially NPM packages), it will fail on some frameworks like Remix when loaded on the server-side, especially now that we support headless mode

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

return timer.current;
},
[cleanup],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function TypingPerfPlugin(): JSX.Element | null {
const report = useReport();
useEffect(() => {
let start = 0;
let timerId: NodeJS.Timeout | null;
let timerId: number | null;
let keyPressTimerId: number | null;
let log: Array<DOMHighResTimeStamp> = [];
let invalidatingEvent = false;
Expand Down Expand Up @@ -61,7 +61,7 @@ export default function TypingPerfPlugin(): JSX.Element | null {
// inconsistencies between the sequencing of rAF in different browsers.
keyPressTimerId = window.setTimeout(measureEventEnd, 0);
// Schedule a timer to report the results.
timerId = setTimeout(() => {
timerId = window.setTimeout(() => {
const total = log.reduce((a, b) => a + b, 0);
const reportedText =
'Typing Perf: ' + Math.round((total / log.length) * 100) / 100 + 'ms';
Expand Down
4 changes: 2 additions & 2 deletions packages/lexical-react/src/LexicalTreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function TreeView({

useEffect(() => {
if (isPlaying) {
let timeoutId: NodeJS.Timeout;
let timeoutId: number;

const play = () => {
const currentIndex = playingIndexRef.current;
Expand All @@ -105,7 +105,7 @@ export function TreeView({
const currentTime = timeStampedEditorStates[currentIndex][0];
const nextTime = timeStampedEditorStates[currentIndex + 1][0];
const timeDiff = nextTime - currentTime;
timeoutId = setTimeout(() => {
timeoutId = window.setTimeout(() => {
playingIndexRef.current++;
const index = playingIndexRef.current;
const input = inputRef.current;
Expand Down