Skip to content

Commit

Permalink
Update 3 files
Browse files Browse the repository at this point in the history
  • Loading branch information
danilowoz committed May 22, 2023
1 parent db1a4fe commit f6c775f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
33 changes: 33 additions & 0 deletions sandpack-react/src/Issues.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import React, { useState } from "react";

import { REACT_TEMPLATE } from "./templates";

import {
Sandpack,
SandpackCodeEditor,
Expand All @@ -13,6 +15,37 @@ export default {
title: "Bug reports/Issues",
};

export const Issue944 = (): JSX.Element => {
const [files, setFiles] = useState(REACT_TEMPLATE["files"]);

return (
<>
<button
onClick={() => {
setFiles(REACT_TEMPLATE["files"]);
}}
>
1
</button>
<button
onClick={() => {
setFiles({
...REACT_TEMPLATE["files"],
"/App.js": `import Foo from "./Foo";
export default function App() {
return <Foo />
}`,
"Foo.js": `export default () => <button> Foo</button>`,
});
}}
>
2
</button>
<Sandpack files={files} template="react" />
</>
);
};

export const FlushServerVsClient = (): JSX.Element => {
return (
<SandpackProvider>
Expand Down
6 changes: 6 additions & 0 deletions sandpack-react/src/contexts/utils/useClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,8 @@ export const useClient: UseClient = (
return;
}

console.log(recompileMode, filesState);

/**
* When the environment changes, Sandpack needs to make sure
* to create a new client and the proper bundler
Expand Down Expand Up @@ -507,6 +509,10 @@ export const useClient: UseClient = (
});
}, recompileDelay);
}

return () => {
window.clearTimeout(debounceHook.current);
};
},
[
filesState.files,
Expand Down
1 change: 1 addition & 0 deletions sandpack-react/src/contexts/utils/useFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const useFiles: UseFiles = (props) => {
const isMountedRef = useRef(false);
useEffect(() => {
if (isMountedRef.current) {
console.log("changed");
setState(getSandpackStateFromProps(props));
} else {
isMountedRef.current = true;
Expand Down

0 comments on commit f6c775f

Please sign in to comment.