Skip to content

Commit ad75077

Browse files
authored
Improve performance by not rendering children in explorer (codesandbox#3413)
* Improve performance by not rendering children in explorer * Fix file icon * Move open condition * Remove open type
1 parent 4d8fa45 commit ad75077

File tree

5 files changed

+47
-44
lines changed

5 files changed

+47
-44
lines changed

packages/app/src/app/pages/Sandbox/Editor/Navigation/Navigation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { TippyProps } from '@tippy.js/react';
1212
import ConfigurationIcon from '-!svg-react-loader!@codesandbox/common/lib/icons/cog.svg';
1313
// @ts-ignore
1414
// eslint-disable-next-line import/no-unresolved
15-
import FilesIcon from '-!svg-react-loader!@codesandbox/common/lib/icons/file.svg';
15+
import FilesIcon from '-!svg-react-loader!@codesandbox/common/lib/icons/file-activity-bar.svg';
1616
// @ts-ignore
1717
// eslint-disable-next-line import/no-unresolved
1818
import GitHubIcon from '-!svg-react-loader!@codesandbox/common/lib/icons/github.svg';

packages/app/src/app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/elements.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const Overlay = styled.div<{ isOver: boolean }>`
1414
display: ${props => (props.isOver ? 'block' : 'none')};
1515
`;
1616

17-
export const Opener = styled.div<{ open: boolean }>`
18-
height: ${props => (props.open ? '100%' : '0px')};
17+
export const Opener = styled.div`
18+
height: 100%;
1919
overflow: hidden;
2020
`;

packages/app/src/app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/index.tsx

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -325,47 +325,49 @@ const DirectoryEntry: React.FunctionComponent<Props> = ({
325325
/>
326326
</EntryContainer>
327327
)}
328-
<Opener open={open}>
329-
{creating === 'directory' && (
330-
<Entry
331-
id=""
332-
title=""
333-
state="editing"
334-
type="directory"
335-
depth={depth + 1}
328+
{open && (
329+
<Opener>
330+
{creating === 'directory' && (
331+
<Entry
332+
id=""
333+
title=""
334+
state="editing"
335+
type="directory"
336+
depth={depth + 1}
337+
renameValidator={validateModuleTitle}
338+
rename={createDirectory}
339+
onRenameCancel={resetState}
340+
/>
341+
)}
342+
<DirectoryChildren
343+
depth={depth}
344+
renameModule={renameModule}
345+
parentShortid={shortid}
336346
renameValidator={validateModuleTitle}
337-
rename={createDirectory}
338-
onRenameCancel={resetState}
347+
deleteEntry={confirmDeleteModule}
348+
setCurrentModule={setCurrentModule}
349+
markTabsNotDirty={markTabsNotDirty}
350+
discardModuleChanges={confirmDiscardChanges}
351+
getModulePath={getModulePath}
339352
/>
340-
)}
341-
<DirectoryChildren
342-
depth={depth}
343-
renameModule={renameModule}
344-
parentShortid={shortid}
345-
renameValidator={validateModuleTitle}
346-
deleteEntry={confirmDeleteModule}
347-
setCurrentModule={setCurrentModule}
348-
markTabsNotDirty={markTabsNotDirty}
349-
discardModuleChanges={confirmDiscardChanges}
350-
getModulePath={getModulePath}
351-
/>
352-
<DirectoryEntryModal
353-
isOpen={Boolean(modalConfirm)}
354-
onClose={closeModals}
355-
{...modalConfirm}
356-
/>
357-
{creating === 'module' && (
358-
<Entry
359-
id=""
360-
title=""
361-
state="editing"
362-
depth={depth + 1}
363-
renameValidator={validateModuleTitle}
364-
rename={createModule}
365-
onRenameCancel={resetState}
353+
<DirectoryEntryModal
354+
isOpen={Boolean(modalConfirm)}
355+
onClose={closeModals}
356+
{...modalConfirm}
366357
/>
367-
)}
368-
</Opener>
358+
{creating === 'module' && (
359+
<Entry
360+
id=""
361+
title=""
362+
state="editing"
363+
depth={depth + 1}
364+
renameValidator={validateModuleTitle}
365+
rename={createModule}
366+
onRenameCancel={resetState}
367+
/>
368+
)}
369+
</Opener>
370+
)}
369371
</div>
370372
);
371373
};
Lines changed: 3 additions & 0 deletions
Loading

packages/common/src/icons/file.svg

Lines changed: 1 addition & 3 deletions
Loading

0 commit comments

Comments
 (0)