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

Exploring #944 #945

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
34 changes: 34 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 @@ -12,6 +14,38 @@ import {
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
2 changes: 2 additions & 0 deletions sandpack-react/src/contexts/utils/useClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,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
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