Repository: codesandbox/codesandbox-client (language: javascript)

Issue:
Dashboard/ContextMenu: missing undefined check
<h1>💥 Crash Report</h1>

  <h2>What were you trying to accomplish when the crash occurred?</h2>

  > Please use this issue template to describe what you were doing when you encountered this crash. While we are able to fill in some details automatically, it's not always enough to reproduce!

  <h3>Link to sandbox: [link]() (optional)</h3>

  <h3>Crash Details</h3>

  <details>
  <summary>Environment</summary>

  | Browser |  Version  | Operating System | CodeSandbox Version |
  | ------- | --------- | ---------------- | ------------------- |
  | chrome | 90.0.4430 | Windows 10           | 72d987691          |

  **Route:**
  https://codesandbox.io/dashboard/drafts?workspace=3bb8275c-2eb4-4ab3-b12b-a07f96c338cb

  **Error Code:**
9b3efe48ce5141d0bc99533869dd091f

  </details>

  <details>
  <summary>Error Message</summary>

  ```bash
  TypeError: Cannot read property 'type' of undefined
  TypeError: Cannot read property 'type' of undefined
    at jm (https://codesandbox.io/static/js/app.f69cc7b3e.js?_sw-precache=f991986d7e9319036dc8e3e600bf8246:266:294793)
    at ua (https://codesandbox.io/static/js/common.06f11edc9.chunk.js?_sw-precache=07cdd3d049c0272c26234d6e31131d5e:1:1781090)
    at Ka (https://codesandbox.io/static/js/common.06f11edc9.chunk.js?_sw-precache=07cdd3d049c0272c26234d6e31131d5e:1:1789355)
    at xs (https://codesandbox.io/static/js/common.06f11edc9.chunk.js?_sw-precache=07cdd3d049c0272c26234d6e31131d5e:1:1827543)
    at ml (https://codesandbox.io/static/js/common.06f11edc9.chunk.js?_sw-precache=07cdd3d049c0272c26234d6e31131d5e:1:1811929)
    at hl (https://codesandbox.io/static/js/common.06f11edc9.chunk.js?_sw-precache=07cdd3d049c0272c26234d6e31131d5e:1:1811854)
    at il (https://codesandbox.io/static/js/common.06f11edc9.chunk.js?_sw-precache=07cdd3d049c0272c26234d6e31131d5e:1:1809182)
    at https://codesandbox.io/static/js/common.06f11edc9.chunk.js?_sw-precache=07cdd3d049c0272c26234d6e31131d5e:1:1767365
    at https://codesandbox.io/static/js/common.06f11edc9.chunk.js?_sw-precache=07cdd3d049c0272c26234d6e31131d5e:1:1842701
    at qo (https://codesandbox.io/static/js/common.06f11edc9.chunk.js?_sw-precache=07cdd3d049c0272c26234d6e31131d5e:1:1767074)
  
    in jm
    in Bm
    in ib
    in t
    in t
    in div
    in Content___StyledElement
    in Unknown
    in withRouter()
    in main
    in Dashboard___StyledElement2
    in div
    in Dashboard___StyledStack2
    in div
    in Dashboard___StyledStack
    in Unknown
    in De
    in Unknown
    in ly
    in t
    in t
    in div
    in elements__Content
    in n
    in withRouter(n)
    in div
    in elements__Container
    in Unknown
    in withRouter()
    in t
    in Unknown
    in De
    in c
    in t
  ```

  </details>
  


Discussion / hints:
Hey @Shlompi84 ,

Thanks for your report! We'll take a look at this and get back to you.
`selectedItems[0]` can be `undefined` in:

https://github.com/codesandbox/codesandbox-client/blob/72d9876913c4c6e6f03c38e0e0a7b7efe40fbce6/packages/app/src/app/pages/Dashboard/Components/Selection/ContextMenu.tsx#L104-L107

Fix patch:
diff --git a/packages/app/src/app/pages/Dashboard/Components/Selection/ContextMenu.tsx b/packages/app/src/app/pages/Dashboard/Components/Selection/ContextMenu.tsx
index 6aca23875bc..d4cd7ccbdd9 100644
--- a/packages/app/src/app/pages/Dashboard/Components/Selection/ContextMenu.tsx
+++ b/packages/app/src/app/pages/Dashboard/Components/Selection/ContextMenu.tsx
@@ -102,8 +102,9 @@ export const ContextMenu: React.FC<IContextMenuProps> = ({
   } else if (selectedItems.length > 1) {
     menu = <MultiMenu page={page} selectedItems={selectedItems} />;
   } else if (
-    (selectedItems[0] && selectedItems[0].type === 'sandbox') ||
-    selectedItems[0].type === 'template'
+    selectedItems[0] &&
+    (selectedItems[0].type === 'sandbox' ||
+      selectedItems[0].type === 'template')
   ) {
     menu = <SandboxMenu item={selectedItems[0]} setRenaming={setRenaming} />;
   } else if (selectedItems[0].type === 'folder') {


Test patch: