Skip to content

Commit

Permalink
fix(getSandpackStateFromProps): get activeFile from files from props …
Browse files Browse the repository at this point in the history
…+ template files (#665)
  • Loading branch information
danilowoz authored Dec 14, 2022
1 parent 00d7b57 commit 0480f1b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
10 changes: 10 additions & 0 deletions sandpack-react/src/Issues.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ export const FlushServerVsClient = (): JSX.Element => {
);
};

export const Issue663 = (): JSX.Element => (
<Sandpack
options={{
showTabs: true,
activeFile: "/index.tsx",
}}
template="react-ts"
/>
);

export const Issue482 = (): JSX.Element => {
const [hidden, setHidden] = useState(false);

Expand Down
12 changes: 11 additions & 1 deletion sandpack-react/src/utils/sandpackUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,20 @@ describe(getSandpackStateFromProps, () => {
expect(setup.activeFile).toEqual("/entry.js");
});

test("custom activeFile", () => {
const setup = getSandpackStateFromProps({
template: "react",
options: {
activeFile: "/index.js",
},
});

expect(setup.activeFile).toBe("/index.js");
});

/**
* hidden file
*/

test("exclude hidden files from custom files", () => {
const setup = getSandpackStateFromProps({
files: {
Expand Down
2 changes: 1 addition & 1 deletion sandpack-react/src/utils/sandpackUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const getSandpackStateFromProps = (
// visibleFiles and activeFile override the setup flags
let visibleFiles = normalizePath(props.options?.visibleFiles ?? []);
let activeFile = props.options?.activeFile
? resolveFile(props.options?.activeFile, normalizedFilesPath || {})
? resolveFile(props.options?.activeFile, projectSetup.files)
: undefined;

if (visibleFiles.length === 0 && normalizedFilesPath) {
Expand Down

0 comments on commit 0480f1b

Please sign in to comment.