opencaesar / oml-vision

A VS Code extension providing UI viewpoints for OML models
Other
4 stars 2 forks source link

Webview crashes if no context menu is provided #53

Closed pogi7 closed 4 months ago

pogi7 commented 5 months ago

Checklist before submitting a bug report

Context

If there is no context menu defined in a layout file and when I try to open a context menu within the webview corresponding to the layout file, then a black page will render and the webview will crash. I want to prevent this behavior from happening.

Steps to reproduce the bug

  1. Go into the any OML model like https://github.com/pogi7/kepler16b-example
  2. Pick any of the src/vision/viewpoints files.
  3. If there is a key-value pair for a contextMenu then remove it. An example of what that would look like is below:
    "contextMenu": {
      "commands": "objectives.json"
    }
  4. Save the file
  5. Open the webview that corresponds to the viewpoint without the contextMenu
  6. Verify that after right clicking the webview crashes

Current result

A black screen is rendered and the webview crashes.

Expected result

A black screen is not rendered and the webview does not crash.

Additional context

Developer Console Log:

Uncaught TypeError: Cannot read properties of undefined (reading 'commands')
    at availableCommands (index.js:154825:64)
    at ContextMenu (index.js:154830:223)
    at renderWithHooks (index.js:14091:27)
    at mountIndeterminateComponent (index.js:16841:21)
    at beginWork (index.js:17822:22)
    at HTMLUnknownElement.callCallback2 (index.js:5594:22)
    at Object.invokeGuardedCallbackDev (index.js:5619:24)
    at invokeGuardedCallback (index.js:5653:39)
    at beginWork$1 (index.js:21681:15)
    at performUnitOfWork (index.js:21117:21)
index.js:154825 Uncaught TypeError: Cannot read properties of undefined (reading 'commands')
    at availableCommands (index.js:154825:64)
    at ContextMenu (index.js:154830:223)
    at renderWithHooks (index.js:14091:27)
    at mountIndeterminateComponent (index.js:16841:21)
    at beginWork (index.js:17822:22)
    at HTMLUnknownElement.callCallback2 (index.js:5594:22)
    at Object.invokeGuardedCallbackDev (index.js:5619:24)
    at invokeGuardedCallback (index.js:5653:39)
    at beginWork$1 (index.js:21681:15)
    at performUnitOfWork (index.js:21117:21)
index.js:15956 The above error occurred in the <ContextMenu> component:

    at ContextMenu (https://file+.vscode-resource.vscode-cdn.net/Users/levitt/git/opencaesar/oml-vision/build/static/index.js:154752:3)
    at div
    at Tree (https://file+.vscode-resource.vscode-cdn.net/Users/levitt/git/opencaesar/oml-vision/build/static/index.js:163352:3)
    at div
    at TreeView (https://file+.vscode-resource.vscode-cdn.net/Users/levitt/git/opencaesar/oml-vision/build/static/index.js:163760:24)
    at QueryClientProvider (https://file+.vscode-resource.vscode-cdn.net/Users/levitt/git/opencaesar/oml-vision/build/static/index.js:123405:3)
    at WizardsProvider (https://file+.vscode-resource.vscode-cdn.net/Users/levitt/git/opencaesar/oml-vision/build/static/index.js:123692:36)
    at CommandProvider (https://file+.vscode-resource.vscode-cdn.net/Users/levitt/git/opencaesar/oml-vision/build/static/index.js:123652:13)
    at RenderedRoute (https://file+.vscode-resource.vscode-cdn.net/Users/levitt/git/opencaesar/oml-vision/build/static/index.js:120242:5)
    at Routes (https://file+.vscode-resource.vscode-cdn.net/Users/levitt/git/opencaesar/oml-vision/build/static/index.js:120525:15)
    at Router (https://file+.vscode-resource.vscode-cdn.net/Users/levitt/git/opencaesar/oml-vision/build/static/index.js:120472:15)
    at MemoryRouter (https://file+.vscode-resource.vscode-cdn.net/Users/levitt/git/opencaesar/oml-vision/build/static/index.js:120434:5)
    at App (https://file+.vscode-resource.vscode-cdn.net/Users/levitt/git/opencaesar/oml-vision/build/static/index.js:180016:23)
    at LayoutProvider (https://file+.vscode-resource.vscode-cdn.net/Users/levitt/git/opencaesar/oml-vision/build/static/index.js:123619:35)

Consider adding an error boundary to your tree to customize error handling behavior.
Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.
index.js:154825 Uncaught TypeError: Cannot read properties of undefined (reading 'commands')
    at availableCommands (index.js:154825:64)
    at ContextMenu (index.js:154830:223)
    at renderWithHooks (index.js:14091:27)
    at mountIndeterminateComponent (index.js:16841:21)
    at beginWork (index.js:17822:22)
    at beginWork$1 (index.js:21669:22)
    at performUnitOfWork (index.js:21117:21)
    at workLoopSync (index.js:21053:13)
    at renderRootSync (index.js:21032:15)
    at recoverFromConcurrentError (index.js:20652:28)

Possible fix

The bug is in view/src/components/Diagram/Diagram.tsx, view/src/components/Table/Table.tsx, and view/src/components/Tree/Tree.tsx components where the component is being rendered

Need to add a conditional to not render the component if the layout.contextMenu variable is undefined

Technical data