Skip to content

Commit a00ac0d

Browse files
committed
fix(sandpack): resolve UI desync after reset by removing call to reset()
Remove call to refresh() in the handleReset function and dependencies related to refresh() from NavigationBar.tsx file to fix a UI desynchronization issue in the Sandpack embedded editor. Currently, clicking the reset button resets the code but does not update the UI until the editor is interacted with.
1 parent 6ae99dd commit a00ac0d

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

src/components/MDX/Sandpack/NavigationBar.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ import {
1111
Fragment,
1212
} from 'react';
1313
import cn from 'classnames';
14-
import {
15-
FileTabs,
16-
useSandpack,
17-
useSandpackNavigation,
18-
} from '@codesandbox/sandpack-react/unstyled';
14+
import {FileTabs, useSandpack} from '@codesandbox/sandpack-react/unstyled';
1915
import {OpenInCodeSandboxButton} from './OpenInCodeSandboxButton';
2016
import {ResetButton} from './ResetButton';
2117
import {DownloadButton} from './DownloadButton';
@@ -47,9 +43,7 @@ export function NavigationBar({providedFiles}: {providedFiles: Array<string>}) {
4743
// By default, show the dropdown because all tabs may not fit.
4844
// We don't know whether they'll fit or not until after hydration:
4945
const [showDropdown, setShowDropdown] = useState(true);
50-
const {activeFile, setActiveFile, visibleFiles, clients} = sandpack;
51-
const clientId = Object.keys(clients)[0];
52-
const {refresh} = useSandpackNavigation(clientId);
46+
const {activeFile, setActiveFile, visibleFiles} = sandpack;
5347
const isMultiFile = visibleFiles.length > 1;
5448
const hasJustToggledDropdown = useRef(false);
5549

@@ -109,8 +103,6 @@ export function NavigationBar({providedFiles}: {providedFiles: Array<string>}) {
109103
) {
110104
sandpack.resetAllFiles();
111105
}
112-
113-
refresh();
114106
};
115107

116108
return (

0 commit comments

Comments
 (0)