Skip to content

Uncaught SyntaxError: "undefined" is not valid JSON #164

@leastofthese23

Description

@leastofthese23

Describe the bug
When right-clicking an element that should display the custom context menu, it instead throws an error in the browser console 'Uncaught SyntaxError

Uncaught SyntaxError: "undefined" is not valid JSON
    at JSON.parse (<anonymous>)
    at d.OnContextMenu (blazorContextMenu.min.js:1:1302)
    at HTMLDivElement.oncontextmenu (NewSheet:1:19)

I should also mention that I followed the setup instructions to the best of my abilities, but my app structure is not the same as in the given instructions. I have a Blazor server-side app targeting .NET 8. The instructions say "Add the following static file references in your _Host.cshtml (server-side blazor) ". My app doesn't have a _Host.cshtml file, but it does have App.razor so I tried this

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <base href="/" />
    <link rel="stylesheet" href="css/app.css" />
    <link rel="stylesheet" href="css/theme-dark.css" />
    <link rel="stylesheet" href="FreedomSheetsApp.styles.css" />
    <link rel="icon" type="image/png" href="favicon.png" />
    <link href="_content/Blazor.ContextMenu/blazorContextMenu.min.css" rel="stylesheet" />
    <script src="_content/Blazor.ContextMenu/blazorContextMenu.min.js"></script>
    <HeadOutlet />
</head>

<body>
    <Routes />
    <script src="_framework/blazor.web.js"></script>
</body>


</html>

I also tried doing it in MainLayout.razor, but that didn't work either. Is it possible to use the custom context menu in this type of project, or is it required to have a _Host.cshtml file?

To Reproduce
Steps to reproduce the behavior:

  1. Create a new (or use existing) Blazor server-side app targeting .NET 8.
  2. Follow the setup instructions for installing the NuGet package and setup, except use App.razor instead of _Host.cshtml.
  3. Run the app and try to use the custom context menu. It displays the standard browser context menu instead of the custom one.

Expected behavior
Display custom context menu.

Screenshots

Image

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: Edge
  • Version: 2.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions