fix: timers type in browser env (#3875)

This commit is contained in:
Camol
2023-08-22 03:14:25 +08:00
committed by GitHub
parent eda5ff4d3f
commit fc9981335b
11 changed files with 19 additions and 19 deletions

View File

@@ -70,7 +70,7 @@ const NameWorkspaceContent = ({
<Input <Input
ref={ref => { ref={ref => {
if (ref) { if (ref) {
setTimeout(() => ref.focus(), 0); window.setTimeout(() => ref.focus(), 0);
} }
}} }}
data-testid="create-workspace-input" data-testid="create-workspace-input"

View File

@@ -82,7 +82,7 @@ export const WorkspaceDeleteModal = ({
<Input <Input
ref={ref => { ref={ref => {
if (ref) { if (ref) {
setTimeout(() => ref.focus(), 0); window.setTimeout(() => ref.focus(), 0);
} }
}} }}
onChange={setDeleteStr} onChange={setDeleteStr}

View File

@@ -106,7 +106,7 @@ const EditorWrapper = memo(function EditorWrapper({
const rootStore = getCurrentStore(); const rootStore = getCurrentStore();
const editorItems = rootStore.get(pluginEditorAtom); const editorItems = rootStore.get(pluginEditorAtom);
let disposes: (() => void)[] = []; let disposes: (() => void)[] = [];
const renderTimeout = setTimeout(() => { const renderTimeout = window.setTimeout(() => {
disposes = Object.entries(editorItems).map(([id, editorItem]) => { disposes = Object.entries(editorItems).map(([id, editorItem]) => {
const div = document.createElement('div'); const div = document.createElement('div');
div.setAttribute('plugin-id', id); div.setAttribute('plugin-id', id);
@@ -123,7 +123,7 @@ const EditorWrapper = memo(function EditorWrapper({
return () => { return () => {
dispose(); dispose();
clearTimeout(renderTimeout); clearTimeout(renderTimeout);
setTimeout(() => { window.setTimeout(() => {
disposes.forEach(dispose => dispose()); disposes.forEach(dispose => dispose());
}); });
}; };
@@ -165,7 +165,7 @@ const PluginContentAdapter = memo<PluginContentAdapterProps>(
}; };
const dispose = addCleanup(pluginName, cl); const dispose = addCleanup(pluginName, cl);
abortController.signal.addEventListener('abort', () => { abortController.signal.addEventListener('abort', () => {
setTimeout(() => { window.setTimeout(() => {
dispose(); dispose();
cl(); cl();
}); });

View File

@@ -25,11 +25,11 @@ const App = () => {
<button <button
data-testid="start-button" data-testid="start-button"
onClick={useCallback(() => { onClick={useCallback(() => {
disposeRef.current = setInterval(() => { disposeRef.current = window.setInterval(() => {
const counter = counterRef.current; const counter = counterRef.current;
map.set('counter', counter + 1); map.set('counter', counter + 1);
counterRef.current = counter + 1; counterRef.current = counter + 1;
}, 0) as any; }, 0);
}, [])} }, [])}
> >
start writing start writing

View File

@@ -91,7 +91,7 @@ Basic.play = async ({ canvasElement }) => {
expect(button).not.toBeNull(); expect(button).not.toBeNull();
button.click(); button.click();
} }
await new Promise(resolve => setTimeout(resolve, 100)); await new Promise(resolve => window.setTimeout(resolve, 100));
{ {
const button = canvasElement.querySelector( const button = canvasElement.querySelector(
'[data-testid="share-menu-enable-affine-cloud-button"]' '[data-testid="share-menu-enable-affine-cloud-button"]'

View File

@@ -35,7 +35,7 @@ export type AppSidebarProps = PropsWithChildren<
function useEnableAnimation() { function useEnableAnimation() {
const [enable, setEnable] = useState(false); const [enable, setEnable] = useState(false);
useEffect(() => { useEffect(() => {
setTimeout(() => { window.setTimeout(() => {
setEnable(true); setEnable(true);
}, 500); }, 500);
}, []); }, []);

View File

@@ -80,7 +80,7 @@ function NotificationCard(props: NotificationCardProps): ReactElement {
const [animationKey, setAnimationKey] = useState(0); const [animationKey, setAnimationKey] = useState(0);
const animationRef = useRef<SVGAnimateElement>(null); const animationRef = useRef<SVGAnimateElement>(null);
const notificationRef = useRef<HTMLLIElement>(null); const notificationRef = useRef<HTMLLIElement>(null);
const timerIdRef = useRef<NodeJS.Timeout>(); const timerIdRef = useRef<number>();
const isFront = index === 0; const isFront = index === 0;
const isVisible = index + 1 <= 3; const isVisible = index + 1 <= 3;
const progressDuration = notification.timeout || 3000; const progressDuration = notification.timeout || 3000;
@@ -164,7 +164,7 @@ function NotificationCard(props: NotificationCardProps): ReactElement {
setHeights(h => setHeights(h =>
h.filter(height => height.notificationKey !== notification.key) h.filter(height => height.notificationKey !== notification.key)
); );
setTimeout(() => { window.setTimeout(() => {
if (!notification.key) { if (!notification.key) {
return; return;
} }
@@ -177,7 +177,7 @@ function NotificationCard(props: NotificationCardProps): ReactElement {
clearTimeout(timerIdRef.current); clearTimeout(timerIdRef.current);
} }
if (!expand) { if (!expand) {
timerIdRef.current = setTimeout(() => { timerIdRef.current = window.setTimeout(() => {
onClickRemove(); onClickRemove();
}, duration); }, duration);
} }

View File

@@ -29,7 +29,7 @@ export const DefaultAvatar = ({ name: propsName }: { name: string }) => {
return colorsSchema[index % colorsSchema.length]; return colorsSchema[index % colorsSchema.length];
}, [name]); }, [name]);
const timer = useRef<ReturnType<typeof setTimeout>>(); const timer = useRef<number>();
const [topColor, middleColor, bottomColor] = colors; const [topColor, middleColor, bottomColor] = colors;
const [isHover, setIsHover] = useState(false); const [isHover, setIsHover] = useState(false);
@@ -38,7 +38,7 @@ export const DefaultAvatar = ({ name: propsName }: { name: string }) => {
<div <div
className={DefaultAvatarContainerStyle} className={DefaultAvatarContainerStyle}
onMouseEnter={() => { onMouseEnter={() => {
timer.current = setTimeout(() => { timer.current = window.setTimeout(() => {
setIsHover(true); setIsHover(true);
}, 300); }, 300);
}} }}

View File

@@ -69,7 +69,7 @@ export const Popper = ({
} }
window.clearTimeout(pointerLeaveTimer.current); window.clearTimeout(pointerLeaveTimer.current);
pointerEnterTimer.current = window.setTimeout(() => { pointerEnterTimer.current = window.window.setTimeout(() => {
setVisible(true); setVisible(true);
}, pointerEnterDelay); }, pointerEnterDelay);
}; };
@@ -81,7 +81,7 @@ export const Popper = ({
return; return;
} }
window.clearTimeout(pointerEnterTimer.current); window.clearTimeout(pointerEnterTimer.current);
pointerLeaveTimer.current = window.setTimeout(() => { pointerLeaveTimer.current = window.window.setTimeout(() => {
setVisible(false); setVisible(false);
}, pointerLeaveDelay); }, pointerLeaveDelay);
}; };

View File

@@ -183,7 +183,7 @@ const BookMarkUI = ({ page }: BookMarkProps) => {
if (!shouldShowBookmarkMenu(pastedBlocks)) { if (!shouldShowBookmarkMenu(pastedBlocks)) {
return; return;
} }
setTimeout(() => { window.setTimeout(() => {
setAnchor(getCurrentNativeRange()); setAnchor(getCurrentNativeRange());
}, 100); }, 100);
}); });

View File

@@ -72,10 +72,10 @@ const ImagePreviewModalImpl = (
const [hasPlayedAnimation, setHasPlayedAnimation] = useState<boolean>(false); const [hasPlayedAnimation, setHasPlayedAnimation] = useState<boolean>(false);
useEffect(() => { useEffect(() => {
let timeoutId: NodeJS.Timeout; let timeoutId: number;
if (!isOpen) { if (!isOpen) {
timeoutId = setTimeout(() => { timeoutId = window.setTimeout(() => {
props.onClose(); props.onClose();
setIsOpen(true); setIsOpen(true);
}, 300); }, 300);