From 2e054545d8a485ceedb389bb11ea31598ceba7f3 Mon Sep 17 00:00:00 2001 From: Danilo Woznica Date: Wed, 5 Jun 2024 14:07:56 +0000 Subject: [PATCH 1/2] fix(open in CSB): pass children to buttons --- sandpack-react/src/PrivatePackage.stories.tsx | 22 +++++++++---------- .../UnstyledOpenInCodeSandboxButton.tsx | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sandpack-react/src/PrivatePackage.stories.tsx b/sandpack-react/src/PrivatePackage.stories.tsx index be40526ec..dc490c046 100644 --- a/sandpack-react/src/PrivatePackage.stories.tsx +++ b/sandpack-react/src/PrivatePackage.stories.tsx @@ -10,19 +10,19 @@ export const Basic: React.FC = () => { return (
Hello World - // }`, - // }} +export default function App() { + return +}`, + }} // options={{ bundlerURL: `http://localhost:3000` }} - options={{ bundlerURL: `https://2-1-0-sandpack.codesandbox.stream/` }} - teamId="6756547b-12fb-465e-82c8-b38a981f1f67" + // options={{ bundlerURL: `https://2-1-0-sandpack.codesandbox.stream/` }} + teamId="642af90c-4717-4730-bad3-e4c1e37ca5e2" template="react" />
diff --git a/sandpack-react/src/components/common/OpenInCodeSandboxButton/UnstyledOpenInCodeSandboxButton.tsx b/sandpack-react/src/components/common/OpenInCodeSandboxButton/UnstyledOpenInCodeSandboxButton.tsx index 2c25d037a..79e62d8e7 100644 --- a/sandpack-react/src/components/common/OpenInCodeSandboxButton/UnstyledOpenInCodeSandboxButton.tsx +++ b/sandpack-react/src/components/common/OpenInCodeSandboxButton/UnstyledOpenInCodeSandboxButton.tsx @@ -45,7 +45,7 @@ const getFileParameters = ( export const UnstyledOpenInCodeSandboxButton: React.FC< React.HtmlHTMLAttributes -> = ({ children, ...props }) => { +> = (props) => { const { sandpack } = useSandpack(); if (sandpack.exportOptions) { From e53f4540f1f064d62e8656b47011ef2be090d8fd Mon Sep 17 00:00:00 2001 From: Danilo Woznica Date: Wed, 5 Jun 2024 14:19:09 +0000 Subject: [PATCH 2/2] format --- .../src/contexts/utils/useFiles.test.ts | 32 ++++++++++--------- sandpack-react/src/contexts/utils/useFiles.ts | 2 +- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/sandpack-react/src/contexts/utils/useFiles.test.ts b/sandpack-react/src/contexts/utils/useFiles.test.ts index d738f554c..95a16be4d 100644 --- a/sandpack-react/src/contexts/utils/useFiles.test.ts +++ b/sandpack-react/src/contexts/utils/useFiles.test.ts @@ -7,7 +7,7 @@ import { VANILLA_TEMPLATE } from "../../templates"; import { getSandpackStateFromProps } from "../../utils/sandpackUtils"; import { useFiles } from "./useFiles"; -import {SandpackBundlerFile} from "@codesandbox/sandpack-client/src"; +import { SandpackBundlerFile } from "@codesandbox/sandpack-client/src"; describe(useFiles, () => { it("should returns an initial state, which is the default template", () => { @@ -127,24 +127,26 @@ describe(useFiles, () => { expect(result.current[0].files["/index.js"]).toEqual({ code: `Baz` }); }); it("doesn't override the activeFile's metadata", () => { - const {result} = renderHook(() => useFiles({ - template: "react", - files: { - "/App.js": { - code: "export default function App() { return

Hello world

}", - readOnly: true, - someOtherMetadata: "foo" - } as SandpackBundlerFile - } - })); + const { result } = renderHook(() => + useFiles({ + template: "react", + files: { + "/App.js": { + code: "export default function App() { return

Hello world

}", + readOnly: true, + someOtherMetadata: "foo", + } as SandpackBundlerFile, + }, + }) + ); act(() => { result.current[1].updateFile("/App.js", "console.log(10)"); }); expect(result.current[0].files["/App.js"]).toEqual({ - code: "console.log(10)", - readOnly: true, - someOtherMetadata: "foo" + code: "console.log(10)", + readOnly: true, + someOtherMetadata: "foo", }); - }) + }); }); diff --git a/sandpack-react/src/contexts/utils/useFiles.ts b/sandpack-react/src/contexts/utils/useFiles.ts index faf168295..97752c3a0 100644 --- a/sandpack-react/src/contexts/utils/useFiles.ts +++ b/sandpack-react/src/contexts/utils/useFiles.ts @@ -78,7 +78,7 @@ export const useFiles: UseFiles = (props) => { ...files, [pathOrFiles]: { ...files[pathOrFiles], - code + code, }, }; } else if (typeof pathOrFiles === "object") {