Skip to content

Commit 8a2d303

Browse files
authored
fix: guard restore action with isTimeTravelling atom (#174)
1 parent efd498b commit 8a2d303

File tree

1 file changed

+8
-3
lines changed
  • src/DevTools/Extension/components/Shell/components/TimeTravel/components/SnapshotDetail/components/DisplaySnapshotDetails/components

1 file changed

+8
-3
lines changed

src/DevTools/Extension/components/Shell/components/TimeTravel/components/SnapshotDetail/components/DisplaySnapshotDetails/components/SnapshotActions.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import React, { useEffect, useState } from 'react';
22
import { Box, Button, ButtonProps, Title } from '@mantine/core';
33
import { useTimeout } from '@mantine/hooks';
44
import { IconCircleCheck, IconRotate2 } from '@tabler/icons-react';
5+
import { flushSync } from 'react-dom';
56
import { AtomsSnapshot } from '../../../../../../../../../../../types';
67
import { useGotoAtomsSnapshot } from '../../../../../../../../../../../utils';
78
import { useUserStoreOptions } from '../../../../../../../../../../hooks/useUserStore';
8-
import { useIsTimeTravelingValue } from '../../../../../atoms';
9+
import { useIsTimeTraveling } from '../../../../../atoms';
910

1011
const commonStyles: ButtonProps['styles'] = {
1112
section: {
@@ -30,7 +31,7 @@ type SnapshotActionsProps = {
3031
export const SnapshotActions = (props: SnapshotActionsProps) => {
3132
const [justRestored, setJustRestored] = useState(false);
3233
const gotoSnapshot = useGotoAtomsSnapshot(useUserStoreOptions());
33-
const isTimeTraveling = useIsTimeTravelingValue();
34+
const [isTimeTraveling, setIsTimeTraveling] = useIsTimeTraveling();
3435
const { start, clear } = useTimeout(() => setJustRestored(false), 1750);
3536

3637
useEffect(() => {
@@ -40,7 +41,11 @@ export const SnapshotActions = (props: SnapshotActionsProps) => {
4041
const handleOnRestoreClick = () => {
4142
setJustRestored(true);
4243
start();
43-
gotoSnapshot(props.snapshotToGoTo);
44+
flushSync(() => {
45+
setIsTimeTraveling(true);
46+
gotoSnapshot(props.snapshotToGoTo);
47+
setIsTimeTraveling(false);
48+
});
4449
};
4550

4651
return (

0 commit comments

Comments
 (0)